src/Listener/GeneratePdfListener.php line 43

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: frup64362
  5.  * Date: 01/01/2017
  6.  * Time: 14:43
  7.  */
  8. namespace App\Listener;
  9. use App\Entity\ProjetLettreMission;
  10. use App\Event\PdfformEvents;
  11. use App\Services\GenerateLmPdf;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Ensepar\Html2pdfBundle\Factory\Html2pdfFactory;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\EventDispatcher\Event;
  16. // #[AsEventListener(event: PdfformEvents::class, method: 'processPdf')]
  17. class GeneratePdfListener implements EventSubscriberInterface
  18. {
  19.     /**
  20.      * @var Html2pdfFactory
  21.      */
  22.   
  23.     private $html2pdfFactory;
  24.     private $generateLmPdf;
  25.     private $entityManager;
  26.     public function __construct(GenerateLmPdf $generateLmPdfEntityManagerInterface $entityManager)
  27.     {
  28.         $this->generateLmPdf $generateLmPdf;
  29.         $this->entityManager $entityManager;
  30.     }
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             PdfformEvents::class => 'processPdf',
  35.         ];
  36.     }
  37.     public function processPdf(PdfformEvents $events)
  38.     {
  39.         if ($events->getNewWorkflow() != $events->getLastWorkflow()) {
  40.             $em $this->entityManager;
  41.             $projetLettreMission $em->getRepository(ProjetLettreMission::class)->find($events->getProjetLetterMission());
  42.             $this->generateLmPdf->generatePdf($projetLettreMission);
  43.         }
  44.     }
  45. }