src/Form/EventSubscriber/LogCampaignActivitySubscriber.php line 93

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Copyright (c) 2023 TECLA Consulting Group oü.
  5.  * All rights reserved.
  6.  *
  7.  * This unpublished material is proprietary to TECLA Consulting Group oü.
  8.  * All rights reserved. The methods and
  9.  * techniques described herein are considered trade secrets
  10.  * and/or confidential. Reproduction or distribution, in whole
  11.  * or in part, is forbidden except by express written permission
  12.  * of TECLA Consulting Group oü.
  13.  *
  14.  * @author    Matúš Sýkorjak <matus@tecla.no>
  15.  * @copyright 2023 TECLA Consulting Group oü
  16.  */
  17. namespace App\Form\EventSubscriber;
  18. use App\Contact\Model\ContactInterface;
  19. use App\Form\Event\FormContact;
  20. use App\Form\Event\FormContactCompanyForSale;
  21. use App\Form\Event\FormContactEstablishCompany;
  22. use App\Form\Event\FormContactHseCard;
  23. use App\Form\Event\FormContactSellCompany;
  24. use App\Form\Event\FormContactService;
  25. use App\Marketing\Dto\Factory\CampaignActivityDtoFactoryInterface;
  26. use App\Marketing\Enum\CampaignActivityType;
  27. use App\Marketing\Model\CampaignInterface;
  28. use App\Marketing\Service\CampaignActivityServiceInterface;
  29. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  30. final class LogCampaignActivitySubscriber implements EventSubscriberInterface
  31. {
  32.     private CampaignActivityDtoFactoryInterface $campaignActivityDtoFactory;
  33.     private CampaignActivityServiceInterface $campaignActivityService;
  34.     public function __construct(
  35.         CampaignActivityDtoFactoryInterface $campaignActivityDtoFactory,
  36.         CampaignActivityServiceInterface $campaignActivityService
  37.     ) {
  38.         $this->campaignActivityDtoFactory $campaignActivityDtoFactory;
  39.         $this->campaignActivityService $campaignActivityService;
  40.     }
  41.     public static function getSubscribedEvents(): array
  42.     {
  43.         return [
  44.             FormContact\CreatedEvent::class => 'onFormContactCreatedEvent',
  45.             FormContactCompanyForSale\CreatedEvent::class => 'onFormContactCompanyForSaleCreatedEvent',
  46.             FormContactEstablishCompany\CreatedEvent::class => 'onFormContactEstablishCompanyCreatedEvent',
  47.             FormContactHseCard\CreatedEvent::class => 'onFormContactHseCardCreatedEvent',
  48.             FormContactSellCompany\CreatedEvent::class => 'onFormContactSellCompanyCreatedEvent',
  49.             FormContactService\CreatedEvent::class => 'onFormContactServiceCreatedEvent',
  50.         ];
  51.     }
  52.     public function onFormContactCreatedEvent(FormContact\CreatedEvent $event): void
  53.     {
  54.         $form $event->getForm();
  55.         if (null === $form->getCampaign()) {
  56.             return;
  57.         }
  58.         $this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());
  59.     }
  60.     public function onFormContactCompanyForSaleCreatedEvent(FormContactCompanyForSale\CreatedEvent $event): void
  61.     {
  62.         $form $event->getForm();
  63.         if (null === $form->getCampaign()) {
  64.             return;
  65.         }
  66.         $this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());
  67.     }
  68.     public function onFormContactEstablishCompanyCreatedEvent(FormContactEstablishCompany\CreatedEvent $event): void
  69.     {
  70.         $form $event->getForm();
  71.         if (null === $form->getCampaign()) {
  72.             return;
  73.         }
  74.         $this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());
  75.     }
  76.     public function onFormContactHseCardCreatedEvent(FormContactHseCard\CreatedEvent $event): void
  77.     {
  78.         $form $event->getForm();
  79.         if (null === $form->getCampaign()) {
  80.             return;
  81.         }
  82.         $this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());
  83.     }
  84.     public function onFormContactSellCompanyCreatedEvent(FormContactSellCompany\CreatedEvent $event): void
  85.     {
  86.         $form $event->getForm();
  87.         if (null === $form->getCampaign()) {
  88.             return;
  89.         }
  90.         $this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());
  91.     }
  92.     public function onFormContactServiceCreatedEvent(FormContactService\CreatedEvent $event): void
  93.     {
  94.         $form $event->getForm();
  95.         if (null === $form->getCampaign()) {
  96.             return;
  97.         }
  98.         $this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());
  99.     }
  100.     private function logCampaignActivity(CampaignInterface $campaignContactInterface $contact): void
  101.     {
  102.         $dto $this->campaignActivityDtoFactory->create()
  103.             ->setCampaign($campaign->getId())
  104.             ->setContact($contact->getId())
  105.             ->setType(CampaignActivityType::LEAD())
  106.         ;
  107.         $this->campaignActivityService->createFromDto($dto);
  108.     }
  109. }