src/Controller/Blo/HomeController.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Blo;
  4. use App\Repository\Blo\CategoryRepository;
  5. use App\Repository\Blo\HomeSliderItemRepository;
  6. use App\Repository\Blo\ProductRepository;
  7. use App\Repository\Blo\ShopRepository;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * Page d'accueil du site BLO (priorité haute pour capturer /).
  13.  */
  14. #[Route('/'name'app_blo_home_'priority100)]
  15. class HomeController extends AbstractController
  16. {
  17.     public function __construct(
  18.         private readonly ProductRepository $productRepository,
  19.         private readonly CategoryRepository $categoryRepository,
  20.         private readonly ShopRepository $shopRepository,
  21.         private readonly HomeSliderItemRepository $sliderRepository,
  22.     ) {
  23.     }
  24.     #[Route(''name'index'methods: ['GET'])]
  25.     public function index(): Response
  26.     {
  27.         $user $this->getUser();
  28.         $roles $user $user->getRoles() : [];
  29.         // Redirection selon le rôle vers le tableau de bord adapté
  30.         if (\in_array('ROLE_ADMIN'$rolestrue)) {
  31.             return $this->redirectToRoute('blo_admin_dashboard');
  32.         }
  33.         if (\in_array('ROLE_VENDOR'$rolestrue)) {
  34.             return $this->redirectToRoute('blo_vendor_dashboard');
  35.         }
  36.         // Rôles métier (transit, gestionnaire commercial) : tableau de bord interne
  37.         foreach (['ROLE_GESTIONNAIRE_TRANSIT''ROLE_AGENT_TRANSIT''ROLE_GESTIONNAIRE''ROLE_VENDEUR'] as $role) {
  38.             if (\in_array($role$rolestrue)) {
  39.                 return $this->redirectToRoute('app_home');
  40.             }
  41.         }
  42.         // Contenu page d’accueil : produits à la une, catégories, boutiques
  43.         $sliderItems $this->sliderRepository->findOrdered();
  44.         $promoProducts $this->productRepository->findPromoProducts(8);
  45.         $featuredProducts $this->productRepository->findNewest(8);
  46.         $newestProducts $this->productRepository->findNewest(8);
  47.         $categories $this->categoryRepository->findRootCategories();
  48.         return $this->render('blo/home/index.html.twig', [
  49.             'sliderItems' => $sliderItems,
  50.             'promoProducts' => $promoProducts,
  51.             'featuredProducts' => $featuredProducts,
  52.             'newestProducts' => $newestProducts,
  53.             'categories' => $categories,
  54.         ]);
  55.     }
  56. }