← Back
Editing: ControlSubscriber.php
<?php namespace App\EventSubscriber; use App\Entity\Controle; use App\Event\ControlSentEvent; use App\Report\Control\ReportControlFactory; use App\Repository\AddressReminderRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Mailer\Exception\TransportExceptionInterface; class ControlSubscriber implements EventSubscriberInterface { public function __construct( private readonly EntityManagerInterface $em, private readonly AddressReminderRepository $addressReminderRepository, private readonly ReportControlFactory $reportControlFactory ) { } /** * @return string[] */ public static function getSubscribedEvents(): array { return [ ControlSentEvent::class => 'onControlSent', ]; } /** * @throws TransportExceptionInterface */ public function onControlSent(ControlSentEvent $event): void { $control = $event->getControl(); $control->setAlertePrestataire($event->getReceivedControl()['alerteFournisseur'] ?? false); $control->setReceiveReport($event->getReceivedControl()['rapport'] ?? false); $control->setSendToManager($event->getReceivedControl()['sendToManager'] ?? false); $this->reportControlFactory->send($control); $this->disableReminders($control); $event->stopPropagation(); } private function disableReminders(Controle $control): void { $reminders = $this->addressReminderRepository->findBy( ['address' => $control->getAdresse(), 'done' => false] ); foreach ($reminders as $reminder) { $reminder->setDone(true); $this->em->persist($reminder); } $this->em->flush(); } }
Save File
Cancel