<?php
namespace Harmonizely\Service\EventSubscriber;
use Harmonizely\Background\Data\DirectoryDeleteCompanyEventData;
use Harmonizely\Background\Data\DirectorySaveCompanyEventData;
use Harmonizely\Background\Data\PushNotificationData;
use Harmonizely\CalendarEvents;
use Harmonizely\Core\BackgroundWork\Contract\IClient;
use Harmonizely\Core\Security\Contract\ISecurityHelper;
use Harmonizely\Entity\RoutingFormResultEntity;
use Harmonizely\Model\Event;
use Harmonizely\Model\EventTypeInterface;
use Harmonizely\Organization\OrganizationEvents;
use Harmonizely\Repository\Contract\IRoutingFormResultRepository;
use Harmonizely\Service\Event\CreateEventTypeEvent;
use Harmonizely\Service\Event\DeleteEventTypeEvent;
use Harmonizely\Service\Event\UpdateEventTypeEvent;
use Harmonizely\Types\UserDeviceNotificationType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class RoutingFormResultSubscriber implements EventSubscriberInterface
{
/**
* @var SessionInterface
*/
private SessionInterface $session;
/**
* @var IRoutingFormResultRepository
*/
private IRoutingFormResultRepository $routingFormResultRepository;
/**
* @param SessionInterface $session
* @param IRoutingFormResultRepository $routingFormResultRepository
*/
public function __construct(
SessionInterface $session,
IRoutingFormResultRepository $routingFormResultRepository
)
{
$this->session = $session;
$this->routingFormResultRepository = $routingFormResultRepository;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
CalendarEvents::EVENT_POST_CREATE => 'postCreateEvent',
];
}
/**
* @param GenericEvent $genericEvent
* @return void
*/
public function postCreateEvent(GenericEvent $genericEvent): void
{
/** @var Event $event */
$event = $genericEvent->getSubject();
$routingFormResultId = $this->session->get(RoutingFormResultEntity::ROUTING_FORM_RESULT_SESSION_KEY);
if ($routingFormResultId) {
$routingFormResult = $this->routingFormResultRepository->findOneById($routingFormResultId);
if ($routingFormResult) {
$eventType = $routingFormResult->getRoutingFormRoute()->getEventType();
if ($eventType === $event->getEventType()) {
$routingFormResult->setEvent($event);
$this->routingFormResultRepository->save($routingFormResult);
}
}
}
$this->session->remove(RoutingFormResultEntity::ROUTING_FORM_RESULT_SESSION_KEY);
}
}