<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;
use App\Repository\ProjectRepository;
use App\Repository\ClientRepository;
use App\Repository\UserRepository;
use App\Repository\TaskRepository;
use App\Repository\TagOrgRepository;
use App\Repository\TagTypeRepository;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class GlobalsSubscriber extends AbstractController implements EventSubscriberInterface
{
private $twig;
private $clientRepository;
private $projectRepository;
private $userRepository;
private $taskRepository;
private $tagTypeRepository;
private $tagOrgRepository;
public function __construct(Environment $twig, ClientRepository $clientRepository, ProjectRepository $projectRepository, UserRepository $userRepository, TaskRepository $taskRepository, TagOrgRepository $tagOrgRepository, TagTypeRepository $tagTypeRepository, FormFactoryInterface $formFactory)
{
$this->twig = $twig;
$this->clientRepository = $clientRepository;
$this->projectRepository = $projectRepository;
$this->userRepository = $userRepository;
$this->taskRepository = $taskRepository;
$this->tagOrgRepository = $tagOrgRepository;
$this->tagTypeRepository = $tagTypeRepository;
}
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => 'onKernelRequest',
];
}
public function onKernelRequest()
{
$this->twig->addGlobal('global_variable', 'valeur');
$this->twig->addGlobal('projects', $this->projectRepository->FindByActive());
$this->twig->addGlobal('users', $this->userRepository->findByNotArchived());
$this->twig->addGlobal('clients', $this->clientRepository->findAll());
$this->twig->addGlobal('tasks', $this->taskRepository->findByIdUserAffected());
$this->twig->addGlobal('todayTasks', $this->taskRepository->findByTodayTask());
$this->twig->addGlobal('threeDayTasks', $this->taskRepository->findByThreeDayTask());
$this->twig->addGlobal('formerTasks', $this->taskRepository->findByFormerTask());
$this->twig->addGlobal('tagOrgs', $this->tagOrgRepository->findAll());
$this->twig->addGlobal('tagTypes', $this->tagTypeRepository->findAll());
}
}