<?php
namespace Aqarmap\Bundle\DiscussionBundle\EventListener;
use Aqarmap\Bundle\NotificationBundle\Events\NotificationBagEvent;
use Aqarmap\Bundle\UserBundle\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class NotificationsBagListener implements EventSubscriberInterface
{
/**
* @var EntityManagerInterface
*/
protected $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
public function bagCreated(NotificationBagEvent $notificationBagEvent): void
{
$usersRepository = $this->getUserRepository();
$usersRepository->updateBulkReachCount($notificationBagEvent->getNotificationBag()->getNotifiables());
}
private function getUserRepository()
{
return $this->entityManager->getRepository(User::class);
}
public static function getSubscribedEvents(): array
{
return [
'aqarmap.neighborhood.discussion.bags' => ['bagCreated'],
];
}
}