src/EventListener/StaticNotificationListener.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\System\Role;
  4. use App\Factory\Admin\StaticNotificationFactory;
  5. use App\Manager\System\CustomerManager;
  6. use App\Service\EnvironmentService;
  7. use App\Service\SecurityService;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. use Twig\Environment;
  11. class StaticNotificationListener implements EventSubscriberInterface
  12. {
  13.     private Environment $environment;
  14.     private EnvironmentService $environmentService;
  15.     private SecurityService $securityService;
  16.     private CustomerManager $customerManager;
  17.     public function __construct(
  18.         Environment $environment,
  19.         EnvironmentService $environmentService,
  20.         SecurityService $securityService,
  21.         CustomerManager $customerManager
  22.     ) {
  23.         $this->environment $environment;
  24.         $this->environmentService $environmentService;
  25.         $this->securityService $securityService;
  26.         $this->customerManager $customerManager;
  27.     }
  28.     /**
  29.      * {@inheritDoc}
  30.      */
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [KernelEvents::REQUEST => ['onKernelRequest']];
  34.     }
  35.     public function onKernelRequest(): void
  36.     {
  37.         $employee $this->securityService->findSessionEmployee();
  38.         if (!$employee || $this->environmentService->isApi()) {
  39.             return;
  40.         }
  41.         $staticNotices = [];
  42.         if (\count($employee->getRoles()) === && $employee->hasRole(Role::ROLE_EMPLOYEE)) {
  43.             $staticNotices[] = StaticNotificationFactory::createFromValues(
  44.                 'Usuario nuevo creado en panel de administración',
  45.                 'Usuario sin permisos de administración, contacta con tu responsable, es quien tiene que solicitar los permisos.'
  46.             );
  47.         }
  48.         $customer $this->customerManager->findOneByEmail($employee->getEmail());
  49.         if (!$customer) {
  50.             $staticNotices[] = StaticNotificationFactory::createFromValues(
  51.                 'Usuario de BigBuy no encontrado',
  52.                 'Necesitas tener una cuenta creada con el email corporativo (@bigbuygroup.com) <a target="_blank" href="https://a4b-group.atlassian.net/wiki/spaces/BBWEB/pages/5773688863/Login+corporativo+en+BigBuy+Web">más info</a>'
  53.             );
  54.         } elseif (!$customer->isActive()) {
  55.             $staticNotices[] = StaticNotificationFactory::createFromValues(
  56.                 'Usuario de BigBuy desactivado',
  57.                 'Contacta con TIC para activar tu cuenta.'
  58.             );
  59.         }
  60.         $this->environment->addGlobal('static_notifications'$staticNotices);
  61.     }
  62. }