src/EventListener/EventCanceledListener.php line 60

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Harmonizely\EventListener;
  4. use Exception;
  5. use Harmonizely\Calendar\ExternalCalendarManager;
  6. use Harmonizely\EmailManager\EventEmailManagerInterface;
  7. use Harmonizely\Mailer\AllowedSendingEmailNotificationToInviteePolicy;
  8. use Harmonizely\Model\EventInterface;
  9. use Psr\Log\LoggerInterface;
  10. use Symfony\Component\EventDispatcher\GenericEvent;
  11. use Webmozart\Assert\Assert;
  12. final class EventCanceledListener
  13. {
  14.     private $eventEmailManager;
  15.     private $externalCalendarManager;
  16.     private $logger;
  17.     private AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy;
  18.     public function __construct(
  19.         EventEmailManagerInterface $eventEmailManager,
  20.         ExternalCalendarManager $externalCalendarManager,
  21.         LoggerInterface $logger,
  22.         AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy
  23.     ) {
  24.         $this->eventEmailManager $eventEmailManager;
  25.         $this->externalCalendarManager $externalCalendarManager;
  26.         $this->logger $logger;
  27.         $this->allowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy;
  28.     }
  29.     public function sendEmail(GenericEvent $event): void
  30.     {
  31.         /** @var EventInterface $event */
  32.         $event $event->getSubject();
  33.         Assert::isInstanceOf($eventEventInterface::class);
  34.         $this->eventEmailManager->sendCancellationNotify($event);
  35.     }
  36.     public function sendCancellationNotifyToInvitee(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->eventEmailManager->sendCancellationNotifyToInvitee($event);
  45.     }
  46.     public function calDavCancel(GenericEvent $event): void
  47.     {
  48.         //TODO - не вызывать при отмене через гугл или аутблук
  49.         /** @var EventInterface $event */
  50.         $event $event->getSubject();
  51.         Assert::isInstanceOf($eventEventInterface::class);
  52.         try {
  53.             $this->externalCalendarManager->remove($event);
  54.         } catch (Exception $e) {
  55.             $this->logger->error($e->getMessage());
  56.         }
  57.     }
  58. }