src/Controller/HomeController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Category;
  4. use App\Twig\GenerateLinkExtension;
  5. use App\Repository\CalendarRepository;
  6. use App\Service\Formatdate;
  7. use App\Repository\CategoryRepository;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. class HomeController extends AbstractController
  12. {
  13.     #[Route('/', name: 'app_home')]
  14.     public function index(CalendarRepository $calendarRepository, GenerateLinkExtension $generateLinkExtension,
  15.      CategoryRepository $categoryRepository , Formatdate $formatdateService): Response
  16.     {
  17.          
  18.           $calendars = $calendarRepository->getAllCalendarActivitie();
  19.           
  20.          
  21.         setlocale(LC_TIME, 'fr_FR');
  22.         // Formate les dates avec le service Formatdate
  23.         foreach ($calendars as $calendar) {
  24.             $calendar->formattedStartDate = $formatdateService->formatCustomDate($calendar->getStart());
  25.             $calendar->formattedEndDate = $formatdateService->formatCustomDate($calendar->getEnd());
  26.         }
  27.         $categories = $categoryRepository->findAll();
  28.           
  29.         // Récupérer l'utilisateur connecté
  30.         $user = $this->getUser();
  31.         // Initialiser le nom complet à null par défaut
  32.         $fullName = null;
  33.         // Vérifier si un utilisateur est connecté
  34.         if ($user) {
  35.             // Si oui, récupérer le nom complet de l'utilisateur
  36.             $fullName = $user->getFullName();
  37.         }
  38.         
  39.         // Récupérer toutes les titres et image par categories
  40.         $categoriesImgTitle = $categoryRepository->findAllWithImages();
  41.           // dd($categoriesImgTitle);
  42.             $titles = [];
  43.             $images = [];
  44.             foreach ($categoriesImgTitle as $category) {
  45.             
  46.                 $titles[] = $category['titleCategory'];
  47.                 $images[] = $category['image'];
  48.             }
  49.          // Utiliser le service pour récupérer les liens de catégorie
  50.          $categoryLinks = $generateLinkExtension->generateCategoryLinks();
  51.           //   dd($categoryLinks);
  52.         return $this->render('calendarFilter/index.html.twig', [
  53.             'calendars' => $calendars,
  54.             'categories' => $categories,
  55.             'titles' => $titles,
  56.             'images' => $images,
  57.             'categoryLinks' => $categoryLinks,
  58.             'fullName' => $fullName,
  59.         ]);
  60.     }
  61.     #[Route('/presentation', name: 'app_presentation')]
  62.     public function presentation()
  63.     {
  64.         return $this->render('home/presentation.html.twig', [
  65.          
  66.         ]);
  67.     }
  68. }