src/Subscriber/Content/ContentCheckSubscriber.php line 108

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber\Content;
  3. use App\Dictionary\ContentStatus;
  4. use App\Dictionary\ConversationMessageSource;
  5. use App\Dictionary\ConversationMessageType;
  6. use App\Event\Content\ContentCheckedEvent;
  7. use App\Lib\Content\ContentServiceAwareInterface;
  8. use App\Service\Content\ContentService;
  9. use App\Service\MemberService;
  10. use App\Service\Messenger\MessengerService;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class ContentCheckSubscriber implements EventSubscriberInterfaceContentServiceAwareInterface
  13. {
  14.     protected ContentService $service;
  15.     protected MessengerService $messenger;
  16.     protected MemberService $memberService;
  17.     /**
  18.      * ContentCheckSubscriber constructor.
  19.      */
  20.     public function __construct(ContentService $serviceMessengerService $messengerMemberService $memberService)
  21.     {
  22.         $this->setContentService($service);
  23.         $this->setMessenger($messenger);
  24.         $this->setMemberService($memberService);
  25.     }
  26.     public function setMemberService(MemberService $service): self
  27.     {
  28.         $this->memberService $service;
  29.         return $this;
  30.     }
  31.     public function getMemberService(): MemberService
  32.     {
  33.         return $this->memberService;
  34.     }
  35.     public function setMessenger(MessengerService $service): self
  36.     {
  37.         $this->messenger $service;
  38.         return $this;
  39.     }
  40.     public function getMessenger(): MessengerService
  41.     {
  42.         return $this->messenger;
  43.     }
  44.     public function setContentService(ContentService $service): ContentServiceAwareInterface
  45.     {
  46.         $this->service $service;
  47.         return $this;
  48.     }
  49.     public function getContentService(): ContentService
  50.     {
  51.         return $this->service;
  52.     }
  53.     public static function getSubscribedEvents(): array
  54.     {
  55.         return [
  56.             ContentCheckedEvent::class => [
  57.                 ['onCheckedAndRejected'0],
  58.                 ['onCheckedAndAcceptedSendMessage'1],
  59.             ],
  60.         ];
  61.     }
  62.     /**
  63.      * @throws \Doctrine\ORM\ORMException
  64.      * @throws \Doctrine\ORM\OptimisticLockException
  65.      */
  66.     public function onCheckedAndRejected(ContentCheckedEvent $event)
  67.     {
  68.         if ($event->isAccepted()) {
  69.             return;
  70.         }
  71.         $content $event->getContent();
  72.         $author $content->getMember();
  73.         // change to none not new as of gitlab #486
  74.         // when its set to new, we can only edit the preview images. but most likely, the title, categories,
  75.         // actors need to be changed. so one step back even more.
  76.         $this->service->changeContentStatus($contentContentStatus::NONE);
  77.         // Send messenger message to author (from support)
  78.         $supportMember $this->getMemberService()->getSupportMember();
  79.         $type ConversationMessageType::TEXT;
  80.         $source ConversationMessageSource::SYSTEM;
  81.         $this->getMessenger()->sendDirectMessage($supportMember$author$event->getRejectMessage($content), $type$source);
  82.     }
  83.     /**
  84.      * @throws \Doctrine\ORM\ORMException
  85.      * @throws \Doctrine\ORM\OptimisticLockException
  86.      */
  87.     public function onCheckedAndAcceptedSendMessage(ContentCheckedEvent $event)
  88.     {
  89.         if (!$event->isAccepted()) {
  90.             return;
  91.         }
  92.         $content $event->getContent();
  93.         $author $content->getMember();
  94.         // Send messenger message to author (from support)
  95.         $supportMember $this->getMemberService()->getSupportMember();
  96.         $type ConversationMessageType::TEXT;
  97.         $source ConversationMessageSource::SYSTEM;
  98.         $this->getMessenger()->sendDirectMessage($supportMember$author$event->getAcceptMessage($content), $type$source);
  99.     }
  100. }