src/ForumBundle/Security/ForumVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace ForumBundle\Security;
  3. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use CoreBundle\Entity\Category;
  6. use CoreBundle\Entity\Tutor;
  7. use CoreBundle\Entity\Student;
  8. class ForumVoter extends Voter
  9. {
  10.     public function __construct()
  11.     {
  12.     }
  13.     protected function supports($attribute$subject)
  14.     {
  15.         // if the attribute isn't one we support, return false
  16.         if (! in_array($attribute, array('view'))) {
  17.             return false;
  18.         }
  19.         if ($subject !== 'forum') {
  20.             return false;
  21.         }
  22.         return true;
  23.     }
  24.     /**
  25.      * Droit d'accès au forum
  26.      *
  27.      * {@inheritDoc}
  28.      * @see \Symfony\Component\Security\Core\Authorization\Voter\Voter::voteOnAttribute()
  29.      */
  30.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  31.     {
  32.         $user $token->getUser();
  33.         // les tables tutor et student n'ont pas évoluées ensemble, elles présentent pas mal de différences.
  34.         if ($user instanceof Tutor) {
  35.             return true;
  36.         } elseif ($user instanceof Student) {
  37.             /*if ($user->getBranche()->getId() === 1) {
  38.                 if ($user->getIsPau()) {
  39.                     return true;
  40.                 }
  41.                 return false;
  42.             }*/
  43.             return true;
  44.         }
  45.         return true;
  46.     }
  47. }