src/EventSubscriber/Content/ContentHitsSubscriber.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Content;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use App\Event\Content\ContentDisplayEvent;
  5. use App\Repository\ContentRepository;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. /**
  8.  * @author Przemysław Chrupek <przemyslaw.chrupek@avt.pl>
  9.  */
  10. class ContentHitsSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var Content
  14.      */
  15.     private $content;
  16.     private $cr;
  17.     public function __construct(ContentRepository $cr)
  18.     {
  19.         $this->cr $cr;
  20.     }
  21.     public static function getSubscribedEvents()
  22.     {
  23.         return [
  24.             ContentDisplayEvent::NAME => [
  25.                 ['preContentDisplay'1000],
  26.             ]
  27.         ];
  28.     }
  29.     public function preContentDisplay(ContentDisplayEvent $event): void
  30.     {
  31.         $this->content $event->getContent();
  32.         
  33.         // $this->content->addHits();
  34.         // $this->em->persist($this->content);
  35.         // $this->em->flush();
  36.         $this->cr->addHits$this->content);
  37.     }
  38. }