src/Service/EventSubscriber/WelcomeTourSubscriber.php line 51

Open in your IDE?
  1. <?php
  2. namespace Harmonizely\Service\EventSubscriber;
  3. use Harmonizely\Core\Security\Contract\ISecurityHelper;
  4. use Harmonizely\Repository\Contract\IUserRepository;
  5. use Harmonizely\Service\Event\CreateEventTypeEvent;
  6. use Harmonizely\Types\WelcomeTourStepType;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class WelcomeTourSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var ISecurityHelper
  12.      */
  13.     private ISecurityHelper $securityHelper;
  14.     /**
  15.      * @var IUserRepository
  16.      */
  17.     private IUserRepository $userRepository;
  18.     /**
  19.      * @param ISecurityHelper $securityHelper
  20.      * @param IUserRepository $userRepository
  21.      */
  22.     public function __construct(
  23.         ISecurityHelper $securityHelper,
  24.         IUserRepository $userRepository
  25.     )
  26.     {
  27.         $this->securityHelper $securityHelper;
  28.         $this->userRepository $userRepository;
  29.     }
  30.     /**
  31.      * @return string[]
  32.      */
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         return [
  36.             CreateEventTypeEvent::NAME => 'createEventType',
  37.         ];
  38.     }
  39.     /**
  40.      * @param CreateEventTypeEvent $event
  41.      * @return void
  42.      */
  43.     public function createEventType(CreateEventTypeEvent $event): void
  44.     {
  45.         $user $this->securityHelper->getUser();
  46.         if ($user->getWelcomeTourStep() === WelcomeTourStepType::TYPE_EVENT_TYPE) {
  47.             $user->setWelcomeTourStep(WelcomeTourStepType::TYPE_CALENDAR_INTEGRATION);
  48.             $this->userRepository->save($user);
  49.         }
  50.     }
  51. }