src/EventSubscriber/SendParticipantInviteEventPostCreateSubscriber.php line 60

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Harmonizely\EventSubscriber;
  4. use Harmonizely\CalendarEvents;
  5. use Harmonizely\Core\Security\Contract\ISecurityHelper;
  6. use Harmonizely\Model\EventInterface;
  7. use Harmonizely\Model\ParticipantInterface;
  8. use Harmonizely\Twig\isBookingFromAdmin;
  9. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\EventDispatcher\GenericEvent;
  12. final class SendParticipantInviteEventPostCreateSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @var EventDispatcherInterface
  16.      */
  17.     private EventDispatcherInterface $eventDispatcher;
  18.     /**
  19.      * @var ISecurityHelper
  20.      */
  21.     private ISecurityHelper $securityHelper;
  22.     private isBookingFromAdmin $isBookingFromAdmin;
  23.     /**
  24.      * @param EventDispatcherInterface $eventDispatcher
  25.      * @param ISecurityHelper $securityHelper
  26.      * @param isBookingFromAdmin $isBookingFromAdmin
  27.      */
  28.     public function __construct(
  29.         EventDispatcherInterface $eventDispatcher,
  30.         ISecurityHelper $securityHelper,
  31.         isBookingFromAdmin $isBookingFromAdmin
  32.     )
  33.     {
  34.         $this->eventDispatcher $eventDispatcher;
  35.         $this->securityHelper $securityHelper;
  36.         $this->isBookingFromAdmin $isBookingFromAdmin;
  37.     }
  38.     /**
  39.      * @return string[]
  40.      */
  41.     public static function getSubscribedEvents(): array
  42.     {
  43.         return [
  44.             CalendarEvents::EVENT_POST_CREATE => 'sendParticipantInviteEventPostCreate',
  45.         ];
  46.     }
  47.     /**
  48.      * @param GenericEvent $genericEvent
  49.      */
  50.     public function sendParticipantInviteEventPostCreate(GenericEvent $genericEvent): void
  51.     {
  52.         /** @var EventInterface $event */
  53.         $event $genericEvent->getSubject();
  54.         $isBookingFromAdmin $this->securityHelper->getUser() || $this->isBookingFromAdmin->isBookingFromAdmin();
  55.         if ($event->getEventType()->isClientCanAddParticipants() || $isBookingFromAdmin) {
  56.             $participantsEmails = [];
  57.             /** @var ParticipantInterface $participant */
  58.             foreach ($event->getParticipants() as $participant) {
  59.                 $participantsEmails[] = $participant->getEmail();
  60.             }
  61.             if (!empty($participantsEmails)) {
  62.                 $this->eventDispatcher->dispatch(new GenericEvent($event, [
  63.                     'emails' => $participantsEmails,
  64.                     'message' => null,
  65.                     'inviter' => $event->getInvitee()->getFullName()
  66.                 ]), CalendarEvents::EVENT_POST_INVITE_MORE);
  67.             }
  68.         }
  69.     }
  70. }