<?php
namespace App\Security\Voter;
use App\Entity\NielsenOrder;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class NielsenOrderVoter extends AbstractVoter
{
public const LIST = 'NielsenOrder:ViewList';
private ?NielsenOrder $nielsenOrder = null;
protected function supports(string $attribute, mixed $subject): bool
{
return $attribute === self::LIST;
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$this->user = $token->getUser();
$this->nielsenOrder = $subject;
return match ($attribute) {
self::LIST => $this->canViewList(),
default => false,
};
}
private function canViewList(): bool
{
// Read-only superadmins can view Nielsen orders
return $this->isSuperAdmin() || $this->isReadOnlySuperAdmin();
}
}