<?php
namespace App\Subscriber\Content;
use App\Dictionary\ContentStatus;
use App\Event\Content\ContentPreviewsSelectedEvent;
use App\Event\Content\ImagesetPixelatedEvent;
use App\Lib\Content\ContentServiceAwareInterface;
use App\Service\Content\ContentService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ContentStatusSubscriber implements EventSubscriberInterface, ContentServiceAwareInterface
{
protected ContentService $contentService;
/**
* ContentStatusSubscriber constructor.
*/
public function __construct(ContentService $service)
{
$this->setContentService($service);
}
public function getContentService(): ContentService
{
return $this->contentService;
}
public function setContentService(ContentService $service): ContentServiceAwareInterface
{
$this->contentService = $service;
return $this;
}
public static function getSubscribedEvents(): array
{
return [
ImagesetPixelatedEvent::class => [
['onImagesetPixelatedUpdateContent', 0],
],
ContentPreviewsSelectedEvent::class => [
['onContentPreviewsSelectedUpdateContent', 0],
],
];
}
/**
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function onImagesetPixelatedUpdateContent(ImagesetPixelatedEvent $event)
{
$content = $event->getEntity()->getContent();
$content->setStatus(ContentStatus::SELFRATED);
$this->getContentService()->storeEntity($content);
}
/**
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function onContentPreviewsSelectedUpdateContent(ContentPreviewsSelectedEvent $event)
{
$content = $event->getEntity();
$content->setStatus(ContentStatus::PREVIEWSCHOSEN);
$this->getContentService()->storeEntity($content);
}
}