src/Controller/HomeController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Evenement;
  4. use DateTimeZone;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Exception;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpFoundation\Session\Session;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class HomeController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/", name="app_home")
  15.      * @throws Exception
  16.      */
  17.     public function index(EntityManagerInterface $manager): Response
  18.     {
  19.         $allEvenements $manager->getRepository(Evenement::class)->findBy(['visible' => 1], ['date' => 'ASC']);
  20.         $curDate = new \DateTimeImmutable(null, new DateTimeZone('Europe/Paris'));
  21.         $evenements = [];
  22.         foreach ($allEvenements as $evenement){
  23.             if ($evenement->getDate() > $curDate){
  24.                 $evenements[] = $evenement;
  25.             }
  26.         }
  27.         if ($this->isGranted('IS_AUTHENTICATED_FULLY')){
  28.             return $this->redirectToRoute('app_evenement_show', [
  29.                 'id' => 1
  30.             ]);
  31.         }
  32.         return $this->render('home/index.html.twig', [
  33.             'controller_name' => 'HomeController',
  34.             'evenements' => $evenements
  35.         ]);
  36.     }
  37.     /**
  38.      * @Route("/{code}/home", name="app_home_aut")
  39.      * @param $code
  40.      * @param EntityManagerInterface $manager
  41.      * @return Response
  42.      * @throws Exception
  43.      */
  44.     public function index_aut($codeEntityManagerInterface $manager): Response
  45.     {
  46.         if ($code === 'ecf8c2436a681b124b9d633be0c2ca58'){
  47.             $session = new  Session();
  48.             $session->start();
  49.             $session->set('hasAut''ok');
  50.         }
  51.         $allEvenements $manager->getRepository(Evenement::class)->findBy(['visible' => 1], ['date' => 'ASC']);
  52.         $curDate = new \DateTimeImmutable(null, new DateTimeZone('Europe/Paris'));
  53.         $evenements = [];
  54.         foreach ($allEvenements as $evenement){
  55.             if ($evenement->getDate() > $curDate){
  56.                 $evenements[] = $evenement;
  57.             }
  58.         }
  59.         return $this->redirectToRoute('app_evenement_show', [
  60.             'id' => 1
  61.         ]);
  62. //        return $this->render('home/index.html.twig', [
  63. //            'controller_name' => 'HomeController',
  64. //            'evenements' => $evenements
  65. //        ]);
  66.     }
  67. }