<?php
/**
* Created by PhpStorm.
* User: frup64362
* Date: 01/01/2017
* Time: 14:43
*/
namespace App\Listener;
use App\Entity\ProjetLettreMission;
use App\Event\PdfformEvents;
use App\Services\GenerateLmPdf;
use Doctrine\ORM\EntityManagerInterface;
use Ensepar\Html2pdfBundle\Factory\Html2pdfFactory;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
// #[AsEventListener(event: PdfformEvents::class, method: 'processPdf')]
class GeneratePdfListener implements EventSubscriberInterface
{
/**
* @var Html2pdfFactory
*/
private $html2pdfFactory;
private $generateLmPdf;
private $entityManager;
public function __construct(GenerateLmPdf $generateLmPdf, EntityManagerInterface $entityManager)
{
$this->generateLmPdf = $generateLmPdf;
$this->entityManager = $entityManager;
}
public static function getSubscribedEvents()
{
return [
PdfformEvents::class => 'processPdf',
];
}
public function processPdf(PdfformEvents $events)
{
if ($events->getNewWorkflow() != $events->getLastWorkflow()) {
$em = $this->entityManager;
$projetLettreMission = $em->getRepository(ProjetLettreMission::class)->find($events->getProjetLetterMission());
$this->generateLmPdf->generatePdf($projetLettreMission);
}
}
}