Exemplo n.º 1
0
 /**
  * 
  * @param string $attribute
  * @param Club $club
  * @param UserInterface $user
  * @return boolean
  */
 protected function isGranted($attribute, $club, $user = null)
 {
     switch ($attribute) {
         case self::VIEW:
             if (!$club->isPrivate()) {
                 return true;
             }
             // make sure there is a user object (i.e. that the user is logged in)
             if (!$user instanceof UserInterface) {
                 return false;
             }
             if (in_array('ROLE_ADMIN', $user->getRoles())) {
                 return true;
             }
             break;
         case self::EDIT:
             // make sure there is a user object (i.e. that the user is logged in)
             if (!$user instanceof UserInterface) {
                 return false;
             }
             foreach ($club->getAdministrators() as $administrator) {
                 if ($administrator->getId() == $user->getId()) {
                     return true;
                 }
             }
             if (in_array('ROLE_ADMIN', $user->getRoles())) {
                 return true;
             }
             return false;
         case self::CREATE:
             break;
     }
     return false;
 }