src/Controller/PistesController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\PisteRepository;
  4. use App\Repository\SponsorsRepository;
  5. use App\Repository\SupportRepository;
  6. use App\Repository\TimePistesRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class PistesController extends AbstractController
  12. {
  13.     private $sponsorsRepository;
  14.     private $pisteRepository;
  15.     private $timePistesRepository;
  16.     private $supportRepository;
  17.     public function __construct(SponsorsRepository $sponsorsRepositoryPisteRepository $pisteRepositoryTimePistesRepository $timePistesRepositorySupportRepository $supportRepository)
  18.     {
  19.         $this->sponsorsRepository $sponsorsRepository;
  20.         $this->pisteRepository $pisteRepository;
  21.         $this->timePistesRepository $timePistesRepository;
  22.         $this->supportRepository $supportRepository;
  23.     }
  24.     #[Route('/sections'name'app_pistes')]
  25.     public function index(Request $request): Response
  26.     {
  27.         $filterPiste $request->query->all();
  28.         if (isset($filterPiste["Piste"]) == "Bleu" || isset($filterPiste["Piste"]) == "Vert" || isset($filterPiste["Piste"]) == "Rouge" || isset($filterPiste["Piste"]) == "Noir") {
  29.             return $this->render('pistes/index.html.twig', [
  30.                 'controller_name' => 'PistesController',
  31.                 'Pistes' => $this->pisteRepository->findBy(['color' => $filterPiste]),
  32.                 'Sponsors' => $this->sponsorsRepository->findAll(),
  33.                 'pistesForBase' => $this->pisteRepository->findAll(),
  34.             ]);
  35.         } else {
  36.             return $this->render('pistes/index.html.twig', [
  37.                 'controller_name' => 'PistesController',
  38.                 'Pistes' => $this->pisteRepository->findAll(),
  39.                 'Sponsors' => $this->sponsorsRepository->findAll(),
  40.                 'pistesForBase' => $this->pisteRepository->findAll(),
  41.             ]);
  42.         }
  43.     }
  44.     #[Route('/sections/{id}&filters={filters}'name'app_pistes_show')]
  45.     public function show($idRequest $request$filters): Response
  46.     {
  47.         if ($filters == "all") {
  48.             return $this->render('pistes/show.html.twig', [
  49.                 'controller_name' => 'PistesController',
  50.                 'Pistes' => $this->pisteRepository->findOneBy(['id' => $id]),
  51.                 'Sponsors' => $this->sponsorsRepository->findAll(),
  52.                 'Classement' => $this->timePistesRepository->findBy(['Piste' => $this->pisteRepository->findOneBy(['id' => $id])], ['time' => 'ASC']),
  53.                 'pistesForBase' => $this->pisteRepository->findAll(),
  54.             ]);
  55.         } else {
  56.             $support $this->supportRepository->findOneBy(['name' => $filters]);
  57.             return $this->render('pistes/show.html.twig', [
  58.                 'controller_name' => 'PistesController',
  59.                 'Pistes' => $this->pisteRepository->findOneBy(['id' => $id]),
  60.                 'Sponsors' => $this->sponsorsRepository->findAll(),
  61.                 'Classement' => $this->timePistesRepository->findBy(['Piste' => $this->pisteRepository->findOneBy(['id' => $id]), 'support' => $support], ['time' => 'ASC']),
  62.                 'pistesForBase' => $this->pisteRepository->findAll(),
  63.             ]);
  64.         }
  65.         return $this->render('pistes/show.html.twig', [
  66.             'controller_name' => 'PistesController',
  67.             'Pistes' => $this->pisteRepository->findOneBy(['id' => $id]),
  68.             'Sponsors' => $this->sponsorsRepository->findAll(),
  69.             'Classement' => $this->timePistesRepository->findBy(['Piste' => $this->pisteRepository->findOneBy(['id' => $id])], ['time' => 'ASC']),
  70.             'pistesForBase' => $this->pisteRepository->findAll(),
  71.         ]);
  72.     }
  73. }