<?php
namespace App\EventSubscriber\Content;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Event\Content\ContentDisplayEvent;
use App\Repository\ContentRepository;
use Doctrine\ORM\EntityManagerInterface;
/**
* @author Przemysław Chrupek <przemyslaw.chrupek@avt.pl>
*/
class ContentHitsSubscriber implements EventSubscriberInterface
{
/**
* @var Content
*/
private $content;
private $cr;
public function __construct(ContentRepository $cr)
{
$this->cr = $cr;
}
public static function getSubscribedEvents()
{
return [
ContentDisplayEvent::NAME => [
['preContentDisplay', 1000],
]
];
}
public function preContentDisplay(ContentDisplayEvent $event): void
{
$this->content = $event->getContent();
// $this->content->addHits();
// $this->em->persist($this->content);
// $this->em->flush();
$this->cr->addHits( $this->content);
}
}