/**
  * 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());
 }
 /**
  * @param int $id
  * @throws \Nette\Application\BadRequestException
  * @SWG\Put(
  *   tags={"Rules"},
  *   path="/rules/{id}",
  *   summary="Update existing rule set",
  *   security={{"apiKey":{}},{"apiKeyHeader":{}}},
  *   produces={"application/json","application/xml"},
  *   consumes={"application/json","application/xml"},
  *   @SWG\Parameter(
  *     name="id",
  *     description="RuleSet ID",
  *     required=true,
  *     type="integer",
  *     in="path"
  *   ),
  *   @SWG\Parameter(
  *     description="Rule",
  *     name="rule",
  *     required=true,
  *     @SWG\Schema(ref="#/definitions/RuleInput"),
  *     in="body"
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="Rule updated successfully. Returns details of the rule.",
  *     @SWG\Schema(ref="#/definitions/RuleResponse")
  *   ),
  *   @SWG\Response(response=404, description="Requested rule set was not found.")
  * )
  */
 public function actionUpdate($id)
 {
     //prepare RuleSet from input values
     //FIXME not implemented!
     throw new NotImplementedException();
     /** @var RuleSet $ruleSet */
     $ruleSet = $this->findRuleWithCheckAccess($id);
     /** @noinspection PhpUndefinedFieldInspection */
     $ruleSet->name = $this->input->name;
     /** @noinspection PhpUndefinedFieldInspection */
     $ruleSet->description = $this->input->description;
     $ruleSet->rulesCount = 0;
     if ($user = $this->getCurrentUser()) {
         $ruleSet->user = $user;
     }
     $this->ruleSetsFacade->saveRuleSet($ruleSet);
     //send response
     $this->actionRead($ruleSet->ruleSetId);
 }
 /**
  * Akce pro vypsání existujících rulesetů
  * @SWG\Get(
  *   tags={"RuleSets"},
  *   path="/rule-sets",
  *   summary="List rule sets for the current user",
  *   security={{"apiKey":{}},{"apiKeyHeader":{}}},
  *   produces={"application/json","application/xml"},
  *   consumes={"application/json","application/xml"},
  *   @SWG\Response(
  *     response=200,
  *     description="List of rule sets",
  *     @SWG\Schema(
  *       type="array",
  *       @SWG\Items(ref="#/definitions/RuleSetResponse")
  *     )
  *   )
  * )
  */
 public function actionList()
 {
     $result = [];
     $ruleSets = $this->ruleSetsFacade->findRuleSetsByUser($this->getCurrentUser());
     if (empty($ruleSets)) {
         //pokud není nalezen ani jeden RuleSet, jeden založíme...
         $ruleSet = new RuleSet();
         $user = $this->usersFacade->findUser($this->user->id);
         $ruleSet->user = $user;
         $ruleSet->name = $user->name;
         $this->ruleSetsFacade->saveRuleSet($ruleSet);
         $result[] = $ruleSet->getDataArr();
     } else {
         foreach ($ruleSets as $ruleSet) {
             $result[] = $ruleSet->getDataArr();
         }
     }
     $this->setXmlMapperElements('rulesets', 'ruleset');
     $this->resource = $result;
     $this->sendResource();
 }