<?php
namespace App\Voters;
use App\Entity\Clinic\NotConvertReason;
use App\Entity\Clinic\Questionaire\Questionaire;
use App\Entity\Person\Admin;
use App\Entity\Person\SuperClinicAdmin;
use App\Entity\Person\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class NotConvertReasonVoter extends OrganisationVoter
{
protected function supports($attribute, $subject)
{
return $subject instanceof NotConvertReason && $attribute == self::EDIT;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
/** @var User $user */
$user = $token->getUser();
if ($user instanceof Admin) {
return true;
}
if ($user instanceof SuperClinicAdmin) {
/* @var Questionaire $subject */
return parent::voteOnAttribute(self::VIEW, $subject->getClinic()->getOrganisation(), $token);
}
return false;
}
}