コード例 #1
0
ファイル: ResourceForm.php プロジェクト: vipercz/sandbox
 /** 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;
 }
コード例 #2
0
ファイル: RoleForm.php プロジェクト: vipercz/sandbox
 /** Vytvoření formuláře
  * 
  * @return \Nette\Application\UI\Form
  */
 protected function createComponentForm()
 {
     $form = new Form();
     $form->getElementPrototype()->id = "roleForm";
     $form->addText("name", "Jméno skupiny:")->setHtmlId("name")->setRequired("Prosím zadejte jméno skupiny oprávnění.");
     $form->addHidden("aclRoleID");
     $form->addButton("cancel", "Storno")->setHtmlId("cancel");
     $form->addSubmit("sender", "Uložit změny")->setHtmlId("sender");
     $resources = $this->resourceRepository->read();
     foreach ($resources as $resource) {
         $container = $form->addContainer($resource->aclResourceID);
         $actions = $this->modelRepository->read()->where("aclResourceID", $resource->aclResourceID);
         foreach ($actions as $key => $action) {
             $checkbox = $container->addCheckbox($key, $action->getAclAction()->humanName);
             if ($this->aclRoleID) {
                 $permissions = $this->permissionRepository->read()->where("aclRoleID", $this->aclRoleID)->where("aclModel.aclResourceID", $resource->aclResourceID)->where("aclModel.aclActionID", $action->aclActionID)->where("allowed", TRUE);
                 if ($permissions->count() > 0) {
                     $checkbox->setValue(TRUE);
                 }
             }
         }
     }
     if ($this->aclRoleID) {
         $roleEntity = $this->roleRepository->get($this->aclRoleID);
         if ($roleEntity) {
             $form['aclRoleID']->setValue($roleEntity->aclRoleID);
             $form['name']->setValue($roleEntity->name);
         }
     }
     $form->onSuccess[] = callback($this, "Submit");
     $form->onError[] = callback($this, "Error");
     return $form;
 }
コード例 #3
0
ファイル: ModelManager.php プロジェクト: vipercz/sandbox
 /** Remove
  * @param array $keys
  * @return bool|string
  */
 public function remove($keys)
 {
     try {
         $this->database->beginTransaction();
         $this->modelRepository->read()->where("aclResourceID", $keys)->getSelection()->delete();
         $this->resourceRepository->read()->where("aclResourceID", $keys)->getSelection()->delete();
         $this->database->commit();
         return TRUE;
     } catch (\PDOException $e) {
         $this->database->rollBack();
         return $e->getMessage();
     }
 }