src/Service/EventSubscriber/RoutingFormResultSubscriber.php line 64

Open in your IDE?
  1. <?php
  2. namespace Harmonizely\Service\EventSubscriber;
  3. use Harmonizely\Background\Data\DirectoryDeleteCompanyEventData;
  4. use Harmonizely\Background\Data\DirectorySaveCompanyEventData;
  5. use Harmonizely\Background\Data\PushNotificationData;
  6. use Harmonizely\CalendarEvents;
  7. use Harmonizely\Core\BackgroundWork\Contract\IClient;
  8. use Harmonizely\Core\Security\Contract\ISecurityHelper;
  9. use Harmonizely\Entity\RoutingFormResultEntity;
  10. use Harmonizely\Model\Event;
  11. use Harmonizely\Model\EventTypeInterface;
  12. use Harmonizely\Organization\OrganizationEvents;
  13. use Harmonizely\Repository\Contract\IRoutingFormResultRepository;
  14. use Harmonizely\Service\Event\CreateEventTypeEvent;
  15. use Harmonizely\Service\Event\DeleteEventTypeEvent;
  16. use Harmonizely\Service\Event\UpdateEventTypeEvent;
  17. use Harmonizely\Types\UserDeviceNotificationType;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. use Symfony\Component\EventDispatcher\GenericEvent;
  20. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  21. class RoutingFormResultSubscriber implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * @var SessionInterface
  25.      */
  26.     private SessionInterface $session;
  27.     /**
  28.      * @var IRoutingFormResultRepository
  29.      */
  30.     private IRoutingFormResultRepository $routingFormResultRepository;
  31.     /**
  32.      * @param SessionInterface $session
  33.      * @param IRoutingFormResultRepository $routingFormResultRepository
  34.      */
  35.     public function __construct(
  36.         SessionInterface $session,
  37.         IRoutingFormResultRepository $routingFormResultRepository
  38.     )
  39.     {
  40.         $this->session $session;
  41.         $this->routingFormResultRepository $routingFormResultRepository;
  42.     }
  43.     /**
  44.      * @return string[]
  45.      */
  46.     public static function getSubscribedEvents(): array
  47.     {
  48.         return [
  49.             CalendarEvents::EVENT_POST_CREATE => 'postCreateEvent',
  50.         ];
  51.     }
  52.     /**
  53.      * @param GenericEvent $genericEvent
  54.      * @return void
  55.      */
  56.     public function postCreateEvent(GenericEvent $genericEvent): void
  57.     {
  58.         /** @var Event $event */
  59.         $event $genericEvent->getSubject();
  60.         $routingFormResultId $this->session->get(RoutingFormResultEntity::ROUTING_FORM_RESULT_SESSION_KEY);
  61.         if ($routingFormResultId) {
  62.             $routingFormResult $this->routingFormResultRepository->findOneById($routingFormResultId);
  63.             if ($routingFormResult) {
  64.                 $eventType $routingFormResult->getRoutingFormRoute()->getEventType();
  65.                 if ($eventType === $event->getEventType()) {
  66.                     $routingFormResult->setEvent($event);
  67.                     $this->routingFormResultRepository->save($routingFormResult);
  68.                 }
  69.             }
  70.         }
  71.         $this->session->remove(RoutingFormResultEntity::ROUTING_FORM_RESULT_SESSION_KEY);
  72.     }
  73. }