src/EventSubscriber/NonConformitySubscriber.php line 84
<?phpnamespace App\EventSubscriber;use App\Entity\App\NonConformity;use App\Event\NcApprovedEvent;use App\Event\NcClosedEvent;use App\Event\NcRefusedEvent;use App\Event\NcSubmittedEvent;use Symfony\Bridge\Twig\Mime\NotificationEmail;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\Mailer\MailerInterface;use Symfony\Component\Mime\Address;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Symfony\Component\Routing\RouterInterface;class NonConformitySubscriber implements EventSubscriberInterface{public function __construct(private MailerInterface $mailer,private RouterInterface $router,){}/*** @return string[]*/public static function getSubscribedEvents(): array{return [NcSubmittedEvent::NAME => 'onNcSubmitted',NcApprovedEvent::NAME => 'onNcApproved',NcRefusedEvent::NAME => 'onNcRefused',NcClosedEvent::NAME => 'onNcClosed',];}/*** Intercept the nc.submitted event** Sends a notification to the SQSS department to let them know* that a new NC has been created** @param NcSubmittedEvent $event** @return void** @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface*/public function onNcSubmitted(NcSubmittedEvent $event): void{$nc = $event->getNonConformity();if (!$nc instanceof NonConformity) {return;}$notification = (new NotificationEmail())->to(new Address('qualite@itoh-denki.com'), new Address('laurence-floux@itoh-denki.com'))->subject('La non-conformité '.str_pad($nc->getId(), 6, 0, STR_PAD_LEFT).' a été soumise')->content('<p>Bonjour,</p><p>Une nouvelle non-conformité vient d\'être ouverte par '.$nc->getEmetteur().'</p><p>Vous pouvez la consulter en cliquant ici :</p>')->action('Voir la non-conformité', $this->router->generate('non_conformity_view', ['id' => $nc->getId()], UrlGeneratorInterface::ABSOLUTE_URL))->markAsPublic();$this->mailer->send($notification);}/*** Intercept the nc.approved event** Sends a notification to the NC sender to let him know* that hist NC has been approved** @param NcApprovedEvent $event** @return void** @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface*/public function onNcApproved(NcApprovedEvent $event): void{$nc = $event->getNonConformity();if (!$nc instanceof NonConformity) {return;}if (!empty($nc->getEmmeteurEmail())) {$notification = (new NotificationEmail())->to(new Address($nc->getEmmeteurEmail()))->subject('Votre non-conformité '.str_pad($nc->getId(), 6, 0, STR_PAD_LEFT).' a été approuvée')->content('<p>Bonjour,</p><p>Votre non-conformité n°'.$nc->getId().' vient d\'être approuvée</p><p>Vous pouvez la consulter en cliquant ici :</p>')->action('Voir la non-conformité', $this->router->generate('non_conformity_view', ['id' => $nc->getId()], UrlGeneratorInterface::ABSOLUTE_URL))->markAsPublic();$this->mailer->send($notification);}}/*** Intercept the nc.refused event** Sends a notification to the NC sender to let him know* that hist NC has been refused** @param NcRefusedEvent $event** @return void** @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface*/public function onNcRefused(NcRefusedEvent $event): void{$nc = $event->getNonConformity();if (!$nc instanceof NonConformity) {return;}if (!empty($nc->getEmmeteurEmail())) {$notification = (new NotificationEmail())->to(new Address($nc->getEmmeteurEmail()))->subject('Votre non-conformité '.str_pad($nc->getId(), 6, 0, STR_PAD_LEFT).' a été refusée')->content('<p>Bonjour,</p><p>Votre non-conformité n°'.$nc->getId().' vient d\'être refusée</p><p>Voici la raison du refus :</p><p>'.$nc->getRefuseNcMessage().'</p>')->markAsPublic();$this->mailer->send($notification);}}/*** Intercept the nc.closed event** Sends a notification to the NC sender to let him know* that hist NC has been closed** @param NcClosedEvent $event** @return void** @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface*/public function onNcClosed(NcClosedEvent $event): void{$nc = $event->getNonConformity();if (!$nc instanceof NonConformity) {return;}if (!empty($nc->getEmmeteurEmail())) {$notification = (new NotificationEmail())->to(new Address($nc->getEmmeteurEmail()))->subject('Votre non-conformité '.str_pad($nc->getId(), 6, 0, STR_PAD_LEFT).' a été fermée')->content('<p>Bonjour,</p><p>Votre non-conformité n°'.$nc->getId().' vient d\'être fermée</p>')->markAsPublic();$this->mailer->send($notification);}}}