<?php
namespace App\Controller\Front;
use App\Entity\Menu;
use App\Entity\Post;
use App\Entity\Contact;
use App\Entity\Country;
use App\Entity\UrlPost;
use App\Entity\Language;
use App\Entity\ListeRef;
use App\Entity\Secteurs;
use App\Entity\GroupBloc;
use App\Entity\ListeMenu;
use App\Service\BuildTree;
use Spatie\SchemaOrg\Graph;
use App\Entity\ParamContact;
use App\Entity\ParametreRef;
use App\Entity\ThemeOptions;
use App\Service\MetaService;
use Spatie\SchemaOrg\Schema;
use App\Entity\ParametreSite;
use App\Entity\ProduitOption;
use App\Entity\ReseauSociaux;
use App\Entity\TextParametrable;
use App\Service\FunctionService;
use App\Entity\CategoriesProduct;
use App\Service\RenderDefaultBloc;
use App\Service\RefMetaTagsService;
use App\Entity\TextParametrableTranslation;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class LocaliteController extends AbstractController
{
private $functionService;
private $refMetaTagsService;
public $basicSeo;
public $metaService;
public function __construct(string $theme,MetaService $metaService,BasicSeoGenerator $basicSeo, RefMetaTagsService $refMetaTagsService,HttpClientInterface $client,string $projectDirr,FunctionService $functionService)
{
$this->theme = $theme;
$this->client = $client;
$this->projectDirr = $projectDirr;
$this->functionService = $functionService;
$this->refMetaTagsService = $refMetaTagsService;
$this->basicSeo = $basicSeo;
$this->metaService = $metaService;
}
/**
* @Route("/localites", name="page_localite", options={"sitemap" = true},priority=10)
*/
public function index(Request $request)
{
$_locale = $request->getLocale();
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'hub_localite']);
$home = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
$title_home_ariane = $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
$title_page = $parametreRef && $parametreRef->translate($_locale)->getBreadcrumb() ? $parametreRef->translate($_locale)->getBreadcrumb() : "Localités";
$schemaOrg = new Graph();
$breadcrumb = [];
$schema_breadcrumb_items = [];
$breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(1)
->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
$breadcrumb [] = ['url'=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page,'active'=> false];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(2)
->item(["@id"=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page]);
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
$secteurs = $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=> true]);
$parametre = $this->functionService->parametreGenerale();
if ($parametreRef) {
$meta_tags = $this->metaService->generateMetaPage($parametreRef,'hub_localite');
if ($meta_tags) {
$this->basicSeo->setTitle($meta_tags['title'])
->setDescription($meta_tags['description']);
}
}
return $this->render('front/'.$this->theme.'/localite.html.twig',[
'secteurs'=> $secteurs,
'parametre'=> $parametre,
'breadcrumb'=> $breadcrumb,
'schemaOrg'=> $schemaOrg,
'parametreRef'=> $parametreRef,
'title_page'=> $title_page
]);
}
/**
* @Route("/localite/{slug}", name="page_details_localite", options={"sitemap" = false},priority=10)
*/
public function detialsLocalite(Request $request,$slug)
{
$_locale = $request->getLocale();
$resultats = [];
$secteur = $this->getDoctrine()->getRepository(Secteurs::class)->findSecteurBySlug($slug);
if ($secteur) {
$slug_lang = $this->getDoctrine()->getRepository(UrlPost::class)->findLangUrl($slug);
if ($slug_lang['locale'] != $_locale) {
$request->getSession()->set('_locale', $slug_lang['locale']);
return $this->redirectToroute('page_details_localite',['slug'=> $slug]);
}
$page_ref_activite_primaire = $this->getDoctrine()->getRepository(Post::class)->findBy(["type_page_ref"=>"activite","id_secteur"=> $secteur->getId()]);
if($page_ref_activite_primaire){
foreach ($page_ref_activite_primaire as $value) {
$resultats [] = ['titre'=> $value->translate($_locale)->getTitle(),
'slug'=> $value->translate($_locale)->getSlug(),
'type'=> 'activite_primaire'];
}
}
$page_ref_activite_secondaire = $this->getDoctrine()->getRepository(Post::class)->findBy(["type_page_ref"=>"activite_secondaire","id_secteur"=> $secteur->getId()]);
if($page_ref_activite_secondaire){
foreach ($page_ref_activite_secondaire as $value) {
$resultats [] = ['titre'=> $value->translate($_locale)->getTitle(),
'slug'=> $value->translate($_locale)->getSlug(),
'type'=> 'activite_secondaire'];
}
}
$page_ref_article = $this->getDoctrine()->getRepository(Post::class)->findBy(["type_page_ref"=> null,"id_secteur"=> $secteur->getId()]);
if($page_ref_article){
foreach ($page_ref_article as $value) {
$resultats [] = ['titre'=> $value->translate($_locale)->getTitle(),
'slug'=> $value->translate($_locale)->getSlug(),
'type'=> 'article'];
}
}
}else{
throw new NotFoundHttpException('Sorry not existing!');
}
$home = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
$title_home_ariane = $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
$schemaOrg = new Graph();
$breadcrumb = [];
$schema_breadcrumb_items = [];
$breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(1)
->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
$breadcrumb [] = ['url'=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Localités','active'=> true];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(2)
->item(["@id"=> $this->generateUrl('page_localite', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Localités']);
$title_breadcrumb_secteur = $secteur->translate($_locale)->getBreadcrumb() ? $secteur->translate($_locale)->getBreadcrumb() : $secteur->translate($_locale)->getTitreSecteur();
$breadcrumb [] = ['url'=> $this->generateUrl('page_details_localite', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL),
"name"=> $title_breadcrumb_secteur,'active'=> false];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(3)
->item(["@id"=> $this->generateUrl('page_details_localite', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL),
"name"=> $title_breadcrumb_secteur]);
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
$meta_tags = $this->refMetaTagsService->generateMetaPage($secteur,'secteur');
if ($meta_tags) {
$this->basicSeo->setTitle($meta_tags['title'])
->setDescription($meta_tags['description']);
}
return $this->render('front/'.$this->theme.'/localite_details.html.twig',[
'secteur'=> $secteur,
'resultats'=> $resultats,
'breadcrumb'=> $breadcrumb,
'schemaOrg'=> $schemaOrg,
]);
}
}