src/EventListener/CallMeBackListener.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Component\Configuration\Util\Config;
  4. use App\Event\CallMeBackSubmitEvent;
  5. use App\Sendgrid\MailerInterface;
  6. use App\Util\StringToEntityUtil;
  7. use Gedmo\Translatable\TranslatableListener;
  8. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  9. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  10. use Symfony\Component\Routing\RouterInterface;
  11. class CallMeBackListener extends FormSubmitEventListener
  12. {
  13.     public const DEFAULT_TEMPLATE_PROPERTIES = [
  14.         'recruiter' => '',
  15.         'vacancy' => '',
  16.         'vacancy_id' => '',
  17.         'vacancy_external_id' => '',
  18.         'vacancy_displayable_external_id' => '',
  19.         'vacancy_url' => '',
  20.     ];
  21.     private RouterInterface $router;
  22.     public function __construct(
  23.         MailerInterface $mailer,
  24.         ParameterBagInterface $parameterBag,
  25.         StringToEntityUtil $stringToEntityUtil,
  26.         ?TranslatableListener $translatableListener,
  27.         Config $config,
  28.         RouterInterface $router
  29.     ) {
  30.         parent::__construct($mailer$parameterBag$stringToEntityUtil$translatableListener$config);
  31.         $this->router $router;
  32.     }
  33.     public function postRequestSubmit(CallMeBackSubmitEvent $event)
  34.     {
  35.         $contact $event->getRequest();
  36.         if ($siteOwnerMail $this->getMail('site_call_me_back_mail_site_owner')) {
  37.             $templateProperties self::DEFAULT_TEMPLATE_PROPERTIES;
  38.             $templateProperties['request'] = $contact;
  39.             $recipient $this->getCompanyEmailaddress();
  40.             if ($this->config->get('site_call_me_back_custom_system_recipient')) {
  41.                 $recipient $this->config->get('site_call_me_back_custom_system_recipient');
  42.             }
  43.             if ($contact->getRecruiter() && $contact->getRecruiter()->getEmail()) {
  44.                 $recipient $contact->getRecruiter()->getEmail();
  45.                 $templateProperties['recruiter'] = $contact->getRecruiter()->getName();
  46.             }
  47.             if (!empty($contact->getVacancy())
  48.                 && !empty($contact->getVacancy()->getRecruiter())
  49.                 && $recruiter $contact->getVacancy()->getRecruiter()) {
  50.                 $recipient $recruiter->getEmail();
  51.                 $templateProperties['vacancy'] = $contact->getVacancy()->getTitle();
  52.                 $templateProperties['vacancy_id'] = $contact->getVacancy()->getId();
  53.                 $templateProperties['vacancy_external_id'] = $contact->getVacancy()->getExternalId();
  54.                 $templateProperties['vacancy_displayable_external_id'] = $contact->getVacancy()->getDisplayableExternalId();
  55.                 $templateProperties['vacancy_url'] = $this->router->generate(
  56.                     'vacancy_detail',
  57.                     ['id' => $contact->getVacancy()->getId(), 'slug' => $contact->getVacancy()->getSlug()],
  58.                     UrlGeneratorInterface::ABSOLUTE_URL
  59.                 );
  60.                 // Set recruiter from related vacancy, if call me back request has related vacancy.
  61.                 $templateProperties['recruiter'] = $recruiter->getName();
  62.             }
  63.             $this->mailer->mail(
  64.                 $siteOwnerMail,
  65.                 $this->getCompanyEmailSender(),
  66.                 [$recipient],
  67.                 $templateProperties
  68.             );
  69.         }
  70.     }
  71. }