src/Voters/TreatmentVoter.php line 11

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