src/Voters/NotConvertReasonVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Voters;
  3. use App\Entity\Clinic\NotConvertReason;
  4. use App\Entity\Clinic\Questionaire\Questionaire;
  5. use App\Entity\Person\Admin;
  6. use App\Entity\Person\SuperClinicAdmin;
  7. use App\Entity\Person\User;
  8. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  9. class NotConvertReasonVoter extends OrganisationVoter
  10. {
  11.     protected function supports($attribute$subject)
  12.     {
  13.         return $subject instanceof NotConvertReason && $attribute == self::EDIT;
  14.     }
  15.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  16.     {
  17.         /** @var User $user */
  18.         $user $token->getUser();
  19.         if ($user instanceof Admin) {
  20.             return true;
  21.         }
  22.         if ($user instanceof SuperClinicAdmin) {
  23.             /* @var Questionaire $subject */
  24.             return parent::voteOnAttribute(self::VIEW$subject->getClinic()->getOrganisation(), $token);
  25.         }
  26.         return false;
  27.     }
  28. }