src/Knitink/ManagementBundle/Security/TeamVoter.php line 19

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the Knitink Project package.
  4.  *
  5.  * Created by Globunet Soluciones Tecnologicas, SL. on 13/01/17. <info@globunet.com>
  6.  * Copyright (c) 2016 Knitink Technologies, SL. All rights reserved.
  7.  */
  8. namespace Knitink\ManagementBundle\Security;
  9. use Knitink\ManagementBundle\Domain\TeamManager;
  10. use Knitink\ManagementBundle\Entity\Team;
  11. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  12. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  13. use Symfony\Component\HttpFoundation\Session\Session;
  14. use Doctrine\ORM\EntityManager;
  15. class TeamVoter extends Voter
  16. {
  17.     private $manager;
  18.     public function __construct(TeamManager $manager)
  19.     {
  20.         $this->manager $manager;
  21.     }
  22.     protected function supports($attribute$subject)
  23.     {
  24.         return $subject instanceof Team && $attribute === 'VOTER_KNITINK_MANAGEMENT_TEAM';
  25.     }
  26.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  27.     {
  28.         $user $token->getUser();
  29.         if(($user instanceof \Symfony\Component\Security\Core\User\User || $user instanceof \Globunet\UserBundle\Model\UserInterface) && in_array("ROLE_SUPER_ADMIN"$user->getRoles())){
  30.             return true;
  31.         }
  32.         if (!$user instanceof \Knitink\CoreBundle\Entity\User) {
  33.             return false;
  34.         }
  35.         $ids $this->manager->searchIdsBy($user);
  36.         $result $this->checker($ids$attribute$subject);
  37.         return $result;
  38.     }
  39.     public function checker($ids$attribute$subject)
  40.     {
  41.         $result false;
  42.         if($subject != null && in_array($subject->getId(), $ids) ){
  43.             $result true;
  44.         }
  45.         return $result;
  46.     }
  47. }