src/Form/EventSubscriber/LogCampaignActivitySubscriber.php line 82
<?phpdeclare(strict_types=1);/*** Copyright (c) 2023 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2023 TECLA Consulting Group oü*/namespace App\Form\EventSubscriber;use App\Contact\Model\ContactInterface;use App\Form\Event\FormContact;use App\Form\Event\FormContactCompanyForSale;use App\Form\Event\FormContactEstablishCompany;use App\Form\Event\FormContactHseCard;use App\Form\Event\FormContactSellCompany;use App\Form\Event\FormContactService;use App\Marketing\Dto\Factory\CampaignActivityDtoFactoryInterface;use App\Marketing\Enum\CampaignActivityType;use App\Marketing\Model\CampaignInterface;use App\Marketing\Service\CampaignActivityServiceInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;final class LogCampaignActivitySubscriber implements EventSubscriberInterface{private CampaignActivityDtoFactoryInterface $campaignActivityDtoFactory;private CampaignActivityServiceInterface $campaignActivityService;public function __construct(CampaignActivityDtoFactoryInterface $campaignActivityDtoFactory,CampaignActivityServiceInterface $campaignActivityService) {$this->campaignActivityDtoFactory = $campaignActivityDtoFactory;$this->campaignActivityService = $campaignActivityService;}public static function getSubscribedEvents(): array{return [FormContact\CreatedEvent::class => 'onFormContactCreatedEvent',FormContactCompanyForSale\CreatedEvent::class => 'onFormContactCompanyForSaleCreatedEvent',FormContactEstablishCompany\CreatedEvent::class => 'onFormContactEstablishCompanyCreatedEvent',FormContactHseCard\CreatedEvent::class => 'onFormContactHseCardCreatedEvent',FormContactSellCompany\CreatedEvent::class => 'onFormContactSellCompanyCreatedEvent',FormContactService\CreatedEvent::class => 'onFormContactServiceCreatedEvent',];}public function onFormContactCreatedEvent(FormContact\CreatedEvent $event): void{$form = $event->getForm();if (null === $form->getCampaign()) {return;}$this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());}public function onFormContactCompanyForSaleCreatedEvent(FormContactCompanyForSale\CreatedEvent $event): void{$form = $event->getForm();if (null === $form->getCampaign()) {return;}$this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());}public function onFormContactEstablishCompanyCreatedEvent(FormContactEstablishCompany\CreatedEvent $event): void{$form = $event->getForm();if (null === $form->getCampaign()) {return;}$this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());}public function onFormContactHseCardCreatedEvent(FormContactHseCard\CreatedEvent $event): void{$form = $event->getForm();if (null === $form->getCampaign()) {return;}$this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());}public function onFormContactSellCompanyCreatedEvent(FormContactSellCompany\CreatedEvent $event): void{$form = $event->getForm();if (null === $form->getCampaign()) {return;}$this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());}public function onFormContactServiceCreatedEvent(FormContactService\CreatedEvent $event): void{$form = $event->getForm();if (null === $form->getCampaign()) {return;}$this->logCampaignActivity($form->getCampaign(), $form->getSubmittedBy());}private function logCampaignActivity(CampaignInterface $campaign, ContactInterface $contact): void{$dto = $this->campaignActivityDtoFactory->create()->setCampaign($campaign->getId())->setContact($contact->getId())->setType(CampaignActivityType::LEAD());$this->campaignActivityService->createFromDto($dto);}}