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