/**
  * Akce pro přejmenování existujícího rulesetu
  * @param int $id
  * @param string $name
  * @param string $description=""
  */
 public function actionRename($id, $name, $description = "")
 {
     //najití RuleSetu a kontroly
     $ruleSet = $this->ruleSetsFacade->findRuleSet($id);
     $this->ruleSetsFacade->checkRuleSetAccess($ruleSet, $this->user->id);
     $this->ruleSetsFacade->checkUniqueRuleSetNameByUser($name, $this->user->id, $ruleSet);
     //změna a uložení
     $ruleSet->name = $name;
     $ruleSet->description = $description;
     $this->ruleSetsFacade->saveRuleSet($ruleSet);
     //odeslání výsledku
     $this->sendJsonResponse($ruleSet->getDataArr());
 }
 /**
  * Funkce pro kontrolu vstupů pro aktualizaci rule setu
  * @param int $id
  */
 public function validateUpdate($id)
 {
     $fieldName = $this->input->field('name');
     $fieldName->addRule(IValidator::MIN_LENGTH, 'Minimal length of name is  %d characters!', 3)->addRule(IValidator::MAX_LENGTH, 'Maximal length of name is  %d characters!', 100)->addRule(IValidator::REQUIRED, 'Name is required!');
     if ($user = $this->getCurrentUser()) {
         $fieldName->addRule(IValidator::CALLBACK, 'RuleSet with this name already exists!', function ($value) use($user, $id) {
             try {
                 /** @noinspection PhpUndefinedFieldInspection */
                 $this->ruleSetsFacade->checkUniqueRuleSetNameByUser($value, $user, $id);
                 return true;
             } catch (\Exception $e) {
             }
             return false;
         });
     }
     $this->input->field('description')->addRule(IValidator::MAX_LENGTH, 'Maximal length of description is %d characters!', 200);
 }