Example #1
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());
     }
 }
Example #2
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());
     }
 }
Example #3
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());
     }
 }