<?php declare( strict_types=1 );
namespace App\EventListener;
use App\Event\ReviewEvent;
use App\Event\UnavailabilityEvent;
use App\Manager\CrmManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Twig\Environment;
class UnavailabilitySubscriber implements EventSubscriberInterface
{
private $attachment_dir;
private $mailer;
private $logger;
private $template;
private $crmManager;
public function __construct(
\Swift_Mailer $mailer,
LoggerInterface $logger,
Environment $template
) {
$this->mailer = $mailer;
$this->logger = $logger;
$this->template = $template;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
UnavailabilityEvent::SEND_ADMIN_MAIL => 'sendMail'
];
}
public function sendMail(UnavailabilityEvent $unavailabilityEvent)
{
$experience = $unavailabilityEvent->getExperience();
$message = ( new \Swift_Message() )
->setSubject('[evasion] Une expérience a été marquée indisponible')
// ->setTo([ '[email protected]', '[email protected]', '[email protected]', '[email protected]' ])
// ->setBcc([ '[email protected]', '[email protected]' ])
->setTo(['[email protected]'])
->setFrom([ '[email protected]' => 'Isère Attractivité' ])
->setBody(
$this->template->render('email/unavailability.html.twig', [
'experience' => $experience,
]),
'text/html'
)
;
try {
$this->mailer->send($message);
} catch (\Exception $e) {
$this->logger->error('Error sending email', [ 'message' => $e->getMessage(), 'code' => $e->getCode() ]);
}
}
}