src/EventSubscriber/TwigAdminNotificationSubscriber.php line 22

Open in your IDE?
  1. <?php
  2. // src/EventSubscriber/TwigAdminNotificationSubscriber.php
  3. namespace App\EventSubscriber;
  4. use App\Repository\TicketRepository;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Twig\Environment;
  9. class TwigAdminNotificationSubscriber implements EventSubscriberInterface
  10. {
  11.     private $twig;
  12.     private $ticketRepository;
  13.     public function __construct(Environment $twigTicketRepository $ticketRepository)
  14.     {
  15.         $this->twig $twig;
  16.         $this->ticketRepository $ticketRepository;
  17.     }
  18.     public function onKernelController(ControllerEvent $event)
  19.     {
  20.         // Zähle offene Tickets (offen oder in Bearbeitung) für den Admin-Bereich
  21.         $adminUnreadTicketsCount $this->ticketRepository->countOpenTickets();
  22.         // Setze die globale Variable in Twig (klar benannt für den Admin-Kontext)
  23.         $this->twig->addGlobal('admin_unreadTicketsCount'$adminUnreadTicketsCount);
  24.     }
  25.     public static function getSubscribedEvents()
  26.     {
  27.         return [
  28.             KernelEvents::CONTROLLER => 'onKernelController',
  29.         ];
  30.     }
  31. }