<?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\Entity\StatutDossier;
use App\Event\NotifyEvent;
use App\Event\SansSuiteEvent;
class SansSuiteSubscriber 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 [
SansSuiteEvent::NAME => 'notify'
];
}
public function notify(SansSuiteEvent $event) {
$dossier = $event->getDossier();
$dossier->setStatut(StatutDossier::STATUT_SANS_SUITE);
$statut = new StatutDossier();
$statut->setDossier($dossier);
$statut->setStatut(StatutDossier::STATUT_SANS_SUITE);
$statut->setDate(new \DateTime());
$this->em->persist($dossier);
$this->em->persist($statut);
$this->em->flush();
/*
$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);
*/
}
}