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