<?php
namespace App\Controller\front\Pages;
use App\Entity\Pages\PageCategory;
use App\Controller\Admin\CoreController;
use App\Repository\Pages\PageRepository;
use App\Repository\Medias\MediaRepository;
use App\Service\Manager\Blocs\BlocManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\Pages\PageCategoryRepository;
use App\Service\Manager\Pages\PaletteColorsManager;
use App\Repository\Pages\PageCategoryLangRepository;
use App\Repository\Pages\PageSousCategoryRepository;
#[Route('/page_category')]
class CategoryController extends CoreController
{
#[Route('/filter/{id}/{slug}', name: 'filter')]
public function filter(string $id, $slug, PageRepository $pageRepo, PageSousCategoryRepository $pageSousCategoryRepo,PageCategoryRepository $pageCategoryRepository,
PageCategoryLangRepository $pageCategoryLangRepository,
BlocManager $blocManager
): Response
{
$template = "front/pages/page_category/index.html.twig";
$language = $this->getCurrentLanguage();
$params = [
'isEnable' => 1,
($id === 'voir_tout') ? 'item_all_page' : 'item_page' => $id,
];
$itemsPage = $pageRepo->getAllQb($language, $params)->getResult();
$pageCategoryLang = $pageCategoryLangRepository->findOneBy([
'language'=> $language,
'slug' => $slug
]);
if(!$pageCategoryLang){
$pCLangCheck = $pageCategoryLangRepository->findOneBy([
'slug' => $slug
]);
$pageCategoryLang = $pageCategoryLangRepository->findOneBy([
'slug' => $slug,
'id' => $pCLangCheck->getPageCategory()
]);
}
$pageCategory = $pageCategoryLang->getPageCategory();
if (count($itemsPage) > 0 && isset($itemsPage[0]['id_catg'])) {
$id_cat = $itemsPage[0]['id_catg'];
$params = [
'isEnable' => 1,
'item_ref' => $id_cat,
];
}
$items = $pageSousCategoryRepo->getAllQb($language, $params)->getResult();
$grouppedPages = array_reduce($itemsPage, function ($carry, $item) {
$carry[$item['id']][] = $item;
return $carry;
}, []);
$blocs = $blocManager->getBlocs($pageCategory);
$infoPageCategory = $pageCategoryRepository->getAllQb($language,['id' => $pageCategory->getId()])->getOneOrNullResult();
return $this->render($template, [
'items' => $items,
'pages' => $grouppedPages,
'blocs' => $blocs,
'page_category' => $infoPageCategory,
]);
}
#[Route('/{slug}', name: 'front_page_category_show')]
public function show(
PageCategoryRepository $pageCategoryRepository,
PageCategoryLangRepository $pageCategoryLangRepository,
PageSousCategoryRepository $pagesouscategorie,
PageRepository $pagerepo,
MediaRepository $mediaRepository,
BlocManager $blocManager,
Request $request,
PaletteColorsManager $paletteColorsManager,
$slug
): Response
{
$language = $this->getCurrentLanguage($request->getLocale());
$items = $template = "";
$pageCategoryLang = $pageCategoryLangRepository->findOneBy([
'language'=> $language,
'slug' => $slug
]);
$pageCategory = $pageCategoryLang->getPageCategory();
$medias = $mediaRepository->findBy([
'idOrigin' => $pageCategory->getId(),
'origin' => get_class($pageCategory),
'deletedAt' => null
]);
$type = $pageCategory ? $pageCategory->getType() : null;
if($type == PageCategory::TYPE_REFERENCS){
$template = "front/pages/page_category/index.html.twig";
$params = [
'isEnable' => 1 ,
'item_ref'=> $pageCategory->getId(),
];
$items = $pagesouscategorie->getAllQb($language, $params)->getResult();
$params = [
'isEnable' => 1 ,
'item_all_page'=>'voir_tout',
];
$itemsPage = $pagerepo->getAllQb($language, $params)->getResult();
$grouppedPages = array_reduce($itemsPage, function ($carry, $item) {
$carry[$item['id']][] = $item;
return $carry;
}, []);
}
$paletteColors = $paletteColorsManager->getValues('App\\Entity\\Pages\\PageCategory',$pageCategory->getId());
$colorPage=null;
if($paletteColors){
$colorPage=$paletteColors[0];
}
$blocs = $blocManager->getBlocs($pageCategory);
$infoPageCategory = $pageCategoryRepository->getAllQb($language,['id' => $pageCategory->getId()])->getOneOrNullResult();
return $this->render($template, [
'page_category' => $infoPageCategory,
'items' => $items,
'pages' => $grouppedPages,
'paletteColors' =>$colorPage,
'blocs' => $blocs,
]);
}
}