<?php
namespace App\Controller;
use App\Entity\Evenement;
use DateTimeZone;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
/**
* @Route("/", name="app_home")
* @throws Exception
*/
public function index(EntityManagerInterface $manager): Response
{
$allEvenements = $manager->getRepository(Evenement::class)->findBy(['visible' => 1], ['date' => 'ASC']);
$curDate = new \DateTimeImmutable(null, new DateTimeZone('Europe/Paris'));
$evenements = [];
foreach ($allEvenements as $evenement){
if ($evenement->getDate() > $curDate){
$evenements[] = $evenement;
}
}
if ($this->isGranted('IS_AUTHENTICATED_FULLY')){
return $this->redirectToRoute('app_evenement_show', [
'id' => 1
]);
}
return $this->render('home/index.html.twig', [
'controller_name' => 'HomeController',
'evenements' => $evenements
]);
}
/**
* @Route("/{code}/home", name="app_home_aut")
* @param $code
* @param EntityManagerInterface $manager
* @return Response
* @throws Exception
*/
public function index_aut($code, EntityManagerInterface $manager): Response
{
if ($code === 'ecf8c2436a681b124b9d633be0c2ca58'){
$session = new Session();
$session->start();
$session->set('hasAut', 'ok');
}
$allEvenements = $manager->getRepository(Evenement::class)->findBy(['visible' => 1], ['date' => 'ASC']);
$curDate = new \DateTimeImmutable(null, new DateTimeZone('Europe/Paris'));
$evenements = [];
foreach ($allEvenements as $evenement){
if ($evenement->getDate() > $curDate){
$evenements[] = $evenement;
}
}
return $this->redirectToRoute('app_evenement_show', [
'id' => 1
]);
// return $this->render('home/index.html.twig', [
// 'controller_name' => 'HomeController',
// 'evenements' => $evenements
// ]);
}
}