<?php
namespace App\EventSubscriber;
use App\Entity\PracticalFile;
use App\Event\AppEvents;
use App\Service\MailerService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class WorkflowSubscriber implements EventSubscriberInterface
{
/**
* @var MailerService
*/
private $mailerService;
public function __construct(MailerService $mailerService)
{
$this->mailerService = $mailerService;
}
public static function getSubscribedEvents()
{
return [
AppEvents::WORKFLOW_REINIT => 'notifyWorkflowReinit',
];
}
/**
* Envoi d'un mail de notification lors de la réinitialisation d'un workflow fiche pratique
*/
public function notifyWorkflowReinit($event)
{
$entity = $event->getArticleWorkflow()->getRelatedEntity();
if (!$entity instanceof PracticalFile || !$event->getArguments()['notify']) {
return;
}
$practicalFile = $entity;
if ($practicalFile->getPrincipalAuthor()->getStopEmail()) {
return;
}
$vars = [
'practical_file' => $practicalFile,
];
$this->mailerService->sendMail(
[$practicalFile->getPrincipalAuthor()->getEmail()],
"email/notification_workflow_reinit_{$practicalFile->getEditionPrefix()}.html.twig",
$vars
);
}
}