<?php
namespace App\Controller;
use App\Repository\PisteRepository;
use App\Repository\SponsorsRepository;
use App\Repository\SupportRepository;
use App\Repository\TimePistesRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class PistesController extends AbstractController
{
private $sponsorsRepository;
private $pisteRepository;
private $timePistesRepository;
private $supportRepository;
public function __construct(SponsorsRepository $sponsorsRepository, PisteRepository $pisteRepository, TimePistesRepository $timePistesRepository, SupportRepository $supportRepository)
{
$this->sponsorsRepository = $sponsorsRepository;
$this->pisteRepository = $pisteRepository;
$this->timePistesRepository = $timePistesRepository;
$this->supportRepository = $supportRepository;
}
#[Route('/sections', name: 'app_pistes')]
public function index(Request $request): Response
{
$filterPiste = $request->query->all();
if (isset($filterPiste["Piste"]) == "Bleu" || isset($filterPiste["Piste"]) == "Vert" || isset($filterPiste["Piste"]) == "Rouge" || isset($filterPiste["Piste"]) == "Noir") {
return $this->render('pistes/index.html.twig', [
'controller_name' => 'PistesController',
'Pistes' => $this->pisteRepository->findBy(['color' => $filterPiste]),
'Sponsors' => $this->sponsorsRepository->findAll(),
'pistesForBase' => $this->pisteRepository->findAll(),
]);
} else {
return $this->render('pistes/index.html.twig', [
'controller_name' => 'PistesController',
'Pistes' => $this->pisteRepository->findAll(),
'Sponsors' => $this->sponsorsRepository->findAll(),
'pistesForBase' => $this->pisteRepository->findAll(),
]);
}
}
#[Route('/sections/{id}&filters={filters}', name: 'app_pistes_show')]
public function show($id, Request $request, $filters): Response
{
if ($filters == "all") {
return $this->render('pistes/show.html.twig', [
'controller_name' => 'PistesController',
'Pistes' => $this->pisteRepository->findOneBy(['id' => $id]),
'Sponsors' => $this->sponsorsRepository->findAll(),
'Classement' => $this->timePistesRepository->findBy(['Piste' => $this->pisteRepository->findOneBy(['id' => $id])], ['time' => 'ASC']),
'pistesForBase' => $this->pisteRepository->findAll(),
]);
} else {
$support = $this->supportRepository->findOneBy(['name' => $filters]);
return $this->render('pistes/show.html.twig', [
'controller_name' => 'PistesController',
'Pistes' => $this->pisteRepository->findOneBy(['id' => $id]),
'Sponsors' => $this->sponsorsRepository->findAll(),
'Classement' => $this->timePistesRepository->findBy(['Piste' => $this->pisteRepository->findOneBy(['id' => $id]), 'support' => $support], ['time' => 'ASC']),
'pistesForBase' => $this->pisteRepository->findAll(),
]);
}
return $this->render('pistes/show.html.twig', [
'controller_name' => 'PistesController',
'Pistes' => $this->pisteRepository->findOneBy(['id' => $id]),
'Sponsors' => $this->sponsorsRepository->findAll(),
'Classement' => $this->timePistesRepository->findBy(['Piste' => $this->pisteRepository->findOneBy(['id' => $id])], ['time' => 'ASC']),
'pistesForBase' => $this->pisteRepository->findAll(),
]);
}
}