Пример #1
0
 /**
  *
  * @param string $attribute
  * @param \Tracker\Entity\Comment $comment
  * @param \Tracker\Entity\User $user
  * @return boolean
  * @throws \LogicException
  */
 protected function isGranted($attribute, $comment, $user = null)
 {
     // make sure there is a user object (i.e. that the user is logged in)
     if (!$user instanceof UserInterface) {
         return false;
     }
     // double-check that the User object is the expected entity.
     // It always will be, unless there is some misconfiguration of the
     // security system.
     if (!$user instanceof User) {
         throw new \LogicException('The user is somehow not our User class!');
     }
     // If the current user have administrator rights, we should return true
     if ($user->getIsAdmin()) {
         return true;
     }
     switch ($attribute) {
         case self::DELETE:
             if ($comment->getMember() === $user) {
                 return true;
             }
             break;
     }
     return false;
 }
 /**
  * Base query used when listing results.
  *
  * @return \Doctrine\ORM\QueryBuilder
  */
 public function getCollection(User $user)
 {
     $qb = $this->createQueryBuilder('p')->addSelect('u', 'c')->leftJoin('p.createdBy', 'u')->leftJoin('p.category', 'c')->orderBy('p.id', 'ASC');
     // Check if our user does not have admin rights
     // and he is regular user, select those projects
     // that he is part of.
     if (!$user->getIsAdmin()) {
         $qb->leftJoin('p.members', 'pm')->where('pm.member = :user')->setParameter('user', $user);
     }
     return $qb;
 }