src/Controller/Front/LocaliteController.php line 194

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\Contact;
  6. use App\Entity\Country;
  7. use App\Entity\UrlPost;
  8. use App\Entity\Language;
  9. use App\Entity\ListeRef;
  10. use App\Entity\Secteurs;
  11. use App\Entity\GroupBloc;
  12. use App\Entity\ListeMenu;
  13. use App\Service\BuildTree;
  14. use Spatie\SchemaOrg\Graph;
  15. use App\Entity\ParamContact;
  16. use App\Entity\ParametreRef;
  17. use App\Entity\ThemeOptions;
  18. use App\Service\MetaService;
  19. use Spatie\SchemaOrg\Schema;
  20. use App\Entity\ParametreSite;
  21. use App\Entity\ProduitOption;
  22. use App\Entity\ReseauSociaux;
  23. use App\Entity\TextParametrable;
  24. use App\Service\FunctionService;
  25. use App\Entity\CategoriesProduct;
  26. use App\Service\RenderDefaultBloc;
  27. use App\Service\RefMetaTagsService;
  28. use App\Entity\TextParametrableTranslation;
  29. use Symfony\Component\Filesystem\Filesystem;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Component\HttpFoundation\Response;
  32. use Symfony\Component\Routing\Annotation\Route;
  33. use Symfony\Contracts\HttpClient\HttpClientInterface;
  34. use Symfony\Component\Translation\TranslatorInterface;
  35. use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator;
  36. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  37. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  38. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  39. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  40. class LocaliteController  extends AbstractController
  41. {
  42.     private $functionService;
  43.     private $refMetaTagsService;
  44.     public $basicSeo;
  45.     public $metaService;
  46.     public function __construct(string $theme,MetaService $metaService,BasicSeoGenerator $basicSeoRefMetaTagsService $refMetaTagsService,HttpClientInterface $client,string $projectDirr,FunctionService $functionService)
  47.     {
  48.         $this->theme $theme;
  49.         $this->client $client;
  50.         $this->projectDirr $projectDirr;
  51.         $this->functionService $functionService;
  52.         $this->refMetaTagsService $refMetaTagsService;
  53.         $this->basicSeo $basicSeo;
  54.         $this->metaService $metaService;
  55.     }
  56.     /**
  57.      * @Route("/localites", name="page_localite", options={"sitemap" = true},priority=10)
  58.      */
  59.     public function index(Request $request)
  60.     {
  61.         $_locale $request->getLocale();
  62.         $parametreRef $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'hub_localite']);
  63.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  64.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  65.         $title_page $parametreRef && $parametreRef->translate($_locale)->getBreadcrumb() ? $parametreRef->translate($_locale)->getBreadcrumb() : "Localités";
  66.         $schemaOrg = new Graph();
  67.         $breadcrumb = [];
  68.         $schema_breadcrumb_items = [];
  69.         
  70.         $breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
  71.         $schema_breadcrumb_items[] = Schema::ListItem()
  72.                                      ->position(1)
  73.                                      ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  74.         
  75.         $breadcrumb [] = ['url'=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page,'active'=> false];
  76.         $schema_breadcrumb_items[] = Schema::ListItem()
  77.                                     ->position(2)
  78.                                     ->item(["@id"=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page]);
  79.                       
  80.         $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  81.         $secteurs $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=> true]);
  82.         $parametre $this->functionService->parametreGenerale();
  83.         if ($parametreRef) {
  84.             $meta_tags $this->metaService->generateMetaPage($parametreRef,'hub_localite');
  85.             if ($meta_tags) {
  86.                 $this->basicSeo->setTitle($meta_tags['title'])
  87.                                ->setDescription($meta_tags['description']);
  88.             }
  89.         }
  90.         return $this->render('front/'.$this->theme.'/localite.html.twig',[
  91.             'secteurs'=> $secteurs,
  92.             'parametre'=> $parametre,
  93.             'breadcrumb'=> $breadcrumb,
  94.             'schemaOrg'=> $schemaOrg,
  95.             'parametreRef'=> $parametreRef,
  96.             'title_page'=> $title_page
  97.         ]);
  98.     }
  99.     /**
  100.      * @Route("/localite/{slug}", name="page_details_localite", options={"sitemap" = false},priority=10)
  101.      */
  102.     public function detialsLocalite(Request $request,$slug)
  103.     {
  104.         $_locale $request->getLocale();
  105.         $resultats = [];
  106.         $secteur $this->getDoctrine()->getRepository(Secteurs::class)->findSecteurBySlug($slug);
  107.         if ($secteur) {
  108.             $slug_lang $this->getDoctrine()->getRepository(UrlPost::class)->findLangUrl($slug);
  109.             if ($slug_lang['locale'] != $_locale) {
  110.                 $request->getSession()->set('_locale'$slug_lang['locale']);
  111.                 return $this->redirectToroute('page_details_localite',['slug'=> $slug]);
  112.             }
  113.             
  114.             $page_ref_activite_primaire $this->getDoctrine()->getRepository(Post::class)->findBy(["type_page_ref"=>"activite","id_secteur"=> $secteur->getId()]);
  115.             if($page_ref_activite_primaire){
  116.                 foreach ($page_ref_activite_primaire as $value) {
  117.                     $resultats [] = ['titre'=> $value->translate($_locale)->getTitle(),
  118.                                      'slug'=> $value->translate($_locale)->getSlug(),
  119.                                      'type'=> 'activite_primaire'];
  120.                 }
  121.             }
  122.             $page_ref_activite_secondaire $this->getDoctrine()->getRepository(Post::class)->findBy(["type_page_ref"=>"activite_secondaire","id_secteur"=> $secteur->getId()]);
  123.             if($page_ref_activite_secondaire){
  124.                 foreach ($page_ref_activite_secondaire as $value) {
  125.                     $resultats [] = ['titre'=> $value->translate($_locale)->getTitle(),
  126.                                      'slug'=> $value->translate($_locale)->getSlug(),
  127.                                      'type'=> 'activite_secondaire'];
  128.                 }
  129.             }
  130.             $page_ref_article $this->getDoctrine()->getRepository(Post::class)->findBy(["type_page_ref"=> null,"id_secteur"=> $secteur->getId()]);
  131.             if($page_ref_article){
  132.                 foreach ($page_ref_article as $value) {
  133.                     $resultats [] = ['titre'=> $value->translate($_locale)->getTitle(),
  134.                                      'slug'=> $value->translate($_locale)->getSlug(),
  135.                                      'type'=> 'article'];
  136.                 }
  137.             }
  138.         }else{
  139.             throw new NotFoundHttpException('Sorry not existing!');
  140.         }
  141.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  142.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  143.         $schemaOrg = new Graph();
  144.         $breadcrumb = [];
  145.         $schema_breadcrumb_items = [];
  146.         
  147.         $breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
  148.         $schema_breadcrumb_items[] = Schema::ListItem()
  149.                                      ->position(1)
  150.                                      ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  151.         
  152.         $breadcrumb [] = ['url'=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Localités','active'=> true];
  153.         $schema_breadcrumb_items[] = Schema::ListItem()
  154.                                     ->position(2)
  155.                                     ->item(["@id"=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Localités']);
  156.         $title_breadcrumb_secteur $secteur->translate($_locale)->getBreadcrumb() ? $secteur->translate($_locale)->getBreadcrumb() : $secteur->translate($_locale)->getTitreSecteur();
  157.         $breadcrumb [] = ['url'=> $this->generateUrl('page_details_localite', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL),
  158.                           "name"=> $title_breadcrumb_secteur,'active'=> false];
  159.         $schema_breadcrumb_items[] = Schema::ListItem()
  160.                                     ->position(3)
  161.                                     ->item(["@id"=> $this->generateUrl('page_details_localite', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL),
  162.                                     "name"=> $title_breadcrumb_secteur]);
  163.                       
  164.         $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  165.         $meta_tags $this->refMetaTagsService->generateMetaPage($secteur,'secteur');
  166.         if ($meta_tags) {
  167.             $this->basicSeo->setTitle($meta_tags['title'])
  168.                            ->setDescription($meta_tags['description']);
  169.         }
  170.         return $this->render('front/'.$this->theme.'/localite_details.html.twig',[
  171.             'secteur'=> $secteur,
  172.             'resultats'=> $resultats,
  173.             'breadcrumb'=> $breadcrumb,
  174.             'schemaOrg'=> $schemaOrg,
  175.         ]);
  176.     }
  177. }