<?php
namespace App\Voters;
use App\Entity\Clinic\Appointment;
use App\Entity\Person\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class AppointmentVoter extends OrganisationVoter
{
protected function supports($attribute, $subject)
{
return $subject instanceof Appointment && self::EDIT == $attribute;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
/** @var User $user */
$user = $token->getUser();
if ($this->decisionManager->decide($token, [User::ROLE_SUB_CALENDAR_ACCESS])) {
if ($user->isSuperClinicAdmin()) {
return parent::voteOnAttribute(self::VIEW, $subject->getClinic()->getOrganisation(), $token);
}
return $user->getClinic() === $subject->getClinic();
}
return false;
}
}