src/Core/Application/EventSubscriber/Chat/KickUserOutOfChannelSubscriber.php line 35

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Core\Application\EventSubscriber\Chat;
  4. use App\Core\Application\Event\Chat\KickUserOutOfChannelEvent;
  5. use App\Core\Application\Service\RocketChat\RocketChatClientServiceInterface;
  6. use App\Core\Domain\Entity\ChatSetting\ChatChannel;
  7. use App\Core\Domain\Entity\Student\Student;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class KickUserOutOfChannelSubscriber implements EventSubscriberInterface
  11. {
  12.     private readonly RocketChatClientServiceInterface $rocketChatClientService;
  13.     private readonly EntityManagerInterface $em;
  14.     public function __construct(
  15.         EntityManagerInterface $em,
  16.         RocketChatClientServiceInterface $rocketChatClientService,
  17.     ) {
  18.         $this->rocketChatClientService $rocketChatClientService;
  19.         $this->em $em;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             KickUserOutOfChannelEvent::class => 'kickUserOfChannel',
  25.         ];
  26.     }
  27.     public function kickUserOfChannel(KickUserOutOfChannelEvent $event): void
  28.     {
  29.         $user $event->user;
  30.         if ($user instanceof Student) {
  31.             $channels $user->getChatSetting()->getChatChannels();
  32.             /* @var ChatChannel $channel */
  33.             foreach ($channels as $channel) {
  34.                 /** @TODO Add logic that will retrieve the information about the completed subscription for the course and pass the channel */
  35.                 $this->rocketChatClientService->kickUserOurOfChannel($channel->getChatChannelId(), $user->getChatSetting()->getChatUserId());
  36.             }
  37.         }
  38.     }
  39. }