<?php
// src/EventSubscriber/TwigAdminNotificationSubscriber.php
namespace App\EventSubscriber;
use App\Repository\TicketRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;
class TwigAdminNotificationSubscriber implements EventSubscriberInterface
{
private $twig;
private $ticketRepository;
public function __construct(Environment $twig, TicketRepository $ticketRepository)
{
$this->twig = $twig;
$this->ticketRepository = $ticketRepository;
}
public function onKernelController(ControllerEvent $event)
{
// Zähle offene Tickets (offen oder in Bearbeitung) für den Admin-Bereich
$adminUnreadTicketsCount = $this->ticketRepository->countOpenTickets();
// Setze die globale Variable in Twig (klar benannt für den Admin-Kontext)
$this->twig->addGlobal('admin_unreadTicketsCount', $adminUnreadTicketsCount);
}
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => 'onKernelController',
];
}
}