src/EventListener/EventRescheduledListener.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Harmonizely\EventListener;
  4. use Harmonizely\Background\Data\EventMailManagerData;
  5. use Harmonizely\Core\BackgroundWork\Contract\IClient;
  6. use Harmonizely\Mailer\AllowedSendingEmailNotificationToInviteePolicy;
  7. use Harmonizely\Model\EventInterface;
  8. use Harmonizely\Service\Core\Contract\ICompanySelector;
  9. use Symfony\Component\EventDispatcher\GenericEvent;
  10. use Webmozart\Assert\Assert;
  11. final class EventRescheduledListener
  12. {
  13.     private AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy;
  14.     private IClient $backgroundClient;
  15.     private ICompanySelector $companySelector;
  16.     public function __construct(
  17.         AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy,
  18.         IClient $backgroundClient,
  19.         ICompanySelector $companySelector
  20.     ) {
  21.         $this->allowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy;
  22.         $this->backgroundClient $backgroundClient;
  23.         $this->companySelector $companySelector;
  24.     }
  25.     public function sendEmail(GenericEvent $event): void
  26.     {
  27.         /** @var EventInterface $event */
  28.         $event $event->getSubject();
  29.         Assert::isInstanceOf($eventEventInterface::class);
  30.         $this->backgroundClient->add(new EventMailManagerData(
  31.             $event->getId(),
  32.             EventMailManagerData::RESCHEDULING_NOTIFY,
  33.             $this->companySelector->getCompany()
  34.         ));
  35.     }
  36.     public function sendReschedulingNotifyToInvitee(GenericEvent $event): void
  37.     {
  38.         /** @var EventInterface $event */
  39.         $event $event->getSubject();
  40.         Assert::isInstanceOf($eventEventInterface::class);
  41.         if (false === ($this->allowedSendingEmailNotificationToInviteePolicy)($event)) {
  42.             return;
  43.         }
  44.         $this->backgroundClient->add(new EventMailManagerData(
  45.             $event->getId(),
  46.             EventMailManagerData::RESCHEDULING_NOTIFY_TO_INVITEE,
  47.             $this->companySelector->getCompany()
  48.         ));
  49.     }
  50. }