src/EventSubscriber/EventoNotificacionSubscriber.php line 27
<?phpnamespace App\EventSubscriber;use ApiPlatform\Symfony\EventListener\EventPriorities;use App\Entity\Evento;use App\Entity\Notificacion;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpKernel\Event\ViewEvent;use Symfony\Component\HttpKernel\KernelEvents;final class EventoNotificacionSubscriber implements EventSubscriberInterface{public function __construct(private readonly EntityManagerInterface $entityManager){}public static function getSubscribedEvents(){return [KernelEvents::VIEW => ['createNotificacion', EventPriorities::POST_WRITE],];}public function createNotificacion(ViewEvent $event): void{$evento = $event->getControllerResult();$method = $event->getRequest()->getMethod();if (!$evento instanceof Evento || Request::METHOD_POST !== $method) {return;}foreach($evento->getUsers() as $user){$notificacion = new Notificacion();$notificacion->setEmpresa($evento->getCreatedBy()->getEmpresa());$notificacion->setUser($user);$notificacion->setTitulo($evento->getTitulo());$notificacion->setIsNew(true);$notificacion->setModulo(Evento::TIPO_MANUAL);$notificacion->setModuloRef($evento->getUuid());$notificacion->setHint($evento->getDescripcion());$this->entityManager->persist($notificacion);}$this->entityManager->flush();}}