src/EventSubscriber/TemplateVariableSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. // src/EventSubscriber/TemplateVariableSubscriber.php
  3. namespace App\EventSubscriber;
  4. use App\Service\InvoiceService;
  5. use App\Service\PrescriberService;
  6. use App\Service\VisitReportService;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. use Twig\Environment;
  11. class TemplateVariableSubscriber implements EventSubscriberInterface
  12. {
  13.     public function __construct(
  14.         private readonly Environment        $twig,
  15.         private readonly VisitReportService $reportService,
  16.         private readonly PrescriberService  $prescriberService,
  17.         private readonly InvoiceService     $invoiceService,
  18.     )
  19.     {
  20.     }
  21.     public function onKernelController(ControllerEvent $event)
  22.     {
  23.         if (!$event->isMainRequest()) {
  24.             return;
  25.         }
  26.         $this->twig->addGlobal('isUnvalidatedReportsCount'$this->reportService->getUnvalidatedReportsCount());
  27.         $this->twig->addGlobal('isNotApprovedReportsCount'$this->reportService->getNotApprovedReportsCount());
  28.         $this->twig->addGlobal('visitReportToApproveCount'$this->reportService->getVisitReportToApproveCount());
  29.         $this->twig->addGlobal('nullPrescriberValidationUserCount'$this->invoiceService->getNullPrescriberValidationUserCount());
  30.         $this->twig->addGlobal('prescribersUnapprovedCount'$this->prescriberService->countUnapproved());
  31.         $this->twig->addGlobal('prescribersPendingApprovalCount'$this->prescriberService->countPendingApproval());
  32.     }
  33.     public static function getSubscribedEvents()
  34.     {
  35.         return [
  36.             KernelEvents::CONTROLLER => ['onKernelController'0],
  37.         ];
  38.     }
  39. }