<?php
namespace App\EventListener;
use App\Component\Configuration\Util\Config;
use App\Event\JobAlertCreatedEvent;
use App\Sendgrid\MailerInterface;
use App\Service\SiteService;
use App\Util\StringToEntityUtil;
use Gedmo\Translatable\TranslatableListener;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class JobAlertCreatedEventListener extends FormSubmitEventListener
{
private SiteService $siteService;
public function __construct(
MailerInterface $mailer,
ParameterBagInterface $parameterBag,
StringToEntityUtil $stringToEntityUtil,
?TranslatableListener $translatableListener,
Config $config,
SiteService $siteService
) {
parent::__construct($mailer, $parameterBag, $stringToEntityUtil, $translatableListener, $config);
$this->siteService = $siteService;
}
public function jobAlertCreated(JobAlertCreatedEvent $event)
{
if (false === $this->config->get('site_jobalert_company_send_mail')
|| null === $this->config->get('site_jobalert_company_email')
) {
return;
}
$companyMail = $this->getMail('site_jobalert_company_email');
$companyMailAddress = $this->config->get('site_jobalert_company_email_address')
?: $this->getCompanyEmailaddress();
if ($companyMail && $companyMailAddress) {
$this->mailer->mail(
$companyMail,
$this->getCompanyEmailSender(),
[$companyMailAddress],
['jobAlert' => $event->getJobAlert(), 'site' => $this->siteService->getSite()],
);
}
}
}