<?php
namespace App\EventListener;
use App\Component\Configuration\Util\Config;
use App\Event\LearningTrackContactSubmitEvent;
use App\Sendgrid\MailerInterface;
use App\Util\StringToEntityUtil;
use Doctrine\ORM\EntityManagerInterface;
use Flagception\Manager\FeatureManagerInterface;
use Gedmo\Translatable\TranslatableListener;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class LearningTrackContactListener extends FormSubmitEventListener
{
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
private FeatureManagerInterface $featureManager;
/**
* LearningTrackContactListener constructor.
*/
public function __construct(
EntityManagerInterface $em,
EventDispatcherInterface $eventDispatcher,
MailerInterface $mailer,
ParameterBagInterface $parameterBag,
StringToEntityUtil $stringToEntityUtil,
FeatureManagerInterface $featureManager,
?TranslatableListener $translatableListener,
Config $config
) {
parent::__construct($mailer, $parameterBag, $stringToEntityUtil, $translatableListener, $config);
$this->em = $em;
$this->eventDispatcher = $eventDispatcher;
$this->featureManager = $featureManager;
}
public function postContactSubmit(LearningTrackContactSubmitEvent $event)
{
if (!$this->featureManager->isActive('feature_learning_track_contact')) {
return;
}
$contact = $event->getLearningTrackContact();
if (!$siteOwnerMail = $this->getMail('site_learning_track_contact_mail_site_owner')) {
return;
}
$recipient = $this->parameterBag->get('site_learning_track_contact_custom_system_recipient') ?:
$this->parameterBag->get('site_company_email_address');
$this->mailer->mail(
$siteOwnerMail,
$this->getCompanyEmailSender(),
[$recipient],
['contact' => $contact]
);
}
}