src/Service/Panel/Api/Zapier/EventSubscriber/ZapierNotificationSubscriber.php line 70

Open in your IDE?
  1. <?php
  2. namespace Harmonizely\Service\Panel\Api\Zapier\EventSubscriber;
  3. use Harmonizely\Background\Data\ZapierNotificationData;
  4. use Harmonizely\CalendarEvents;
  5. use Harmonizely\Core\BackgroundWork\Contract\IClient;
  6. use Harmonizely\Model\Event;
  7. use Harmonizely\Service\Core\Contract\ICompanySelector;
  8. use Harmonizely\Types\Company\ZapierNotificationType;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\EventDispatcher\GenericEvent;
  11. class ZapierNotificationSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var IClient
  15.      */
  16.     private IClient $backgroundClient;
  17.     /**
  18.      * @var ICompanySelector
  19.      */
  20.     private ICompanySelector $companySelector;
  21.     /**
  22.      * @param IClient $backgroundClient
  23.      * @param ICompanySelector $companySelector
  24.      */
  25.     public function __construct(
  26.         IClient $backgroundClient,
  27.         ICompanySelector $companySelector
  28.     )
  29.     {
  30.         $this->backgroundClient $backgroundClient;
  31.         $this->companySelector $companySelector;
  32.     }
  33.     /**
  34.      * @return string[]
  35.      */
  36.     public static function getSubscribedEvents(): array
  37.     {
  38.         return [
  39.             CalendarEvents::EVENT_POST_CREATE => 'create',
  40.             CalendarEvents::EVENT_POST_RESCHEDULE => 'reschedule',
  41.             CalendarEvents::EVENT_POST_CANCEL => 'cancel',
  42.         ];
  43.     }
  44.     /**
  45.      * @param GenericEvent $genericEvent
  46.      * @return void
  47.      */
  48.     public function create(GenericEvent $genericEvent): void
  49.     {
  50.         /** @var Event $event */
  51.         $event $genericEvent->getSubject();
  52.         $this->backgroundClient->add(new ZapierNotificationData(
  53.             ZapierNotificationType::TYPE_EVENT_CREATE,
  54.             $event->getId(),
  55.             $this->companySelector->getCompany()
  56.         ));
  57.         $this->backgroundClient->runJobs();
  58.     }
  59.     /**
  60.      * @param GenericEvent $genericEvent
  61.      * @return void
  62.      */
  63.     public function reschedule(GenericEvent $genericEvent): void
  64.     {
  65.         /** @var Event $event */
  66.         $event $genericEvent->getSubject();
  67.         $this->backgroundClient->add(new ZapierNotificationData(
  68.             ZapierNotificationType::TYPE_EVENT_RESCHEDULE,
  69.             $event->getId(),
  70.             $this->companySelector->getCompany()
  71.         ));
  72.         $this->backgroundClient->runJobs();
  73.     }
  74.     /**
  75.      * @param GenericEvent $genericEvent
  76.      * @return void
  77.      */
  78.     public function cancel(GenericEvent $genericEvent): void
  79.     {
  80.         /** @var Event $event */
  81.         $event $genericEvent->getSubject();
  82.         $this->backgroundClient->add(new ZapierNotificationData(
  83.             ZapierNotificationType::TYPE_EVENT_CANCEL,
  84.             $event->getId(),
  85.             $this->companySelector->getCompany()
  86.         ));
  87.         $this->backgroundClient->runJobs();
  88.     }
  89. }