<?php
namespace Aqarmap\Bundle\NotifierBundle\EventListener;
use Aqarmap\Bundle\NotifierBundle\Event\NotifierEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class NotifierInteractionListener implements EventSubscriberInterface
{
/**
* @var EntityManagerInterface
*/
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function onNotifierInteraction(NotifierEvent $event): void
{
$notifier = $event->getNotifier();
$notifier->setLastClickDate(new \DateTime());
$notifier->incrementNumberOfClicks();
$this->em->persist($notifier);
$this->em->flush($notifier);
}
public static function getSubscribedEvents()
{
return [
'aqarmap.notifier.interaction' => 'onNotifierInteraction',
];
}
}