src/Aqarmap/Bundle/DiscussionBundle/EventListener/NotificationsBagListener.php line 22

Open in your IDE?
  1. <?php
  2. namespace Aqarmap\Bundle\DiscussionBundle\EventListener;
  3. use Aqarmap\Bundle\NotificationBundle\Events\NotificationBagEvent;
  4. use Aqarmap\Bundle\UserBundle\Entity\User;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class NotificationsBagListener implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var EntityManagerInterface
  11.      */
  12.     protected $entityManager;
  13.     public function __construct(EntityManagerInterface $entityManager)
  14.     {
  15.         $this->entityManager $entityManager;
  16.     }
  17.     public function bagCreated(NotificationBagEvent $notificationBagEvent): void
  18.     {
  19.         $usersRepository $this->getUserRepository();
  20.         $usersRepository->updateBulkReachCount($notificationBagEvent->getNotificationBag()->getNotifiables());
  21.     }
  22.     private function getUserRepository()
  23.     {
  24.         return $this->entityManager->getRepository(User::class);
  25.     }
  26.     public static function getSubscribedEvents(): array
  27.     {
  28.         return [
  29.             'aqarmap.neighborhood.discussion.bags' => ['bagCreated'],
  30.         ];
  31.     }
  32. }