src/Aqarmap/Bundle/NotifierBundle/EventListener/NotifierInteractionListener.php line 21

Open in your IDE?
  1. <?php
  2. namespace Aqarmap\Bundle\NotifierBundle\EventListener;
  3. use Aqarmap\Bundle\NotifierBundle\Event\NotifierEvent;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class NotifierInteractionListener implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @var EntityManagerInterface
  10.      */
  11.     protected $em;
  12.     public function __construct(EntityManagerInterface $em)
  13.     {
  14.         $this->em $em;
  15.     }
  16.     public function onNotifierInteraction(NotifierEvent $event): void
  17.     {
  18.         $notifier $event->getNotifier();
  19.         $notifier->setLastClickDate(new \DateTime());
  20.         $notifier->incrementNumberOfClicks();
  21.         $this->em->persist($notifier);
  22.         $this->em->flush($notifier);
  23.     }
  24.     public static function getSubscribedEvents()
  25.     {
  26.         return [
  27.             'aqarmap.notifier.interaction' => 'onNotifierInteraction',
  28.         ];
  29.     }
  30. }