<?php
// src/EventSubscriber/TemplateVariableSubscriber.php
namespace App\EventSubscriber;
use App\Service\InvoiceService;
use App\Service\PrescriberService;
use App\Service\VisitReportService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;
class TemplateVariableSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly Environment $twig,
private readonly VisitReportService $reportService,
private readonly PrescriberService $prescriberService,
private readonly InvoiceService $invoiceService,
)
{
}
public function onKernelController(ControllerEvent $event)
{
if (!$event->isMainRequest()) {
return;
}
$this->twig->addGlobal('isUnvalidatedReportsCount', $this->reportService->getUnvalidatedReportsCount());
$this->twig->addGlobal('isNotApprovedReportsCount', $this->reportService->getNotApprovedReportsCount());
$this->twig->addGlobal('visitReportToApproveCount', $this->reportService->getVisitReportToApproveCount());
$this->twig->addGlobal('nullPrescriberValidationUserCount', $this->invoiceService->getNullPrescriberValidationUserCount());
$this->twig->addGlobal('prescribersUnapprovedCount', $this->prescriberService->countUnapproved());
$this->twig->addGlobal('prescribersPendingApprovalCount', $this->prescriberService->countPendingApproval());
}
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => ['onKernelController', 0],
];
}
}