<?php
declare(strict_types=1);
namespace App\Controller\Blo;
use App\Repository\Blo\CategoryRepository;
use App\Repository\Blo\HomeSliderItemRepository;
use App\Repository\Blo\ProductRepository;
use App\Repository\Blo\ShopRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Page d'accueil du site BLO (priorité haute pour capturer /).
*/
#[Route('/', name: 'app_blo_home_', priority: 100)]
class HomeController extends AbstractController
{
public function __construct(
private readonly ProductRepository $productRepository,
private readonly CategoryRepository $categoryRepository,
private readonly ShopRepository $shopRepository,
private readonly HomeSliderItemRepository $sliderRepository,
) {
}
#[Route('', name: 'index', methods: ['GET'])]
public function index(): Response
{
$user = $this->getUser();
$roles = $user ? $user->getRoles() : [];
// Redirection selon le rôle vers le tableau de bord adapté
if (\in_array('ROLE_ADMIN', $roles, true)) {
return $this->redirectToRoute('blo_admin_dashboard');
}
if (\in_array('ROLE_VENDOR', $roles, true)) {
return $this->redirectToRoute('blo_vendor_dashboard');
}
// Rôles métier (transit, gestionnaire commercial) : tableau de bord interne
foreach (['ROLE_GESTIONNAIRE_TRANSIT', 'ROLE_AGENT_TRANSIT', 'ROLE_GESTIONNAIRE', 'ROLE_VENDEUR'] as $role) {
if (\in_array($role, $roles, true)) {
return $this->redirectToRoute('app_home');
}
}
// Contenu page d’accueil : produits à la une, catégories, boutiques
$sliderItems = $this->sliderRepository->findOrdered();
$promoProducts = $this->productRepository->findPromoProducts(8);
$featuredProducts = $this->productRepository->findNewest(8);
$newestProducts = $this->productRepository->findNewest(8);
$categories = $this->categoryRepository->findRootCategories();
return $this->render('blo/home/index.html.twig', [
'sliderItems' => $sliderItems,
'promoProducts' => $promoProducts,
'featuredProducts' => $featuredProducts,
'newestProducts' => $newestProducts,
'categories' => $categories,
]);
}
}