vendor/ibexa/scheduler/src/lib/Event/Subscriber/QuickReviewEventSubscriber.php line 56

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\Scheduler\Event\Subscriber;
  8. use Ibexa\Contracts\Core\Repository\NotificationService;
  9. use Ibexa\Contracts\Scheduler\Repository\DateBasedPublishServiceInterface;
  10. use Ibexa\Scheduler\ValueObject\NotificationFactory;
  11. use JMS\TranslationBundle\Annotation\Desc;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\Workflow\Event\CompletedEvent;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. class QuickReviewEventSubscriber implements EventSubscriberInterface
  16. {
  17.     /** @var \Ibexa\Contracts\Scheduler\Repository\DateBasedPublishServiceInterface */
  18.     private $dateBasedPublisherService;
  19.     /** @var \Ibexa\Contracts\Core\Repository\NotificationService */
  20.     private $notificationService;
  21.     /** @var \Ibexa\Scheduler\ValueObject\NotificationFactory */
  22.     private $notificationFactory;
  23.     /** @var \Symfony\Contracts\Translation\TranslatorInterface */
  24.     private $translator;
  25.     public function __construct(
  26.         DateBasedPublishServiceInterface $dateBasedPublisherService,
  27.         NotificationService $notificationService,
  28.         NotificationFactory $notificationFactory,
  29.         TranslatorInterface $translator
  30.     ) {
  31.         $this->dateBasedPublisherService $dateBasedPublisherService;
  32.         $this->notificationService $notificationService;
  33.         $this->notificationFactory $notificationFactory;
  34.         $this->translator $translator;
  35.     }
  36.     public static function getSubscribedEvents(): array
  37.     {
  38.         return [
  39.             'workflow.quick_review.completed' => ['onQuickReview'0],
  40.         ];
  41.     }
  42.     /**
  43.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
  44.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
  45.      */
  46.     public function onQuickReview(CompletedEvent $event)
  47.     {
  48.         /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */
  49.         $content $event->getSubject();
  50.         $scheduledVersions $this->dateBasedPublisherService->getVersionsEntriesForContent($content->id);
  51.         /** @var \Ibexa\Contracts\Scheduler\ValueObject\ScheduledEntry $scheduledVersion */
  52.         foreach ($scheduledVersions as $scheduledVersion) {
  53.             $this->dateBasedPublisherService->unschedulePublish(
  54.                 $scheduledVersion->versionInfo->id
  55.             );
  56.             $createStruct $this->notificationFactory->getNotificationCreateStruct($scheduledVersionNotificationFactory::TYPE_UNSCHEDULED);
  57.             $createStruct->data['message'] = $this->translator->trans(/** @Desc("Content sent to review") */
  58.                 'content.in_review',
  59.                 [],
  60.                 'ibexa_scheduler'
  61.             );
  62.             $this->notificationService->createNotification($createStruct);
  63.         }
  64.     }
  65. }
  66. class_alias(QuickReviewEventSubscriber::class, 'EzSystems\DateBasedPublisher\Core\Event\Subscriber\QuickReviewEventSubscriber');