Example #1
0
 /** Vytvoření formuláře
  * 
  * @return \Nette\Application\UI\Form
  */
 protected function createComponentForm()
 {
     $form = new Form();
     $form->getElementPrototype()->id = "resourceForm";
     $form->addText("name", "Jméno modulu:")->setHtmlId("name")->setRequired("Prosím zadejte jméno modulu.");
     $form->addHidden("aclResourceID");
     $form->addButton("cancel", "Storno")->setHtmlId("cancel");
     $form->addSubmit("sender", "Uložit změny")->setHtmlId("sender");
     $actions = $this->actionRepository->read();
     $container = $form->addContainer("actions");
     foreach ($actions as $key => $action) {
         $container->addCheckbox($key, $action->humanName);
     }
     if ($this->aclResourceID) {
         $modelEntities = $this->modelRepository->read()->where("aclResourceID", $this->aclResourceID);
         $modelEntity = $modelEntities->fetch();
         if ($modelEntity) {
             $form['aclResourceID']->setValue($modelEntity->getAclResource()->getAclResourceID());
             $form['name']->setValue($modelEntity->getAclResource()->name);
             foreach ($modelEntities as $entity) {
                 $form["actions"][$entity->aclActionID]->setValue(TRUE);
             }
         } else {
             $resourceEntity = $this->resourceRepository->get($this->aclResourceID);
             if ($resourceEntity) {
                 $form['aclResourceID']->setValue($this->aclResourceID);
                 $form['name']->setValue($resourceEntity->getName());
             }
         }
     }
     $form->onSuccess[] = callback($this, "Submit");
     $form->onError[] = callback($this, "Error");
     return $form;
 }
Example #2
0
 /**
  * @secured
  * @param $actionID
  */
 public function handleDeleteAction($actionID)
 {
     if ($this->user->isAllowed("permission", "delete")) {
         if (is_string($actionID)) {
             try {
                 $actionID = (array) Json::decode($actionID);
                 $actionID = array_values($actionID);
             } catch (JsonException $e) {
                 $this['notification']->addError($e->getMessage());
                 if ($this->isAjax()) {
                     $this['notification']->redrawControl('error');
                 }
             }
         }
         $result = $this->actionRepository->delete($actionID);
         if ($result !== TRUE) {
             if (strpos("Integrity constraint violation", $result) != -1) {
                 $this['notification']->addError("Akci stále využívá některý z modelů, proto ji nebylo možné vymazat.");
             } else {
                 $this['notification']->addError($result);
             }
         } else {
             $this['notification']->addSuccess("Úspěšně uloženo...");
         }
     }
     if ($this->isAjax()) {
         $this['notification']->redrawControl('error');
         $this['notification']->redrawControl('success');
         $this['gridAction']->redrawControl();
     }
 }
Example #3
0
 /**
  * @param array $values
  * @return bool|string
  */
 public function update($values)
 {
     try {
         $this->database->beginTransaction();
         $resourceEntity = $this->resourceRepository->get($values['aclResourceID']);
         if ($resourceEntity) {
             $resourceEntity->setName($values['name']);
             $this->resourceRepository->save(FALSE);
             $modelEntities = $this->modelRepository->read()->where("aclResourceID", $resourceEntity->getAclResourceID());
             $modelEntities->fetchAll();
             $actions = $this->actionRepository->read();
             foreach ($actions as $key => $action) {
                 if (isset($values["actions"][$key]) && $values["actions"][$key]) {
                     $hasAction = FALSE;
                     foreach ($modelEntities as $entity) {
                         if ($entity->aclActionID == $action->aclActionID) {
                             $hasAction = TRUE;
                             break;
                         }
                     }
                     if ($hasAction === FALSE) {
                         $modelEntity = new ModelEntity();
                         $modelEntity->setAclResourceID($values['aclResourceID']);
                         $modelEntity->setAclActionID($action->aclActionID);
                         $this->modelRepository->push($modelEntity);
                     }
                 } elseif (isset($values["actions"][$key]) && $values["actions"][$key] === FALSE) {
                     $this->modelRepository->deleteByActionID($values['aclResourceID'], $action->getAclActionID());
                 }
             }
             $this->modelRepository->save();
         } else {
             throw new \PDOException("Item with ID " . $values['aclResourceID'] . " not found");
         }
         $this->database->commit();
         return TRUE;
     } catch (\PDOException $e) {
         $this->database->rollBack();
         return $e->getMessage();
     }
 }