src/Service/Panel/Api/PushNotification/EventSubscriber/PushNotificationSubscriber.php line 73

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