Пример #1
0
 /** Update
  * @param array $values
  * @return bool|string
  */
 public function update($values)
 {
     try {
         $this->database->beginTransaction();
         $roleEntity = $this->roleRepository->get($values['aclRoleID']);
         if ($roleEntity) {
             $roleEntity->setName($values['name']);
             $this->roleRepository->push($roleEntity)->save();
             $resources = $this->resourceRepository->read();
             $this->permissionRepository->read()->where("aclRoleID", $values['aclRoleID'])->getSelection()->delete();
             foreach ($resources as $resource) {
                 foreach ($values[$resource->aclResourceID] as $key => $action) {
                     $permissionEntity = new PermissionEntity();
                     $permissionEntity->setAclRoleID($values['aclRoleID']);
                     $permissionEntity->setAclModelID($key);
                     $permissionEntity->setAllowed($action);
                     $this->permissionRepository->push($permissionEntity);
                 }
             }
             $this->permissionRepository->save();
         } else {
             throw new \PDOException("Nepovedlo se načíst roli z databáze.");
         }
         $this->database->commit();
         return TRUE;
     } catch (\PDOException $e) {
         $this->database->rollBack();
         return $e->getMessage();
     }
 }
Пример #2
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;
 }
Пример #3
0
 /** 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;
 }
Пример #4
0
 /** 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();
     }
 }
Пример #5
0
 /**
  *
  */
 private function InitResource()
 {
     foreach ($this->resourceRepository->read()->order("aclResourceID ASC") as $resource) {
         $this->acl->addResource($resource->name);
     }
 }