<?php
namespace Harmonizely\Service\EventSubscriber;
use Harmonizely\Core\Security\Contract\ISecurityHelper;
use Harmonizely\Repository\Contract\IUserRepository;
use Harmonizely\Service\Event\CreateEventTypeEvent;
use Harmonizely\Types\WelcomeTourStepType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class WelcomeTourSubscriber implements EventSubscriberInterface
{
/**
* @var ISecurityHelper
*/
private ISecurityHelper $securityHelper;
/**
* @var IUserRepository
*/
private IUserRepository $userRepository;
/**
* @param ISecurityHelper $securityHelper
* @param IUserRepository $userRepository
*/
public function __construct(
ISecurityHelper $securityHelper,
IUserRepository $userRepository
)
{
$this->securityHelper = $securityHelper;
$this->userRepository = $userRepository;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
CreateEventTypeEvent::NAME => 'createEventType',
];
}
/**
* @param CreateEventTypeEvent $event
* @return void
*/
public function createEventType(CreateEventTypeEvent $event): void
{
$user = $this->securityHelper->getUser();
if ($user->getWelcomeTourStep() === WelcomeTourStepType::TYPE_EVENT_TYPE) {
$user->setWelcomeTourStep(WelcomeTourStepType::TYPE_CALENDAR_INTEGRATION);
$this->userRepository->save($user);
}
}
}