src/Controller/front/Pages/CategoryController.php line 80

Open in your IDE?
  1. <?php
  2. namespace App\Controller\front\Pages;
  3. use App\Entity\Pages\PageCategory;
  4. use App\Controller\Admin\CoreController;
  5. use App\Repository\Pages\PageRepository;
  6. use App\Repository\Medias\MediaRepository;
  7. use App\Service\Manager\Blocs\BlocManager;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use App\Repository\Pages\PageCategoryRepository;
  12. use App\Service\Manager\Pages\PaletteColorsManager;
  13. use App\Repository\Pages\PageCategoryLangRepository;
  14. use App\Repository\Pages\PageSousCategoryRepository;
  15. #[Route('/page_category')]
  16. class CategoryController extends CoreController
  17. {
  18.     #[Route('/filter/{id}/{slug}'name'filter')]
  19.     public function filter(string $id$slugPageRepository $pageRepoPageSousCategoryRepository $pageSousCategoryRepo,PageCategoryRepository $pageCategoryRepository,
  20.     PageCategoryLangRepository $pageCategoryLangRepository,
  21.     BlocManager $blocManager
  22.     ): Response
  23.     {
  24.         $template "front/pages/page_category/index.html.twig";
  25.         $language $this->getCurrentLanguage();
  26.         $params = [
  27.             'isEnable' => 1,
  28.             ($id === 'voir_tout') ? 'item_all_page' 'item_page' => $id,
  29.         ];
  30.         $itemsPage $pageRepo->getAllQb($language$params)->getResult();
  31.         $pageCategoryLang $pageCategoryLangRepository->findOneBy([
  32.             'language'=> $language,
  33.             'slug' => $slug
  34.         ]);
  35.         if(!$pageCategoryLang){
  36.             $pCLangCheck $pageCategoryLangRepository->findOneBy([
  37.                 'slug' => $slug
  38.             ]);
  39.             $pageCategoryLang $pageCategoryLangRepository->findOneBy([
  40.                 'slug' => $slug,
  41.                 'id' => $pCLangCheck->getPageCategory()
  42.             ]);
  43.         }
  44.         $pageCategory $pageCategoryLang->getPageCategory();
  45.         if (count($itemsPage) > && isset($itemsPage[0]['id_catg'])) {
  46.             $id_cat $itemsPage[0]['id_catg'];
  47.             $params = [
  48.                 'isEnable' => 1,
  49.                 'item_ref' => $id_cat,
  50.             ];
  51.         }
  52.         
  53.         $items $pageSousCategoryRepo->getAllQb($language$params)->getResult();
  54.     
  55.         $grouppedPages array_reduce($itemsPage, function ($carry$item) {
  56.             $carry[$item['id']][] = $item;
  57.             return $carry;
  58.         }, []);
  59.         $blocs $blocManager->getBlocs($pageCategory);
  60.        $infoPageCategory $pageCategoryRepository->getAllQb($language,['id' => $pageCategory->getId()])->getOneOrNullResult(); 
  61.         return $this->render($template, [
  62.             'items' => $items,
  63.             'pages' => $grouppedPages,
  64.             'blocs'  => $blocs,
  65.             'page_category'   =>  $infoPageCategory,
  66.         ]);
  67.     }
  68.     
  69.     #[Route('/{slug}'name'front_page_category_show')]
  70.     public function show(
  71.                             PageCategoryRepository $pageCategoryRepository,
  72.                             PageCategoryLangRepository $pageCategoryLangRepository,
  73.                             PageSousCategoryRepository $pagesouscategorie,
  74.                             PageRepository $pagerepo,
  75.                             MediaRepository $mediaRepository,
  76.                             BlocManager $blocManager,
  77.                             Request $request,
  78.                             PaletteColorsManager $paletteColorsManager,
  79.                             $slug
  80.                         ): Response
  81.     {
  82.         $language $this->getCurrentLanguage($request->getLocale());
  83.         $items $template  "";
  84.         $pageCategoryLang $pageCategoryLangRepository->findOneBy([
  85.             'language'=> $language,
  86.             'slug' => $slug
  87.         ]);
  88.         $pageCategory $pageCategoryLang->getPageCategory();
  89.      
  90.         $medias =   $mediaRepository->findBy([
  91.             'idOrigin' => $pageCategory->getId(), 
  92.             'origin' => get_class($pageCategory), 
  93.             'deletedAt' => null
  94.         ]);
  95.          
  96.         $type $pageCategory $pageCategory->getType() : null;
  97.         if($type == PageCategory::TYPE_REFERENCS){
  98.         
  99.             $template "front/pages/page_category/index.html.twig";
  100.             $params = [
  101.                 'isEnable' => ,
  102.                 'item_ref'=> $pageCategory->getId(),
  103.             ];
  104.             $items $pagesouscategorie->getAllQb($language$params)->getResult();
  105.                 $params = [
  106.                     'isEnable' => ,
  107.                     'item_all_page'=>'voir_tout',
  108.                 ];
  109.                 $itemsPage $pagerepo->getAllQb($language$params)->getResult(); 
  110.                 $grouppedPages array_reduce($itemsPage, function ($carry$item) {
  111.                     $carry[$item['id']][] = $item;
  112.                     return $carry;
  113.                 }, []);
  114.         }
  115.         $paletteColors $paletteColorsManager->getValues('App\\Entity\\Pages\\PageCategory',$pageCategory->getId());
  116.         $colorPage=null;
  117.        if($paletteColors){
  118.            $colorPage=$paletteColors[0];
  119.        }
  120.        $blocs $blocManager->getBlocs($pageCategory);
  121.        $infoPageCategory $pageCategoryRepository->getAllQb($language,['id' => $pageCategory->getId()])->getOneOrNullResult(); 
  122.         return $this->render($template, [
  123.             'page_category'   =>  $infoPageCategory,
  124.             'items' => $items,
  125.             'pages' => $grouppedPages,
  126.             'paletteColors' =>$colorPage,
  127.             'blocs'  => $blocs,
  128.         ]);
  129.     }
  130. }