src/EventSubscriber/WorkflowSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\PracticalFile;
  4. use App\Event\AppEvents;
  5. use App\Service\MailerService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class WorkflowSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var MailerService
  11.      */
  12.     private $mailerService;
  13.     public function __construct(MailerService $mailerService)
  14.     {
  15.         $this->mailerService $mailerService;
  16.     }
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [
  20.             AppEvents::WORKFLOW_REINIT => 'notifyWorkflowReinit',
  21.         ];
  22.     }
  23.     /**
  24.      * Envoi d'un mail de notification lors de la rĂ©initialisation d'un workflow fiche pratique
  25.      */
  26.     public function notifyWorkflowReinit($event)
  27.     {
  28.         $entity $event->getArticleWorkflow()->getRelatedEntity();
  29.         if (!$entity instanceof PracticalFile || !$event->getArguments()['notify']) {
  30.             return;
  31.         }
  32.         $practicalFile $entity;
  33.         if ($practicalFile->getPrincipalAuthor()->getStopEmail()) {
  34.             return;
  35.         }
  36.         $vars = [
  37.             'practical_file' => $practicalFile,
  38.         ];
  39.         $this->mailerService->sendMail(
  40.             [$practicalFile->getPrincipalAuthor()->getEmail()],
  41.             "email/notification_workflow_reinit_{$practicalFile->getEditionPrefix()}.html.twig",
  42.             $vars
  43.         );
  44.     }
  45. }