src/Controller/Front/LocaliteController.php line 62

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\Language;
  8. use App\Entity\ListeRef;
  9. use App\Entity\Secteurs;
  10. use App\Entity\GroupBloc;
  11. use App\Entity\ListeMenu;
  12. use App\Service\BuildTree;
  13. use Spatie\SchemaOrg\Graph;
  14. use App\Entity\ParamContact;
  15. use App\Entity\ParametreRef;
  16. use App\Entity\ThemeOptions;
  17. use Spatie\SchemaOrg\Schema;
  18. use App\Entity\ParametreSite;
  19. use App\Entity\ProduitOption;
  20. use App\Entity\ReseauSociaux;
  21. use App\Entity\TextParametrable;
  22. use App\Service\FunctionService;
  23. use App\Entity\CategoriesProduct;
  24. use App\Service\RenderDefaultBloc;
  25. use App\Service\RefMetaTagsService;
  26. use App\Entity\TextParametrableTranslation;
  27. use Symfony\Component\Filesystem\Filesystem;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpFoundation\Response;
  30. use Symfony\Component\Routing\Annotation\Route;
  31. use Symfony\Contracts\HttpClient\HttpClientInterface;
  32. use Symfony\Component\Translation\TranslatorInterface;
  33. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  34. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  35. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  36. class LocaliteController  extends AbstractController
  37. {
  38.     private $functionService;
  39.     private $refMetaTagsService;
  40.     public function __construct(string $themeRefMetaTagsService $refMetaTagsService,HttpClientInterface $client,string $projectDirr,FunctionService $functionService)
  41.     {
  42.         $this->theme $theme;
  43.         $this->client $client;
  44.         $this->projectDirr $projectDirr;
  45.         $this->functionService $functionService;
  46.         $this->refMetaTagsService $refMetaTagsService;
  47.         
  48.     }
  49.     /**
  50.      * @Route("/localites", name="page_localite", options={"sitemap" = true},priority=10)
  51.      */
  52.     public function index(Request $request)
  53.     {
  54.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  55.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  56.         $schemaOrg = new Graph();
  57.         $breadcrumb = [];
  58.         $schema_breadcrumb_items = [];
  59.         
  60.         $breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
  61.         $schema_breadcrumb_items[] = Schema::ListItem()
  62.                                      ->position(1)
  63.                                      ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  64.         
  65.         $breadcrumb [] = ['url'=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Localités','active'=> false];
  66.         $schema_breadcrumb_items[] = Schema::ListItem()
  67.                                     ->position(2)
  68.                                     ->item(["@id"=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Localités']);
  69.                       
  70.         $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  71.         $secteurs $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=> true]);
  72.         $parametre $this->functionService->parametreGenerale();
  73.         return $this->render('front/'.$this->theme.'/localite.html.twig',[
  74.             'secteurs'=> $secteurs,
  75.             'parametre'=> $parametre,
  76.             'breadcrumb'=> $breadcrumb,
  77.             'schemaOrg'=> $schemaOrg,
  78.         ]);
  79.     }
  80.     /**
  81.      * @Route("/localite/{slug}", name="page_details_localite", options={"sitemap" = true},priority=10)
  82.      */
  83.     public function detialsLocalite(Request $request,$slug)
  84.     {
  85.         $_locale $request->getLocale();
  86.         $resultats = [];
  87.         $secteur $this->getDoctrine()->getRepository(Secteurs::class)->findSecteurBySlug($slug);
  88.         if ($secteur) {
  89.             $posts $this->getDoctrine()->getRepository(Post::class)->findBy(['id_secteur'=> $secteur->getId()]);
  90.             if($posts){
  91.                 foreach ($posts as $post_item) {
  92.                    $resultats [] = ['titre'=> $post_item->translate($_locale)->getTitle(),
  93.                                     'slug'=> $post_item->translate($_locale)->getSlug(),
  94.                                     'type'=> 'article',
  95.                                    ];
  96.                 }
  97.             }
  98.             $pages $this->getDoctrine()->getRepository(ListeRef::class)->findBy(['id_secteur'=> $secteur->getId()]);
  99.             if ($pages) {
  100.                 foreach ($pages as $value) {
  101.                     $resultats [] = ['titre'=> $value->translate($_locale)->gettitrelisteref(),
  102.                                     'slug'=> $value->translate($_locale)->getSlug(),
  103.                                     'type'=> $value->getType()];
  104.                 }
  105.             }
  106.         }
  107.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  108.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  109.         $schemaOrg = new Graph();
  110.         $breadcrumb = [];
  111.         $schema_breadcrumb_items = [];
  112.         
  113.         $breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
  114.         $schema_breadcrumb_items[] = Schema::ListItem()
  115.                                      ->position(1)
  116.                                      ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  117.         
  118.         $breadcrumb [] = ['url'=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Localités','active'=> true];
  119.         $schema_breadcrumb_items[] = Schema::ListItem()
  120.                                     ->position(2)
  121.                                     ->item(["@id"=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Localités']);
  122.         $title_breadcrumb_secteur $secteur->translate($_locale)->getBreadcrumb() ? $secteur->translate($_locale)->getBreadcrumb() : $secteur->translate($_locale)->getTitre();
  123.         $breadcrumb [] = ['url'=> $this->generateUrl('page_details_localite', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL),
  124.                           "name"=> $title_breadcrumb_secteur,'active'=> false];
  125.         $schema_breadcrumb_items[] = Schema::ListItem()
  126.                                     ->position(3)
  127.                                     ->item(["@id"=> $this->generateUrl('page_details_localite', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL),
  128.                                     "name"=> $title_breadcrumb_secteur]);
  129.                       
  130.         $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  131.         $meta_tags $this->refMetaTagsService->generateMetaPage($secteur,'secteur');
  132.         if ($meta_tags) {
  133.             $this->basicSeo->setTitle($meta_tags['title'])
  134.                            ->setDescription($meta_tags['description']);
  135.         }
  136.         return $this->render('front/'.$this->theme.'/localite_details.html.twig',[
  137.             'secteur'=> $secteur,
  138.             'resultats'=> $resultats,
  139.             'breadcrumb'=> $breadcrumb,
  140.             'schemaOrg'=> $schemaOrg,
  141.         ]);
  142.     }
  143. }