<?php
namespace App\EventListener;
use App\Entity\System\Role;
use App\Factory\Admin\StaticNotificationFactory;
use App\Manager\System\CustomerManager;
use App\Service\EnvironmentService;
use App\Service\SecurityService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;
class StaticNotificationListener implements EventSubscriberInterface
{
private Environment $environment;
private EnvironmentService $environmentService;
private SecurityService $securityService;
private CustomerManager $customerManager;
public function __construct(
Environment $environment,
EnvironmentService $environmentService,
SecurityService $securityService,
CustomerManager $customerManager
) {
$this->environment = $environment;
$this->environmentService = $environmentService;
$this->securityService = $securityService;
$this->customerManager = $customerManager;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
return [KernelEvents::REQUEST => ['onKernelRequest']];
}
public function onKernelRequest(): void
{
$employee = $this->securityService->findSessionEmployee();
if (!$employee || $this->environmentService->isApi()) {
return;
}
$staticNotices = [];
if (\count($employee->getRoles()) === 1 && $employee->hasRole(Role::ROLE_EMPLOYEE)) {
$staticNotices[] = StaticNotificationFactory::createFromValues(
'Usuario nuevo creado en panel de administración',
'Usuario sin permisos de administración, contacta con tu responsable, es quien tiene que solicitar los permisos.'
);
}
$customer = $this->customerManager->findOneByEmail($employee->getEmail());
if (!$customer) {
$staticNotices[] = StaticNotificationFactory::createFromValues(
'Usuario de BigBuy no encontrado',
'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>'
);
} elseif (!$customer->isActive()) {
$staticNotices[] = StaticNotificationFactory::createFromValues(
'Usuario de BigBuy desactivado',
'Contacta con TIC para activar tu cuenta.'
);
}
$this->environment->addGlobal('static_notifications', $staticNotices);
}
}