src/Security/Voter/ReservaVoter.php line 9

  1. <?php
  2. namespace App\Security\Voter;
  3. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  4. use App\Entity\Reserva;
  5. use App\Admin\ReservaPedidaAdmin;
  6. class ReservaVoter extends Voter
  7. {
  8.     
  9.     public function supports($attribute$subject): bool
  10.     {
  11.         // if ($subject) {
  12.         //      var_dump(get_class($subject));echo "-";
  13.         //      var_dump(($subject instanceof ReservaPedidaAdmin));echo "#";
  14.         // }
  15. // return true;
  16.         return $subject instanceof ReservaPedidaAdmin && in_array($attribute, array(
  17.             'ROLE_APP_ADMIN_RESERVA_PEDIDA_LIST',
  18.             'ROLE_APP_ADMIN_RESERVA_PEDIDA_CREATE',
  19.             'ROLE_APP_ADMIN_RESERVA_PEDIDA_VIEW'
  20.         ));
  21.     }
  22.     
  23.     protected function voteOnAttribute($attribute$object$token): bool
  24.     {
  25.         // echo $attribute;
  26. //         return true;
  27.         $user $token->getUser();
  28.         if ($user->hasRole('ROLE_MANAGER')) { //Solo Managers/Oficina
  29.             return true;
  30.         }
  31.         return false;
  32.     }
  33.     
  34. }