src/Controller/Front/PageController.php line 653

Open in your IDE?
  1. <?php 
  2. namespace App\Controller\Front;
  3. use App\Entity\Menu;
  4. use App\Entity\Post;
  5. use App\Entity\UrlRef;
  6. use App\Entity\UrlPost;
  7. use App\Entity\Category;
  8. use App\Entity\Language;
  9. use App\Entity\ListeRef;
  10. use App\Entity\MediaCms;
  11. use App\Entity\Secteurs;
  12. use App\Entity\TypePost;
  13. use App\Entity\Activites;
  14. use App\Entity\ListeMenu;
  15. use App\Service\BuildTree;
  16. use App\Entity\CpPostField;
  17. use App\Entity\PostArchive;
  18. use App\Service\RenderBloc;
  19. use Spatie\SchemaOrg\Graph;
  20. use App\Entity\ParametreRef;
  21. use App\Entity\PostCategory;
  22. use App\Service\MetaService;
  23. use Spatie\SchemaOrg\Schema;
  24. use App\Entity\ModelGallerie;
  25. use App\Entity\ParametreSite;
  26. use App\Entity\ReseauSociaux;
  27. use App\Service\MetaClePageRef;
  28. use App\Service\FunctionService;
  29. use App\Entity\ActiviteSecondaire;
  30. use App\Service\RefMetaTagsService;
  31. use App\Service\MetaWithoutCategoryService;
  32. use Symfony\Component\HttpFoundation\Request;
  33. use Symfony\Component\HttpFoundation\Response;
  34. use Symfony\Component\Routing\Annotation\Route;
  35. use Symfony\Component\HttpFoundation\JsonResponse;
  36. use Leogout\Bundle\SeoBundle\Seo\Og\OgSeoGenerator;
  37. use Symfony\Component\String\Slugger\SluggerInterface;
  38. use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator;
  39. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  40. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  41. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  42. class PageController extends AbstractController
  43. {
  44.     public $basicSeo;
  45.     public $seo;
  46.     private $slugger;
  47.     private $projectDir;
  48.     private $metaService;
  49.     private $metaClePageRef;
  50.     private $renderBloc;
  51.     private $buildTree;
  52.     private $functionService;
  53.     private $metaPostService;
  54.     private $theme;
  55.     private $refMetaTagsService;
  56.     
  57.     public function __construct(string $projectDir,string $theme,
  58.                                 BasicSeoGenerator $basicSeo,
  59.                                 OgSeoGenerator $seo,
  60.                                 RenderBloc $renderBloc,
  61.                                 RefMetaTagsService $refMetaTagsService,
  62.                                 SluggerInterface $slugger,
  63.                                 BuildTree $buildTree,
  64.                                 MetaService $metaService,
  65.                                 MetaWithoutCategoryService $metaPostService,
  66.                                 MetaClePageRef $metaClePageRef,
  67.                                 FunctionService $functionService){
  68.         $this->metaService $metaService;
  69.         $this->metaPostService $metaPostService;
  70.         $this->basicSeo $basicSeo;
  71.         $this->seo $seo;
  72.         $this->buildTree $buildTree;
  73.         $this->slugger $slugger;
  74.         $this->metaClePageRef $metaClePageRef;
  75.         $this->functionService $functionService;
  76.         $this->refMetaTagsService $refMetaTagsService;
  77.         $this->renderBloc $renderBloc;
  78.         $this->projectDir $projectDir;
  79.         $this->theme $theme;
  80.     }
  81.     /**
  82.      * @Route("/{slug}/{page<[1-9]\d*>}", name="page")
  83.      */
  84.     public function Page(Request $request,$slug,$page 1)
  85.     {
  86.         $slug_info $this->getDoctrine()->getRepository(UrlPost::class)->findUrlBySlug($slug);
  87.         if(!$slug_info){
  88.             throw new NotFoundHttpException('Sorry not existing!');
  89.         }
  90.         dump($slug_info->getType());
  91.     
  92.         if($slug_info->getType() === "Post"){
  93.             $this->MetaModulePostOrCategory($request,$slug,$slug_info);
  94.             $post $this->getDoctrine()->getRepository(Post::class)->findPostBySlug($slug);
  95.             if($post == null){
  96.                 throw new NotFoundHttpException('Sorry not existing!');
  97.             }
  98.             if ($post->getTypePageRef() != null) {
  99.                 $render $this->pageRef($request,$slug);
  100.             }else{
  101.                 $render $this->pagePost($request,$slug);
  102.             }
  103.         }elseif ($slug_info->getType() === "Categorie"){
  104.             $this->MetaModulePostOrCategory($request,$slug,$slug_info);
  105.             $render $this->pageCatgorie($request,$slug,$page);
  106.         }elseif($slug_info->getType() === "Activite"){
  107.             $render $this->pageActivite($request,$slug,$slug_info);
  108.         }elseif($slug_info->getType() === "Activite_Secteur"){
  109.             $render $this->pageActiviteSecteur($request,$slug,$slug_info);
  110.         }elseif($slug_info->getType() === "Activite_Secondaire"){
  111.             $render $this->pageActiviteSecondaire($request,$slug,$slug_info);
  112.         }
  113.  
  114.         return $render;
  115.     }
  116.     public function pageRef($request,$slug){
  117.         $schemaOrg = new Graph();
  118.         $_locale $request->getLocale();
  119.         $post $this->getDoctrine()->getRepository(Post::class)->findPostBySlug($slug);
  120.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  121.         $modele_galerie_choisie $post->getModeleGallerie() ? $post->getModeleGallerie()->getId() : 1;
  122.         $modele_gallerie $this->getDoctrine()->getRepository(ModelGallerie::class)->findById($modele_galerie_choisie);
  123.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  124.         $seo_image '';
  125.         $url $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
  126.         if ($this->functionService->parametreGenerale()) {
  127.             if ($this->functionService->parametreGenerale()->getApercuImageLien()) {
  128.                 $seo_image $baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getApercuImageLien();
  129.             }
  130.         }
  131.         $galleries_images = [];
  132.         $bloc_post $this->renderBloc->RenderBloc($post,$schemaOrg);
  133.         $module $post->getTypePost()->getSystemName();
  134.         $galleries $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'media');
  135.         if($galleries){
  136.             foreach ($galleries as $value) {
  137.   
  138.                 $extension_file pathinfo($value->getFileName(), PATHINFO_EXTENSION);
  139.                 $new_galleries_images = ['id'=> $value->getId(),
  140.                                             'path'=> '',
  141.                                             'lienexterne' => $value->getLienExterne(),
  142.                                             'titre'=> $value->translate($_locale)->getTitre(),
  143.                                             'description'=> $value->translate($_locale)->getDescription(),
  144.                                             'extension_file' => $extension_file
  145.                                         ];
  146.                 if($extension_file != 'mp4'){
  147.                     // On récupère le nom de fichier sans son extension
  148.                     $nom_sans_extension pathinfo($value->getFileName(), PATHINFO_FILENAME);
  149.                     // On modifie l'extension du fichier
  150.                     $nouvelle_extension 'webp';
  151.                     $nouveau_nom_fichier $nom_sans_extension '.' $nouvelle_extension;
  152.                     $new_galleries_images['path'] = 'storage/galleries/'.$nouveau_nom_fichier;
  153.                 }else{
  154.                     $new_galleries_images['path'] = 'uploads/media/'.$value->getFileName();
  155.                 }
  156.                 
  157.                 $galleries_images[] = $new_galleries_images;
  158.             }
  159.         }
  160.         $docs $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'doc');
  161.         
  162.         $ListId = [];
  163.         if($post->getPostCategory()){
  164.             foreach($post->getPostCategory() as $value){
  165.                 $ListId[]= $value->getCategory()->getId();
  166.             }
  167.         }
  168.         $categorieTree null;
  169.         if (!empty($ListId)) {
  170.             $categories $this->getDoctrine()->getRepository(Category::class)->findCategoriePost($ListId);
  171.             $categorieTree $this->functionService->buildTree($categories); 
  172.         }
  173.         $meta_robots $post->getMetaRobots();
  174.         $custom_schemaOrg null;
  175.         if ($post->translate($_locale)->getSchema() != '') {
  176.             $custom_schemaOrg $post->translate($_locale)->getSchema();
  177.         }
  178.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  179.         $breadcrumb_item 1;
  180.         $breadcrumb = [];
  181.         $schema_breadcrumb_items = [];
  182.         $title_post_ariane $post->translate($_locale)->getBreadcrumb() ? $post->translate($_locale)->getBreadcrumb() : $post->translate($_locale)->getTitle();
  183.         $breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
  184.         $schema_breadcrumb_items[] = Schema::ListItem()
  185.                                    ->position(1)
  186.                                    ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  187.         $breadcrumb_item 1;
  188.         if ($post->getIdActivite() != null) {
  189.             $breadcrumb_item $breadcrumb_item 1;
  190.             $activite $this->getDoctrine()->getRepository(Activites::class)->find($post->getIdActivite());
  191.             if($activite){
  192.                 $title_breadcrumb_activite_primaire =  $activite->translate($_locale)->getBreadcrumb() ? $activite->translate($_locale)->getBreadcrumb() : $activite->translate($_locale)->getTitreActivite(); 
  193.                 $breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=>  $activite->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
  194.                                   'name'=> $title_breadcrumb_activite_primaire,'active'=> true];
  195.                 $schema_breadcrumb_items[] = Schema::ListItem()
  196.                                             ->position($breadcrumb_item)
  197.                                             ->item(["@id"=> $this->generateUrl('page', ['slug'=>  $activite->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
  198.                                             "name"=> $title_breadcrumb_activite_primaire]);
  199.             }
  200.         }
  201.         if ($post->getIdSousActivite() != null) {
  202.             $breadcrumb_item $breadcrumb_item 1;
  203.             $activite_secondaire $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->find($post->getIdSousActivite());
  204.             if($activite_secondaire){
  205.                 $title_breadcrumb_activite_secondaire =  $activite_secondaire->translate($_locale)->getBreadcrumb() ? $activite_secondaire->translate($_locale)->getBreadcrumb() : $activite_secondaire->translate($_locale)->getTitreActiviteSecondaire();
  206.                 $breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=>  $activite_secondaire->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
  207.                                   'name'=> $title_breadcrumb_activite_secondaire,'active'=> true];
  208.                 $schema_breadcrumb_items[] = Schema::ListItem()
  209.                                             ->position($breadcrumb_item)
  210.                                             ->item(["@id"=> $this->generateUrl('page', ['slug'=>  $activite_secondaire->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
  211.                                             "name"=> $title_breadcrumb_activite_secondaire]);
  212.             }
  213.         }
  214.         $breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),
  215.                          'name'=> $post->translate($_locale)->getTitle(),'active'=> false];                        
  216.         $schema_breadcrumb_items[] = Schema::ListItem()
  217.                                     ->position($breadcrumb_item 1)
  218.                                     ->item(["@id"=> $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=>$title_post_ariane]);
  219.         if ($schema_breadcrumb_items) {
  220.             $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  221.         }
  222.         $schemaOrg->add(Schema::Article()->headline($title_post_ariane)
  223.                                          ->datePublished($post->getDatePublication()?$post->getDatePublication():$post->getCreatedAt())
  224.                                          ->dateModified($post->getUpdatedAt())
  225.                                          ->image($post->getImage()!= null?$baseurl.$post->getImage():'')
  226.                                          ->publisher(Schema::Organization()
  227.                                             ->name($this->functionService->parametreGenerale()?$this->functionService->parametreGenerale()->translate($_locale)->getTitre():'')
  228.                                             ->logo($this->functionService->parametreGenerale()?$baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getImage():''))
  229.                                          ->mainEntityOfPage(Schema::WebPage()->url($url))
  230.                                         );
  231.         
  232.         $url_social = [];
  233.         $social $this->getDoctrine()->getRepository(ReseauSociaux::class)->findAll();
  234.         if($social){
  235.             foreach ($social as $value) {
  236.                 $url_social[] = $value->getUrl();
  237.             }
  238.         }
  239.         // id categorie related with post 
  240.         $categoiesPosts $this->getDoctrine()->getRepository(PostCategory::class)->findCategorieByPost($post->getId());
  241.         $next_article $this->getDoctrine()->getRepository(Post::class)->findPostPrevOrNext($categoiesPosts,$post->getId());
  242.         $prev_article $this->getDoctrine()->getRepository(Post::class)->findPostPrevOrNext($categoiesPosts,$post->getId(),'prev');
  243.         $template_model_galerie $modele_gallerie[0]->getTwig();
  244.         $parametre $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
  245.  
  246.         $secteur $this->getDoctrine()->getRepository(Secteurs::class)->find($post->getIdSecteur());
  247.         $actualite_ref $this->getDoctrine()->getRepository(Post::class)->findPostByIdSecteur($post->getId(),$post->getIdActivite(),$post->getIdSecteur());
  248.         
  249.         
  250.         $template =  $this->render('front/'.$this->theme.'/page_ref.html.twig',[
  251.             'post'=> $post,
  252.             'secteur'=> $secteur,
  253.             'title_home_ariane' => $title_home_ariane,
  254.             'galleries'=> $galleries_images,
  255.             'docs'=> $docs,
  256.             'blocs'=> $bloc_post,
  257.             'meta_robots'=> $meta_robots,
  258.             'schemaOrg'=> $schemaOrg,
  259.             'custom_schemaOrg'=> $custom_schemaOrg,
  260.             'parametre'=> $parametre,
  261.             'next_article'=> $next_article,
  262.             'prev_article'=> $prev_article,
  263.             'modele_galerie' => $modele_gallerie,
  264.             'template_model_gallerie' => $template_model_galerie,
  265.             'actualite_ref'=> $actualite_ref,
  266.             'breadcrumb'=> $breadcrumb
  267.         ]);
  268.         return $template;
  269.     }
  270.     public function pagePost($request,$slug){
  271.         $schemaOrg = new Graph();
  272.         $_locale $request->getLocale();
  273.         $post $this->getDoctrine()->getRepository(Post::class)->findPostBySlug($slug);
  274.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  275.         $modele_galerie_choisie $post->getModeleGallerie() ? $post->getModeleGallerie()->getId() : 1;
  276.         $modele_gallerie $this->getDoctrine()->getRepository(ModelGallerie::class)->findById($modele_galerie_choisie);
  277.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  278.         $seo_image '';
  279.         $url $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
  280.         if ($this->functionService->parametreGenerale()) {
  281.             if ($this->functionService->parametreGenerale()->getApercuImageLien()) {
  282.                 $seo_image $baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getApercuImageLien();
  283.             }
  284.         }
  285.         $galleries_images = [];
  286.         $bloc_post $this->renderBloc->RenderBloc($post,$schemaOrg);
  287.         $module $post->getTypePost()->getSystemName();
  288.         $galleries $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'media');
  289.         if($galleries){
  290.             foreach ($galleries as $value) {
  291.   
  292.                 $extension_file pathinfo($value->getFileName(), PATHINFO_EXTENSION);
  293.                 $new_galleries_images = ['id'=> $value->getId(),
  294.                                             'path'=> '',
  295.                                             'lienexterne' => $value->getLienExterne(),
  296.                                             'titre'=> $value->translate($_locale)->getTitre(),
  297.                                             'description'=> $value->translate($_locale)->getDescription(),
  298.                                             'extension_file' => $extension_file
  299.                                         ];
  300.                 if($extension_file != 'mp4'){
  301.                     // On récupère le nom de fichier sans son extension
  302.                     $nom_sans_extension pathinfo($value->getFileName(), PATHINFO_FILENAME);
  303.                     // On modifie l'extension du fichier
  304.                     $nouvelle_extension 'webp';
  305.                     $nouveau_nom_fichier $nom_sans_extension '.' $nouvelle_extension;
  306.                     $new_galleries_images['path'] = 'storage/galleries/'.$nouveau_nom_fichier;
  307.                 }else{
  308.                     $new_galleries_images['path'] = 'uploads/media/'.$value->getFileName();
  309.                 }
  310.                 
  311.                 $galleries_images[] = $new_galleries_images;
  312.             }
  313.         }
  314.         $docs $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'doc');
  315.         
  316.         $ListId = [];
  317.         if($post->getPostCategory()){
  318.             foreach($post->getPostCategory() as $value){
  319.                 $ListId[]= $value->getCategory()->getId();
  320.             }
  321.         }
  322.         $categorieTree null;
  323.         if (!empty($ListId)) {
  324.             $categories $this->getDoctrine()->getRepository(Category::class)->findCategoriePost($ListId);
  325.             $categorieTree $this->functionService->buildTree($categories); 
  326.         }
  327.         $meta_robots $post->getMetaRobots();
  328.         $custom_schemaOrg null;
  329.         if ($post->translate($_locale)->getSchema() != '') {
  330.             $custom_schemaOrg $post->translate($_locale)->getSchema();
  331.         }
  332.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  333.         $breadcrumb_item 1;
  334.         $schema_breadcrumb_items = [];
  335.         $schema_breadcrumb_items[] = Schema::ListItem()
  336.                                    ->position(1)
  337.                                    ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=>$title_home_ariane]);
  338.         if($categorieTree){
  339.             foreach ($categorieTree as $value) {
  340.                 $breadcrumb_item $breadcrumb_item 1;
  341.                 $schema_breadcrumb_items[] = Schema::ListItem()
  342.                                             ->position($breadcrumb_item)
  343.                                             ->item(["@id"=> $this->generateUrl('page', ['slug'=> $value['slug']], UrlGeneratorInterface::ABSOLUTE_URL),"name"=>$value['titre']]);
  344.             }
  345.         }
  346.         
  347.         $title_post_ariane $post->translate($_locale)->getBreadcrumb() ? $post->translate($_locale)->getBreadcrumb() : $post->translate($_locale)->getTitle();
  348.         $schema_breadcrumb_items[] = Schema::ListItem()
  349.                                     ->position($breadcrumb_item 1)
  350.                                     ->item(["@id"=> $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=>$title_post_ariane]);
  351.         if ($schema_breadcrumb_items) {
  352.             $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  353.         }
  354.         $schemaOrg->add(Schema::Article()->headline($title_post_ariane)
  355.                                          ->datePublished($post->getDatePublication()?$post->getDatePublication():$post->getCreatedAt())
  356.                                          ->dateModified($post->getUpdatedAt())
  357.                                          ->image($post->getImage()!= null?$baseurl.$post->getImage():'')
  358.                                          ->publisher(Schema::Organization()
  359.                                             ->name($this->functionService->parametreGenerale()?$this->functionService->parametreGenerale()->translate($_locale)->getTitre():'')
  360.                                             ->logo($this->functionService->parametreGenerale()?$baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getImage():''))
  361.                                          ->mainEntityOfPage(Schema::WebPage()->url($url))
  362.                                         );
  363.         
  364.         $url_social = [];
  365.         $social $this->getDoctrine()->getRepository(ReseauSociaux::class)->findAll();
  366.         if($social){
  367.             foreach ($social as $value) {
  368.                 $url_social[] = $value->getUrl();
  369.             }
  370.         }
  371.         // id categorie related with post 
  372.         $categoiesPosts $this->getDoctrine()->getRepository(PostCategory::class)->findCategorieByPost($post->getId());
  373.         $next_article $this->getDoctrine()->getRepository(Post::class)->findPostPrevOrNext($categoiesPosts,$post->getId());
  374.         $prev_article $this->getDoctrine()->getRepository(Post::class)->findPostPrevOrNext($categoiesPosts,$post->getId(),'prev');
  375.         $template_model_galerie $modele_gallerie[0]->getTwig();
  376.         $parametre $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
  377.  
  378.         if($post->getTemplateCms()){
  379.     
  380.             $template $this->render('front/'.$this->theme.'/dynamique-page-cms.html.twig',[
  381.                  'template'=> $post->getTemplateCms()->getTwig(),
  382.                  'post'=> $post,
  383.                  'title_home_ariane' => $title_home_ariane,
  384.                  'galleries'=> $galleries_images,
  385.                  'bloc_post'=> $bloc_post,
  386.                  'categorieTree'=> $categorieTree,
  387.                  'meta_robots'=> $meta_robots,
  388.                  'schemaOrg'=> $schemaOrg,
  389.                  'custom_schemaOrg'=> $custom_schemaOrg,
  390.                  'parametre'=> $parametre,
  391.                  'next_article'=> $next_article,
  392.                  'prev_article'=> $prev_article,
  393.                  'modele_galerie' => $modele_gallerie,
  394.                  'template_model_gallerie' => $template_model_galerie,
  395.            ]);
  396.            
  397.         }else{
  398.             // Champs personnalisés
  399.             $valsChamp = [];
  400.             $labelsChamp = [];
  401.             $vCpFields $this->getDoctrine()->getRepository(CpPostField::class)->findBy(['IdPost'=>$post->getId()]);
  402.             $labelFiels "";
  403.             if($vCpFields){
  404.                 foreach ($vCpFields as $vCpField) {
  405.                     $labelFiels $vCpField->getCpField()->translate($_locale)->getLabel();
  406.                     $TypeFiels $vCpField->getCpField()->translate($_locale)->getType();
  407.                     //dump($TypeFiels);
  408.                     $labelsChamp += [
  409.                         $vCpField->getID()=> $labelFiels
  410.                     ];
  411.     
  412.                     if($vCpField){
  413.                         $valChamp $vCpField->getLinkValue() ? $vCpField->getLinkValue() : $vCpField->getTextareaValue();
  414.                         $valsChamp += [
  415.                             $vCpField->getID()=> $valChamp
  416.                         ];  
  417.                     }
  418.                 }
  419.             }
  420.             $template =  $this->render('front/'.$this->theme.'/page_cms.html.twig',[
  421.                 'post'=> $post,
  422.                 'title_home_ariane' => $title_home_ariane,
  423.                 'galleries'=> $galleries_images,
  424.                 'docs'=> $docs,
  425.                 'blocs'=> $bloc_post,
  426.                 'categorieTree'=> $categorieTree,
  427.                 'meta_robots'=> $meta_robots,
  428.                 'schemaOrg'=> $schemaOrg,
  429.                 'custom_schemaOrg'=> $custom_schemaOrg,
  430.                 'champsPersonnalises' => $valsChamp,
  431.                 'lblchampsPersonnalises' => $labelsChamp,
  432.                 'parametre'=> $parametre,
  433.                 'next_article'=> $next_article,
  434.                 'prev_article'=> $prev_article,
  435.                 'modele_galerie' => $modele_gallerie,
  436.                 'template_model_gallerie' => $template_model_galerie,
  437.             ]);
  438.         }
  439.         return $template;
  440.     }
  441.     public function pageCatgorie($request,$slug,$page){
  442.         $module 'category';
  443.         $resultats = [];
  444.         $schemaOrg = new Graph();
  445.         $_locale $request->getLocale();
  446.         $categorie $this->getDoctrine()->getRepository(Category::class)->findCategoryBySlug($slug);
  447.         $sousCategorie $this->getDoctrine()->getRepository(Category::class)->findBy(['parent'=> $categorie->getId()],['order_by'=>'ASC']);
  448.         
  449.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  450.         $template $categorie->getTypeAffichageHome();
  451.         $bloc_categorie $this->renderBloc->RenderBloc($categorie,$schemaOrg,'categorie');
  452.         // Galleries
  453.         $galleries_images = [];
  454.         $modele_galerie_choisie $categorie->getModeleGallerie() ? $categorie->getModeleGallerie()->getId() : 1;
  455.         $modele_gallerie $this->getDoctrine()->getRepository(ModelGallerie::class)->findById($modele_galerie_choisie);
  456.         $galleries $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$categorie->getId(),'media');
  457.         if($galleries){
  458.             foreach ($galleries as $value) {
  459.   
  460.                 $extension_file pathinfo($value->getFileName(), PATHINFO_EXTENSION);
  461.                 $new_galleries_images = ['id'=> $value->getId(),
  462.                                             'path'=> '',
  463.                                             'lienexterne' => $value->getLienExterne(),
  464.                                             'titre'=> $value->translate($_locale)->getTitre(),
  465.                                             'description'=> $value->translate($_locale)->getDescription(),
  466.                                             'extension_file' => $extension_file
  467.                                         ];
  468.                 if($extension_file != 'mp4'){
  469.                     // On récupère le nom de fichier sans son extension
  470.                     $nom_sans_extension pathinfo($value->getFileName(), PATHINFO_FILENAME);
  471.                     // On modifie l'extension du fichier
  472.                     $nouvelle_extension 'webp';
  473.                     $nouveau_nom_fichier $nom_sans_extension '.' $nouvelle_extension;
  474.                     $new_galleries_images['path'] = 'storage/galleries/'.$nouveau_nom_fichier;
  475.                 }else{
  476.                     $new_galleries_images['path'] = 'uploads/media/'.$value->getFileName();
  477.                 }
  478.                 
  479.                 $galleries_images[] = $new_galleries_images;
  480.             }
  481.         }
  482.         $template_model_galerie $modele_gallerie[0]->getTwig();
  483.         if ($categorie->getPagination() == true) {
  484.             $posts $this->getDoctrine()->getRepository(Post::class)->findPostByCategory($categorie->getId(),$categorie->getPagination(),$page,$categorie->getPageSize());
  485.             if($posts->getResults()){
  486.                 foreach ($posts->getResults() as $value) {
  487.                     $resultats[] = [ 'id'=> $value->getId(),
  488.                                      'slug'=> $value->getSlug(),
  489.                                      'titre'=> $value->getTitle(),
  490.                                      'title_affichage'=> $value->getTitleAffichage(),
  491.                                      'content'=> $value->getContent(),
  492.                                      'chapeau'=> $value->getSummary(),
  493.                                      'image'=> $value->getImage(),
  494.                                      'typelien'=> $value->getTypeLien(),
  495.                                      'titrelien'=> $value->getTitreLien(),
  496.                                      'telephone'=> $value->getTelephone(),
  497.                                      'lieninterne'=> $value->getLienInterne(),
  498.                                      'lienexterne'=> $value->getLienExterne(),
  499.                                     ];
  500.                 }
  501.             }
  502.         }else{
  503.             $posts $this->getDoctrine()->getRepository(Post::class)->findPostByCategory($categorie->getId(),false,$page,$categorie->getPageSize());
  504.             if($posts){
  505.                 foreach ($posts as $value) {
  506.                     // Champs personnalisés
  507.                     $valsChamp = [];
  508.                     $vCpFields $this->getDoctrine()->getRepository(CpPostField::class)->findBy(['IdPost'=>$value->getId()]);
  509.                     if($vCpFields){
  510.                     foreach ($vCpFields as $vCpField) {
  511.                         if($vCpField){
  512.                         $valChamp $vCpField->getLinkValue() ? $vCpField->getLinkValue() : $vCpField->getTextareaValue();
  513.                         $valsChamp += [
  514.                             $vCpField->getID()=> $valChamp
  515.                         ];  
  516.                         
  517.                         }
  518.                     }
  519.                     }
  520.                     $resultats[] = [ 'id'=> $value->getId(),
  521.                                      'slug'=> $value->getSlug(),
  522.                                      'titre'=> $value->getTitle(),
  523.                                      'title_affichage'=> $value->getTitleAffichage(),
  524.                                      'content'=> $value->getContent(),
  525.                                      'chapeau'=> $value->getSummary(),
  526.                                      'image'=> $value->getImage(),
  527.                                      'typelien'=> $value->getTypeLien(),
  528.                                      'titrelien'=> $value->getTitreLien(),
  529.                                      'telephone'=> $value->getTelephone(),
  530.                                      'lieninterne'=> $value->getLienInterne(),
  531.                                      'lienexterne'=> $value->getLienExterne(),
  532.                                      'champsPersonnalises' => $valsChamp,
  533.                                     ];
  534.                 }
  535.             }
  536.         }
  537.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  538.        
  539.         $meta_robots $categorie->getMetaRobots();
  540.         $schema_breadcrumb_items = [];
  541.         $schema_breadcrumb_items[] = Schema::ListItem()
  542.                                    ->position(1)
  543.                                    ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  544.         $schema_breadcrumb_items[] = Schema::ListItem()
  545.                                     ->position(2)
  546.                                     ->item(["@id"=> $this->generateUrl('page', ['slug'=> $categorie->translate($_locale)->getSlugUrl()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $categorie->translate($_locale)->getTitreCategorie()]);
  547.         if ($schema_breadcrumb_items) {
  548.             $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  549.         }
  550.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  551.         $schemaOrg->add(Schema::Article()
  552.                             ->headline($categorie->translate($_locale)->getTitreCategorie())
  553.                             ->datePublished($categorie->getCreatedAt())
  554.                             ->dateModified($categorie->getUpdatedAt())
  555.                             ->image($categorie->getImage()!= null?$baseurl.$categorie->getImage():'')
  556.                             ->publisher(Schema::Organization()
  557.                             ->name($this->functionService->parametreGenerale()?$this->functionService->parametreGenerale()->translate($_locale)->getTitre():'')
  558.                             ->logo($this->functionService->parametreGenerale()?$baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getImage():''))
  559.                             ->mainEntityOfPage(Schema::WebPage()->url($this->generateUrl('page', ['slug'=> $categorie->translate($_locale)->getSlugUrl()], UrlGeneratorInterface::ABSOLUTE_URL)))
  560.                         );
  561.         $module $categorie->getTypePost()->translate($_locale)->getSystemName();
  562.         $galleries $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$categorie->getId(),'media');
  563.         $docs $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$categorie->getId(),'doc');
  564.         $parametre $this->functionService->parametreGenerale();
  565.         
  566.         return $this->render('front/'.$this->theme.'/page_categorie.html.twig',[
  567.             'template'=> $template,
  568.             'title_home_ariane' => $title_home_ariane,
  569.             'categorie'=> $categorie,
  570.             'resultats'=> $resultats,
  571.             'blocs'=> $bloc_categorie,
  572.             'posts'=> $posts,
  573.             'meta_robots'=> $meta_robots,
  574.             'pagination'=> $categorie->getPagination(),
  575.             'schemaOrg'=> $schemaOrg,
  576.             'galleries'=> $galleries_images,
  577.             'docs'=> $docs,
  578.             'parametre'=> $parametre,
  579.             'modele_galerie' => $modele_gallerie,
  580.             'template_model_gallerie' => $template_model_galerie,
  581.         ]);
  582.     }
  583.     public function pageActivite($request,$slug,$slug_info){
  584.         $_locale $request->getLocale();
  585.         $activite $this->getDoctrine()->getRepository(Activites::class)->findActiviteBySlug($slug);
  586.         $titre $activite->translate($_locale)->getTitre();
  587.         $titre_activite $activite->translate($_locale)->getTitreActivite();
  588.         $texte $activite->translate($_locale)->getTextActivitePrincipalFinal();
  589.         $meta_tags $this->metaService->generateMetaPage($activite,'activite');
  590.         if ($meta_tags) {
  591.             $this->basicSeo->setTitle($meta_tags['title'])
  592.                            ->setDescription($meta_tags['description']);
  593.         }
  594.         $secteurs = [];
  595.         $all_secteurs $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=> true]);
  596.         if ($all_secteurs) {
  597.             foreach ($all_secteurs as $secteur) {
  598.                if(in_array($activite->getId(),explode(',',$secteur->getActivitePrimaireIds()))){
  599.                    $secteurs[] = $secteur;
  600.                }
  601.             }
  602.         }
  603.         
  604.         $medias $this->getDoctrine()->getRepository(MediaCms::class)->findBy(['module'=>'Activite','module_id'=>$activite->getId()]);
  605.         $ref_pages $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdActivite($activite->getId());
  606.         $actualites $this->getDoctrine()->getRepository(Post::class)->findPageClientByIdActiviteOrSousActivite($activite->getId());
  607.         $parametre $this->functionService->parametreGenerale();
  608.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  609.         $title_home_ariane $home->translate($_locale)->getBreadcrumb() ? $home->translate($_locale)->getBreadcrumb() : "Accueil";
  610.         $schemaOrg = new Graph();
  611.         $breadcrumb = [];
  612.         $schema_breadcrumb_items = [];
  613.         
  614.         $breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
  615.         $schema_breadcrumb_items[] = Schema::ListItem()
  616.                                      ->position(1)
  617.                                      ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  618.         
  619.         $title_breadcrumb_activite =  $activite->translate($_locale)->getBreadcrumb() ? $activite->translate($_locale)->getBreadcrumb() : $titre_activite;
  620.         $breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=>  $activite->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_breadcrumb_activite,'active'=> false];
  621.         $schema_breadcrumb_items[] = Schema::ListItem()
  622.                                     ->position(2)
  623.                                     ->item(["@id"=> $this->generateUrl('page', ['slug'=>  $activite->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_breadcrumb_activite]);
  624.    
  625.         $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  626.         
  627.         $meta_tags $this->refMetaTagsService->generateMetaPage($activite,'activite');
  628.         if ($meta_tags) {
  629.             $this->basicSeo->setTitle($meta_tags['title'])
  630.                            ->setDescription($meta_tags['description']);
  631.         }
  632.         
  633.         $template =  $this->render('front/'.$this->theme.'/page_activite.html.twig',[
  634.             'titre'=> $titre,
  635.             'texte'=> $texte,
  636.             'titre_activite'=> $titre_activite,
  637.             'slug'=> $slug,
  638.             'medias'=> $medias,
  639.             'ref_pages'=> $ref_pages,
  640.             'actualites'=> $actualites,
  641.             'parametre'=> $parametre,
  642.             'secteurs'=> $secteurs,
  643.             'breadcrumb'=> $breadcrumb,
  644.             'schemaOrg'=> $schemaOrg,
  645.         ]);
  646.         return $template;
  647.     }
  648.     public function pageActiviteSecteur($request,$slug,$slug_info){
  649.         $_locale $request->getLocale();
  650.         $activite_primaire_titre null;
  651.         $activite_primaire_slug null;
  652.         $activite_secondaire_titre null;
  653.         $activite_secondaire_slug null;
  654.         $activite_secteur $this->getDoctrine()->getRepository(ListeRef::class)->findActiviteSecteurBySlug($slug);
  655.         if ($activite_secteur) {
  656.             if ($activite_secteur->getType() == 'activite_primaire') {
  657.                 $activite $this->getDoctrine()->getRepository(Activites::class)->findOneBy(['actif'=>true,'id'=>$activite_secteur->getIdActivite()]);
  658.                 if($activite){
  659.                     $activite_primaire_titre $activite->translate($_locale)->getTitreActivite();
  660.                     $activite_primaire_slug $activite->translate($_locale)->getLibelleUrl();
  661.                 }
  662.             }else{
  663.                 $activite_secondaire $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->findOneBy(['actif'=>true,'id'=>$activite_secteur->getIdActivite()]);
  664.                 if ($activite_secondaire) {
  665.                     $activite_secondaire_titre $activite_secondaire->translate($_locale)->getTitreActiviteSecondaire();
  666.                     $activite_secondaire_slug $activite_secondaire->translate($_locale)->getLibelleUrl();
  667.                 }
  668.                 if ($activite_secondaire->getActivitePrimaire()) {
  669.                     $activite_primaire_titre $activite_secondaire->getActivitePrimaire()->translate($_locale)->getTitreActivite();
  670.                     $activite_primaire_slug $activite_secondaire->getActivitePrimaire()->translate($_locale)->getLibelleUrl();
  671.                 }
  672.             }
  673.         }
  674.         $meta_tags $this->metaService->generateMetaPage($activite_secteur,'activite_secteur');
  675.         if ($meta_tags) {
  676.             $this->basicSeo->setTitle($meta_tags['title'])
  677.                            ->setDescription($meta_tags['description']);
  678.         }
  679.      
  680.     
  681.         $template =  $this->render('front/'.$this->theme.'/page_activite_secteur.html.twig',[
  682.             'activite_secteur'=> $activite_secteur,
  683.             'slug'=> $slug,
  684.             'activite_primaire_titre'=> $activite_primaire_titre,
  685.             'activite_primaire_slug'=> $activite_primaire_slug,
  686.             'activite_secondaire_titre'=> $activite_secondaire_titre,
  687.             'activite_secondaire_slug'=> $activite_secondaire_slug,
  688.         ]);
  689.         return $template;
  690.     }
  691.     public function pageActiviteSecondaire($request,$slug,$slug_info){
  692.         $_locale $request->getLocale();
  693.         $activite_primaire_titre null;
  694.         $activite_primaire_slug null;
  695.         $activite_secondaire $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->findActiviteBySlug($slug);
  696.         if ($activite_secondaire->getActivitePrimaire()) {
  697.             $activite_primaire_titre =  $activite_secondaire->getActivitePrimaire()->translate($_locale)->getTitreActivite();
  698.             $activite_primaire_slug $activite_secondaire->getActivitePrimaire()->translate($_locale)->getLibelleUrl();
  699.         }
  700.         $titre $activite_secondaire->translate($_locale)->getTitre();
  701.         $titre_activite $activite_secondaire->translate($_locale)->getTitreActiviteSecondaire();
  702.         $texte $activite_secondaire->translate($_locale)->getTextActiviteSecondaireFinal();
  703.         $meta_tags $this->refMetaTagsService->generateMetaPage($activite_secondaire,'activite_secondaire');
  704.         if ($meta_tags) {
  705.             $this->basicSeo->setTitle($meta_tags['title'])
  706.                            ->setDescription($meta_tags['description']);
  707.         }
  708.         $ref_pages $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdSousActivite($activite_secondaire->getId());
  709.         $actualites $this->getDoctrine()->getRepository(Post::class)->findPageClientByIdActiviteOrSousActivite($activite_secondaire->getId(),'activite_secondaire');
  710.         $parametre $this->functionService->parametreGenerale();
  711.         $secteurs = [];
  712.         $all_secteurs $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=> true]);
  713.         if ($all_secteurs) {
  714.             foreach ($all_secteurs as $secteur) {
  715.                if(in_array($activite_secondaire->getId(),explode(',',$secteur->getActiviteSecondaireIds()))){
  716.                    $secteurs[] = $secteur;
  717.                }
  718.             }
  719.         }
  720.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  721.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  722.         $schemaOrg = new Graph();
  723.         $breadcrumb = [];
  724.         $schema_breadcrumb_items = [];
  725.         
  726.         $breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
  727.         $schema_breadcrumb_items[] = Schema::ListItem()
  728.                                      ->position(1)
  729.                                      ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  730.         $breadcrumb_item 1;
  731.         if ($activite_secondaire->getActivitePrimaire()) {
  732.             $breadcrumb_item $breadcrumb_item 1
  733.             $activite_primaire $activite_secondaire->getActivitePrimaire();
  734.             $activite_primaire_titre =  $activite_primaire->translate($_locale)->getTitreActivite();
  735.             $activite_primaire_slug $activite_primaire->translate($_locale)->getLibelleUrl();
  736.             $title_breadcrumb_activite_primaire =  $activite_primaire->translate($_locale)->getBreadcrumb() ? $activite_primaire->translate($_locale)->getBreadcrumb() : $activite_primaire_titre;
  737.             $breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=>  $activite_primaire_slug], UrlGeneratorInterface::ABSOLUTE_URL),
  738.                               "name"=> $title_breadcrumb_activite_primaire,'active'=> true];
  739.             $schema_breadcrumb_items[] = Schema::ListItem()
  740.                                     ->position($breadcrumb_item)
  741.                                     ->item(["@id"=> $this->generateUrl('page', ['slug'=>  $activite_primaire_slug], UrlGeneratorInterface::ABSOLUTE_URL),
  742.                                             "name"=> $title_breadcrumb_activite_primaire]);
  743.    
  744.         }
  745.         $title_breadcrumb_activite_secondaire =  $activite_secondaire->translate($_locale)->getBreadcrumb() ? $activite_secondaire->translate($_locale)->getBreadcrumb() : $activite_secondaire->translate($_locale)->getTitreActiviteSecondaire();
  746.         $breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=>  $activite_secondaire->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
  747.                             'name'=> $title_breadcrumb_activite_secondaire,'active'=> false];
  748.         $schema_breadcrumb_items[] = Schema::ListItem()
  749.                                     ->position($breadcrumb_item 1)
  750.                                     ->item(["@id"=> $this->generateUrl('page', ['slug'=>  $activite_secondaire->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
  751.                                     "name"=> $title_breadcrumb_activite_secondaire]);
  752.     
  753.         $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  754.         
  755.         $template =  $this->render('front/'.$this->theme.'/page_activite_secondaire.html.twig',[
  756.             'titre'=> $titre,
  757.             'texte'=> $texte,
  758.             'titre_activite'=>$titre_activite,
  759.             'activite_primaire_titre'=> $activite_primaire_titre,
  760.             'activite_primaire_slug'=> $activite_primaire_slug,
  761.             'slug'=> $slug,
  762.             'schemaOrg'=> $schemaOrg,
  763.             'ref_pages'=> $ref_pages,
  764.             'actualites'=> $actualites,
  765.             'parametre'=> $parametre,
  766.             'secteurs'=> $secteurs,
  767.             'breadcrumb'=> $breadcrumb
  768.         ]);
  769.         return $template;
  770.     }
  771.     function MetaModulePostOrCategory($request,$slug,$slug_info){
  772.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  773.         $url $this->generateUrl('page', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL);
  774.      // $metaService = $this->metaService->meta($slug,$slug_info->getType());
  775.         $title_seo =  isset($metaService['title'])?$metaService['title']:null;
  776.         $description_seo = isset($metaService['description'])?$metaService['description']:null;
  777.         $metacle = isset($metaService['metacle'])?$metaService['metacle']:null;
  778.         if($title_seo != '' || $description_seo != ''){
  779.             $this->basicSeo->setTitle($title_seo)
  780.                         ->setDescription($description_seo)
  781.                         ->setkeywords($metacle);
  782.             $this->seo->setTitle($title_seo)
  783.                     ->setDescription($description_seo)
  784.                     ->setUrl($url);
  785.             if ($this->functionService->parametreGenerale()) {
  786.                 if ($this->functionService->parametreGenerale()->getApercuImageLien()) {
  787.                     $this->seo->setImage($baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getApercuImageLien());
  788.                 }
  789.             }
  790.         }
  791.     }
  792. }