<?php
namespace App\Subscriber\UserGroups;
use App\Event\UserGroups\ThreadDeletedEvent;
use App\Service\UserGroups\GroupService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class UserGroupThreadSubscriber implements EventSubscriberInterface
{
/**
* @var GroupService
*/
protected $service;
/**
* UserGroupThreadSubscriber constructor.
*/
public function __construct(GroupService $service)
{
$this->service = $service;
}
public static function getSubscribedEvents(): array
{
return [
ThreadDeletedEvent::class => [
['onThreadDeletedCalculateGroupStatPostCount', 0],
],
];
}
/**
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function onThreadDeletedCalculateGroupStatPostCount(ThreadDeletedEvent $event)
{
$thread = $event->getEntity();
$group = $thread->getUserGroup();
$this->service->calculateUserGroupStatPostCount($group);
}
}