src/Subscriber/Content/ContentStatusSubscriber.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber\Content;
  3. use App\Dictionary\ContentStatus;
  4. use App\Event\Content\ContentPreviewsSelectedEvent;
  5. use App\Event\Content\ImagesetPixelatedEvent;
  6. use App\Lib\Content\ContentServiceAwareInterface;
  7. use App\Service\Content\ContentService;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class ContentStatusSubscriber implements EventSubscriberInterfaceContentServiceAwareInterface
  10. {
  11.     protected ContentService $contentService;
  12.     /**
  13.      * ContentStatusSubscriber constructor.
  14.      */
  15.     public function __construct(ContentService $service)
  16.     {
  17.         $this->setContentService($service);
  18.     }
  19.     public function getContentService(): ContentService
  20.     {
  21.         return $this->contentService;
  22.     }
  23.     public function setContentService(ContentService $service): ContentServiceAwareInterface
  24.     {
  25.         $this->contentService $service;
  26.         return $this;
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             ImagesetPixelatedEvent::class => [
  32.                 ['onImagesetPixelatedUpdateContent'0],
  33.             ],
  34.             ContentPreviewsSelectedEvent::class => [
  35.                 ['onContentPreviewsSelectedUpdateContent'0],
  36.             ],
  37.         ];
  38.     }
  39.     /**
  40.      * @throws \Doctrine\ORM\ORMException
  41.      * @throws \Doctrine\ORM\OptimisticLockException
  42.      */
  43.     public function onImagesetPixelatedUpdateContent(ImagesetPixelatedEvent $event)
  44.     {
  45.         $content $event->getEntity()->getContent();
  46.         $content->setStatus(ContentStatus::SELFRATED);
  47.         $this->getContentService()->storeEntity($content);
  48.     }
  49.     /**
  50.      * @throws \Doctrine\ORM\ORMException
  51.      * @throws \Doctrine\ORM\OptimisticLockException
  52.      */
  53.     public function onContentPreviewsSelectedUpdateContent(ContentPreviewsSelectedEvent $event)
  54.     {
  55.         $content $event->getEntity();
  56.         $content->setStatus(ContentStatus::PREVIEWSCHOSEN);
  57.         $this->getContentService()->storeEntity($content);
  58.     }
  59. }