<?php
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use App\Utils\MailerService;
use App\Entity\Notification;
use App\Event\NotifyEvent;
use App\Event\IncompletRelance1Event;
class IncompletRelance1Subscriber implements EventSubscriberInterface
{
private $mailer;
private $parameters;
private $em;
private $dispatcher;
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameters, MailerService $mailer, EventDispatcherInterface $dispatcher) {
$this->mailer = $mailer;
$this->parameters = $parameters;
$this->em = $em;
$this->dispatcher = $dispatcher;
}
public static function getSubscribedEvents(): array
{
return [
IncompletRelance1Event::NAME => 'notify'
];
}
public function notify(IncompletRelance1Event $event) {
$dossier = $event->getDossier();
$vars = [
'offre' => $dossier->getOffre(),
'raison_sociale' => $dossier->getEntreprise(),
'date' => $dossier->getCreatedAt(),
];
$object = [
'dossier' => $dossier,
'event' => $event::NAME,
'vars' => $vars,
];
// Envoi notification membre
$this->dispatcher->dispatch(new NotifyEvent($object), NotifyEvent::NAME);
}
}