src/EventListener/NewEventScheduledListener.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 NewEventScheduledListener
  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.         if (false === ($this->allowedSendingEmailNotificationToInviteePolicy)($event)) {
  31.             return;
  32.         }
  33.         if ($event->isRecurring()) {
  34.             return;
  35.         }
  36.         $this->backgroundClient->add(new EventMailManagerData(
  37.             $event->getId(),
  38.             EventMailManagerData::NEW_EVENT_INVITEE_CONFIRMATION_ACTION,
  39.             $this->companySelector->getCompany()
  40.         ));
  41.         $this->backgroundClient->runJobs();
  42.     }
  43.     public function sendNewEventEmailConfirmation(GenericEvent $event): void
  44.     {
  45.         /** @var EventInterface $event */
  46.         $event $event->getSubject();
  47.         Assert::isInstanceOf($eventEventInterface::class);
  48.         if ($event->isRecurring()) {
  49.             return;
  50.         }
  51.         $this->backgroundClient->add(new EventMailManagerData(
  52.             $event->getId(),
  53.             EventMailManagerData::NEW_EVENT_EMAIL_CONFIRMATION,
  54.             $this->companySelector->getCompany()
  55.         ));
  56.         $this->backgroundClient->runJobs();
  57.     }
  58. }