src/Voters/LeadCaptureVoter.php line 11

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