<?php
namespace App\Controller;
use App\Repository\PisteRepository;
use App\Repository\SponsorsRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
private $sponsorsRepository;
private $pisteRepository;
public function __construct(SponsorsRepository $sponsorsRepository, PisteRepository $pisteRepository)
{
$this->sponsorsRepository = $sponsorsRepository;
$this->pisteRepository = $pisteRepository;
}
#[Route('/', name: 'app_home')]
public function index(): Response
{
return $this->render('home/index.html.twig', [
'controller_name' => 'HomeController',
// 'PisteRouge' => $this->randPiste($this->pisteRepository->findOneBlue('Rouge')),
'PisteRouge' => $this->pisteRepository->findOneBy(['color' => 'Rouge']),
'PisteBleue' => $this->randPiste($this->pisteRepository->findOneBlue('Bleu')),
'PisteVerte' => $this->randPiste($this->pisteRepository->findOneBlue('Vert')),
// 'PisteNoire' => $this->randPiste($this->pisteRepository->findOneBlue('Noir')),
'PisteNoire' => $this->pisteRepository->findOneBy(['color' => 'Noir']),
'Pistes' => $this->pisteRepository->findThreePistes(),
'pistesForBase' => $this->pisteRepository->findAll(),
'Sponsors' => $this->sponsorsRepository->findAll()
]);
}
private function randPiste($piste)
{
$countPiste = count($piste);
return $piste[rand(0, $countPiste - 1)];
}
}