src/EventListener/UnavailabilitySubscriber.php line 40

Open in your IDE?
  1. <?php declare( strict_types=);
  2. namespace App\EventListener;
  3. use App\Event\ReviewEvent;
  4. use App\Event\UnavailabilityEvent;
  5. use App\Manager\CrmManager;
  6. use Psr\Log\LoggerInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Twig\Environment;
  9. class UnavailabilitySubscriber implements EventSubscriberInterface
  10. {
  11.     private $attachment_dir;
  12.     private $mailer;
  13.     private $logger;
  14.     private $template;
  15.     private $crmManager;
  16.     public function __construct(
  17.         \Swift_Mailer $mailer,
  18.         LoggerInterface $logger,
  19.         Environment $template
  20.     ) {
  21.         $this->mailer   $mailer;
  22.         $this->logger   $logger;
  23.         $this->template $template;
  24.     }
  25.     /**
  26.      * @return array
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             UnavailabilityEvent::SEND_ADMIN_MAIL => 'sendMail'
  32.         ];
  33.     }
  34.     public function sendMail(UnavailabilityEvent $unavailabilityEvent)
  35.     {
  36.         $experience  $unavailabilityEvent->getExperience();
  37.         $message = ( new \Swift_Message() )
  38.             ->setSubject('[evasion] Une expérience a été marquée indisponible')
  39. //            ->setTo([ '[email protected]', '[email protected]', '[email protected]', '[email protected]' ])
  40. //            ->setBcc([ '[email protected]', '[email protected]' ])
  41.                 ->setTo(['[email protected]'])
  42.             ->setFrom([ '[email protected]=> 'Isère Attractivité' ])
  43.             ->setBody(
  44.                 $this->template->render('email/unavailability.html.twig', [
  45.                     'experience' => $experience,
  46.                 ]),
  47.                 'text/html'
  48.             )
  49.         ;
  50.         try {
  51.             $this->mailer->send($message);
  52.         } catch (\Exception $e) {
  53.             $this->logger->error('Error sending email', [ 'message' => $e->getMessage(), 'code' => $e->getCode() ]);
  54.         }
  55.     }
  56. }