src/Voters/PatientVoter.php line 8

Open in your IDE?
  1. <?php
  2. namespace App\Voters;
  3. use App\Entity\Person\Patient;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. class PatientVoter extends OrganisationVoter
  6. {
  7.     protected function supports($attribute$subject null)
  8.     {
  9.         if (!in_array($attribute, [self::VIEWself::CREATEself::EDIT])) {
  10.             return false;
  11.         }
  12.         if (!$subject instanceof Patient && $subject !== null) {
  13.             return false;
  14.         }
  15.         return true;
  16.     }
  17.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  18.     {
  19.         $user $token->getUser();
  20.         switch ($attribute) {
  21.             case self::VIEW:
  22.                 if ($this->decisionManager->decide($token, ['ROLE_SUB_PATIENT_LIST'])) {
  23.                     return true;
  24.                 }
  25.                 break;
  26.             case self::CREATE:
  27.                 if ($this->decisionManager->decide($token, ['ROLE_SUB_PATIENT_PROFILE'])) {
  28.                     if ($user->isSuperClinicAdmin()) {
  29.                         return parent::voteOnAttribute(self::VIEW$subject->getClinic()->getOrganisation(), $token);
  30.                     }
  31.                     return $user->getClinic() === $subject->getClinic() || $subject->getAllowedClinics()->contains($user->getClinic());
  32.                 }
  33.                 break;
  34.             case self::EDIT:
  35.                 if ($this->decisionManager->decide($token, ['ROLE_SUB_PATIENT_RECORD'])) {
  36.                     if ($user->isSuperClinicAdmin()) {
  37.                         return parent::voteOnAttribute(self::VIEW$subject->getClinic()->getOrganisation(), $token);
  38.                     }
  39.                     return $user->getClinic() === $subject->getClinic();
  40.                 }
  41.                 break;
  42.         }
  43.         return false;
  44.     }
  45. }