Exemplo n.º 1
0
 public function updateRole(Role $r)
 {
     if ($r === null) {
         throw new Exceptions\NullPointerException("Argument Role cannot be null");
     }
     try {
         $dbRole = $this->roleDao->find($r->getId());
         if ($dbRole !== null) {
             $dbRole->fromArray($r->toArray());
             $dbRole->setParents($this->roleParentsCollSetup($r));
             //$dbRole->setAdded(new \Nette\Utils\DateTime()); // this might cause hierarchy problems
             $this->entityManager->merge($dbRole);
             $this->entityManager->flush();
             $this->invalidateEntityCache($dbRole);
             $this->onUpdate(clone $dbRole);
         }
     } catch (DuplicateEntryException $e) {
         throw new Exceptions\DuplicateEntryException($e->getMessage(), $e->getCode(), $e->getPrevious());
     } catch (\Exception $e) {
         $this->logError($e);
         throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious());
     }
 }
Exemplo n.º 2
0
 /**
  * @param Role $role
  */
 public function addRole(Role $role)
 {
     $this->roles->add($role);
 }
Exemplo n.º 3
0
 /**
  * Grid column parents render callback
  * @param \App\Model\Entities\Role $item
  * @return string of parents roles
  */
 public function roleParColToString(Role $item)
 {
     $res = "";
     $it = $item->getParents()->getIterator();
     while ($it->current() !== null) {
         $res .= $it->current()->getName();
         $it->next();
         if ($it->valid()) {
             $res .= ", ";
         }
     }
     return $res;
 }
Exemplo n.º 4
0
 public function getUniqueRule(Role $r, $resource = null, $priv = null)
 {
     try {
         $qb = $this->aclRuleDao->createQueryBuilder("r")->where("r.role = :role")->setParameter("role", $r->getId());
         if ($resource === null) {
             $qb->andWhere("r.resource IS NULL");
         } else {
             $qb->andWhere("r.resource = :res")->setParameter("res", $resource);
         }
         if ($priv === null) {
             $qb->andWhere("r.privilege IS NULL");
         } else {
             $qb->andWhere("r.privilege = :priv")->setParameter("priv", $priv);
         }
         return $qb->getQuery()->getSingleResult();
     } catch (\Doctrine\ORM\NoResultException $e) {
         $this->logError($e);
         throw new Exceptions\NoResultException($e->getMessage(), $e->getCode(), $e->getPrevious());
     }
 }
Exemplo n.º 5
0
 public function getUniquePosition(User $u, SportGroup $g, Role $r)
 {
     try {
         $qb = $this->positionDao->createQueryBuilder("p")->where("p.owner = :owner")->andWhere("p.group = :group")->andWhere("p.role = :role")->setParameters(["owner" => $u->getId(), "group" => $g->getId(), "role" => $r->getId()]);
         return $qb->getQuery()->getSingleResult();
     } catch (\Doctrine\ORM\NoResultException $ex) {
         $this->logError($ex);
         throw new Exceptions\NoResultException($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
     } catch (\Exception $ex) {
         $this->logError($ex);
         throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
     }
 }
Exemplo n.º 6
0
 public function testInitialize()
 {
     $this->assertEquals('customer', $this->role->getName());
     $this->assertNull($this->role->getDescription());
     $this->assertInstanceOf(ReadOnlyCollectionWrapper::class, $this->role->getUsers());
 }