src/Controller/HomeController.php line 15

  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\ActiviteRepository;
  4. use App\Repository\EditionRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class HomeController extends AbstractController
  10. {
  11.     #[Route('/'name'home')]
  12.     public function index(EditionRepository $editionRepositoryActiviteRepository $activiteRepository): Response
  13.     {
  14.         $liste_activite = new ArrayCollection();
  15.         $liste_repas    = new ArrayCollection();
  16.         if( $edition $editionRepository->findOneBy(['deletedAt' => null'edition_par_defaut' => true]) ) {
  17.             $liste_activity $activiteRepository->findBy(['deletedAt' => null'edition' => $edition->getId()]);
  18.             foreach($liste_activity as $activity) {
  19.                 // REPAS
  20.                 if(100 === $activity->getType())     $liste_repas->add($activity);
  21.                 // ACTIVITÉ
  22.                 elseif(200 === $activity->getType()) $liste_activite->add($activity);
  23.             }
  24.         }
  25.         if( null !== $edition) {
  26.             if($edition->getRegisterEnd() < new \DateTime('now')) {
  27.                 return $this->render('home/fin_inscription.html.twig', [
  28.                     'edition'        => $edition,
  29.                     ]);
  30.             }
  31.             //calcul du nombre de jours et heure avant la fin des inscriptions
  32.             $now = new \DateTime('now');
  33.             $end $edition->getRegisterEnd();
  34.             $diff $now->diff($end);
  35.             $nbJours $diff->format('%a');
  36.             if($nbJours 0) {
  37.                 if($nbJours 8) {
  38.                     $diff_show $diff->format('%a jours, %h heures et %i minutes');
  39.                 } else {
  40.                     $diff_show '';
  41.                 }
  42.             } else {
  43.                 $diff_show $diff->format('%h heures et %i minutes');
  44.             }
  45.             return $this->render('home/index.html.twig', [
  46.                 'edition'        => $edition,
  47.                 'diff_show'     => $diff_show,
  48.                 'liste_activite' => $liste_activite,
  49.                 'liste_repas'    => $liste_repas
  50.             ]);
  51.         }
  52.         return new Response('Aucune Ã©dition...');
  53.     }
  54. }