<?php
namespace App\Controller\Front;
use App\Entity\Menu;
use App\Entity\Post;
use App\Entity\UrlRef;
use App\Entity\UrlPost;
use App\Entity\Category;
use App\Entity\Language;
use App\Entity\ListeRef;
use App\Entity\MediaCms;
use App\Entity\Secteurs;
use App\Entity\TypePost;
use App\Entity\Activites;
use App\Entity\ListeMenu;
use App\Service\BuildTree;
use App\Entity\CpPostField;
use App\Entity\PostArchive;
use App\Service\RenderBloc;
use Spatie\SchemaOrg\Graph;
use App\Entity\ParametreRef;
use App\Entity\PostCategory;
use App\Service\MetaService;
use Spatie\SchemaOrg\Schema;
use App\Entity\ModelGallerie;
use App\Entity\ParametreSite;
use App\Entity\ReseauSociaux;
use App\Service\MetaClePageRef;
use App\Service\FunctionService;
use App\Entity\ActiviteSecondaire;
use App\Service\RefMetaTagsService;
use App\Service\MetaWithoutCategoryService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Leogout\Bundle\SeoBundle\Seo\Og\OgSeoGenerator;
use Symfony\Component\String\Slugger\SluggerInterface;
use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class PageController extends AbstractController
{
public $basicSeo;
public $seo;
private $slugger;
private $projectDir;
private $metaService;
private $metaClePageRef;
private $renderBloc;
private $buildTree;
private $functionService;
private $metaPostService;
private $theme;
private $refMetaTagsService;
public function __construct(string $projectDir,string $theme,
BasicSeoGenerator $basicSeo,
OgSeoGenerator $seo,
RenderBloc $renderBloc,
RefMetaTagsService $refMetaTagsService,
SluggerInterface $slugger,
BuildTree $buildTree,
MetaService $metaService,
MetaWithoutCategoryService $metaPostService,
MetaClePageRef $metaClePageRef,
FunctionService $functionService){
$this->metaService = $metaService;
$this->metaPostService = $metaPostService;
$this->basicSeo = $basicSeo;
$this->seo = $seo;
$this->buildTree = $buildTree;
$this->slugger = $slugger;
$this->metaClePageRef = $metaClePageRef;
$this->functionService = $functionService;
$this->refMetaTagsService = $refMetaTagsService;
$this->renderBloc = $renderBloc;
$this->projectDir = $projectDir;
$this->theme = $theme;
}
/**
* @Route("/{slug}/{page<[1-9]\d*>}", name="page")
*/
public function Page(Request $request,$slug,$page = 1)
{
$slug_info = $this->getDoctrine()->getRepository(UrlPost::class)->findUrlBySlug($slug);
if(!$slug_info){
throw new NotFoundHttpException('Sorry not existing!');
}
dump($slug_info->getType());
if($slug_info->getType() === "Post"){
$this->MetaModulePostOrCategory($request,$slug,$slug_info);
$post = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug($slug);
if($post == null){
throw new NotFoundHttpException('Sorry not existing!');
}
if ($post->getTypePageRef() != null) {
$render = $this->pageRef($request,$slug);
}else{
$render = $this->pagePost($request,$slug);
}
}elseif ($slug_info->getType() === "Categorie"){
$this->MetaModulePostOrCategory($request,$slug,$slug_info);
$render = $this->pageCatgorie($request,$slug,$page);
}elseif($slug_info->getType() === "Activite"){
$render = $this->pageActivite($request,$slug,$slug_info);
}elseif($slug_info->getType() === "Activite_Secteur"){
$render = $this->pageActiviteSecteur($request,$slug,$slug_info);
}elseif($slug_info->getType() === "Activite_Secondaire"){
$render = $this->pageActiviteSecondaire($request,$slug,$slug_info);
}
return $render;
}
public function pageRef($request,$slug){
$schemaOrg = new Graph();
$_locale = $request->getLocale();
$post = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug($slug);
$home = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
$modele_galerie_choisie = $post->getModeleGallerie() ? $post->getModeleGallerie()->getId() : 1;
$modele_gallerie = $this->getDoctrine()->getRepository(ModelGallerie::class)->findById($modele_galerie_choisie);
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$seo_image = '';
$url = $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
if ($this->functionService->parametreGenerale()) {
if ($this->functionService->parametreGenerale()->getApercuImageLien()) {
$seo_image = $baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getApercuImageLien();
}
}
$galleries_images = [];
$bloc_post = $this->renderBloc->RenderBloc($post,$schemaOrg);
$module = $post->getTypePost()->getSystemName();
$galleries = $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'media');
if($galleries){
foreach ($galleries as $value) {
$extension_file = pathinfo($value->getFileName(), PATHINFO_EXTENSION);
$new_galleries_images = ['id'=> $value->getId(),
'path'=> '',
'lienexterne' => $value->getLienExterne(),
'titre'=> $value->translate($_locale)->getTitre(),
'description'=> $value->translate($_locale)->getDescription(),
'extension_file' => $extension_file
];
if($extension_file != 'mp4'){
// On récupère le nom de fichier sans son extension
$nom_sans_extension = pathinfo($value->getFileName(), PATHINFO_FILENAME);
// On modifie l'extension du fichier
$nouvelle_extension = 'webp';
$nouveau_nom_fichier = $nom_sans_extension . '.' . $nouvelle_extension;
$new_galleries_images['path'] = 'storage/galleries/'.$nouveau_nom_fichier;
}else{
$new_galleries_images['path'] = 'uploads/media/'.$value->getFileName();
}
$galleries_images[] = $new_galleries_images;
}
}
$docs = $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'doc');
$ListId = [];
if($post->getPostCategory()){
foreach($post->getPostCategory() as $value){
$ListId[]= $value->getCategory()->getId();
}
}
$categorieTree = null;
if (!empty($ListId)) {
$categories = $this->getDoctrine()->getRepository(Category::class)->findCategoriePost($ListId);
$categorieTree = $this->functionService->buildTree($categories);
}
$meta_robots = $post->getMetaRobots();
$custom_schemaOrg = null;
if ($post->translate($_locale)->getSchema() != '') {
$custom_schemaOrg = $post->translate($_locale)->getSchema();
}
$title_home_ariane = $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
$breadcrumb_item = 1;
$breadcrumb = [];
$schema_breadcrumb_items = [];
$title_post_ariane = $post->translate($_locale)->getBreadcrumb() ? $post->translate($_locale)->getBreadcrumb() : $post->translate($_locale)->getTitle();
$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_item = 1;
if ($post->getIdActivite() != null) {
$breadcrumb_item = $breadcrumb_item + 1;
$activite = $this->getDoctrine()->getRepository(Activites::class)->find($post->getIdActivite());
if($activite){
$title_breadcrumb_activite_primaire = $activite->translate($_locale)->getBreadcrumb() ? $activite->translate($_locale)->getBreadcrumb() : $activite->translate($_locale)->getTitreActivite();
$breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=> $activite->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
'name'=> $title_breadcrumb_activite_primaire,'active'=> true];
$schema_breadcrumb_items[] = Schema::ListItem()
->position($breadcrumb_item)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $activite->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
"name"=> $title_breadcrumb_activite_primaire]);
}
}
if ($post->getIdSousActivite() != null) {
$breadcrumb_item = $breadcrumb_item + 1;
$activite_secondaire = $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->find($post->getIdSousActivite());
if($activite_secondaire){
$title_breadcrumb_activite_secondaire = $activite_secondaire->translate($_locale)->getBreadcrumb() ? $activite_secondaire->translate($_locale)->getBreadcrumb() : $activite_secondaire->translate($_locale)->getTitreActiviteSecondaire();
$breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=> $activite_secondaire->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
'name'=> $title_breadcrumb_activite_secondaire,'active'=> true];
$schema_breadcrumb_items[] = Schema::ListItem()
->position($breadcrumb_item)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $activite_secondaire->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
"name"=> $title_breadcrumb_activite_secondaire]);
}
}
$breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),
'name'=> $post->translate($_locale)->getTitle(),'active'=> false];
$schema_breadcrumb_items[] = Schema::ListItem()
->position($breadcrumb_item + 1)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=>$title_post_ariane]);
if ($schema_breadcrumb_items) {
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
}
$schemaOrg->add(Schema::Article()->headline($title_post_ariane)
->datePublished($post->getDatePublication()?$post->getDatePublication():$post->getCreatedAt())
->dateModified($post->getUpdatedAt())
->image($post->getImage()!= null?$baseurl.$post->getImage():'')
->publisher(Schema::Organization()
->name($this->functionService->parametreGenerale()?$this->functionService->parametreGenerale()->translate($_locale)->getTitre():'')
->logo($this->functionService->parametreGenerale()?$baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getImage():''))
->mainEntityOfPage(Schema::WebPage()->url($url))
);
$url_social = [];
$social = $this->getDoctrine()->getRepository(ReseauSociaux::class)->findAll();
if($social){
foreach ($social as $value) {
$url_social[] = $value->getUrl();
}
}
// id categorie related with post
$categoiesPosts = $this->getDoctrine()->getRepository(PostCategory::class)->findCategorieByPost($post->getId());
$next_article = $this->getDoctrine()->getRepository(Post::class)->findPostPrevOrNext($categoiesPosts,$post->getId());
$prev_article = $this->getDoctrine()->getRepository(Post::class)->findPostPrevOrNext($categoiesPosts,$post->getId(),'prev');
$template_model_galerie = $modele_gallerie[0]->getTwig();
$parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
$secteur = $this->getDoctrine()->getRepository(Secteurs::class)->find($post->getIdSecteur());
$actualite_ref = $this->getDoctrine()->getRepository(Post::class)->findPostByIdSecteur($post->getId(),$post->getIdActivite(),$post->getIdSecteur());
$template = $this->render('front/'.$this->theme.'/page_ref.html.twig',[
'post'=> $post,
'secteur'=> $secteur,
'title_home_ariane' => $title_home_ariane,
'galleries'=> $galleries_images,
'docs'=> $docs,
'blocs'=> $bloc_post,
'meta_robots'=> $meta_robots,
'schemaOrg'=> $schemaOrg,
'custom_schemaOrg'=> $custom_schemaOrg,
'parametre'=> $parametre,
'next_article'=> $next_article,
'prev_article'=> $prev_article,
'modele_galerie' => $modele_gallerie,
'template_model_gallerie' => $template_model_galerie,
'actualite_ref'=> $actualite_ref,
'breadcrumb'=> $breadcrumb
]);
return $template;
}
public function pagePost($request,$slug){
$schemaOrg = new Graph();
$_locale = $request->getLocale();
$post = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug($slug);
$home = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
$modele_galerie_choisie = $post->getModeleGallerie() ? $post->getModeleGallerie()->getId() : 1;
$modele_gallerie = $this->getDoctrine()->getRepository(ModelGallerie::class)->findById($modele_galerie_choisie);
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$seo_image = '';
$url = $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
if ($this->functionService->parametreGenerale()) {
if ($this->functionService->parametreGenerale()->getApercuImageLien()) {
$seo_image = $baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getApercuImageLien();
}
}
$galleries_images = [];
$bloc_post = $this->renderBloc->RenderBloc($post,$schemaOrg);
$module = $post->getTypePost()->getSystemName();
$galleries = $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'media');
if($galleries){
foreach ($galleries as $value) {
$extension_file = pathinfo($value->getFileName(), PATHINFO_EXTENSION);
$new_galleries_images = ['id'=> $value->getId(),
'path'=> '',
'lienexterne' => $value->getLienExterne(),
'titre'=> $value->translate($_locale)->getTitre(),
'description'=> $value->translate($_locale)->getDescription(),
'extension_file' => $extension_file
];
if($extension_file != 'mp4'){
// On récupère le nom de fichier sans son extension
$nom_sans_extension = pathinfo($value->getFileName(), PATHINFO_FILENAME);
// On modifie l'extension du fichier
$nouvelle_extension = 'webp';
$nouveau_nom_fichier = $nom_sans_extension . '.' . $nouvelle_extension;
$new_galleries_images['path'] = 'storage/galleries/'.$nouveau_nom_fichier;
}else{
$new_galleries_images['path'] = 'uploads/media/'.$value->getFileName();
}
$galleries_images[] = $new_galleries_images;
}
}
$docs = $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'doc');
$ListId = [];
if($post->getPostCategory()){
foreach($post->getPostCategory() as $value){
$ListId[]= $value->getCategory()->getId();
}
}
$categorieTree = null;
if (!empty($ListId)) {
$categories = $this->getDoctrine()->getRepository(Category::class)->findCategoriePost($ListId);
$categorieTree = $this->functionService->buildTree($categories);
}
$meta_robots = $post->getMetaRobots();
$custom_schemaOrg = null;
if ($post->translate($_locale)->getSchema() != '') {
$custom_schemaOrg = $post->translate($_locale)->getSchema();
}
$title_home_ariane = $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
$breadcrumb_item = 1;
$schema_breadcrumb_items = [];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(1)
->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=>$title_home_ariane]);
if($categorieTree){
foreach ($categorieTree as $value) {
$breadcrumb_item = $breadcrumb_item + 1;
$schema_breadcrumb_items[] = Schema::ListItem()
->position($breadcrumb_item)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $value['slug']], UrlGeneratorInterface::ABSOLUTE_URL),"name"=>$value['titre']]);
}
}
$title_post_ariane = $post->translate($_locale)->getBreadcrumb() ? $post->translate($_locale)->getBreadcrumb() : $post->translate($_locale)->getTitle();
$schema_breadcrumb_items[] = Schema::ListItem()
->position($breadcrumb_item + 1)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $post->translate($_locale)->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=>$title_post_ariane]);
if ($schema_breadcrumb_items) {
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
}
$schemaOrg->add(Schema::Article()->headline($title_post_ariane)
->datePublished($post->getDatePublication()?$post->getDatePublication():$post->getCreatedAt())
->dateModified($post->getUpdatedAt())
->image($post->getImage()!= null?$baseurl.$post->getImage():'')
->publisher(Schema::Organization()
->name($this->functionService->parametreGenerale()?$this->functionService->parametreGenerale()->translate($_locale)->getTitre():'')
->logo($this->functionService->parametreGenerale()?$baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getImage():''))
->mainEntityOfPage(Schema::WebPage()->url($url))
);
$url_social = [];
$social = $this->getDoctrine()->getRepository(ReseauSociaux::class)->findAll();
if($social){
foreach ($social as $value) {
$url_social[] = $value->getUrl();
}
}
// id categorie related with post
$categoiesPosts = $this->getDoctrine()->getRepository(PostCategory::class)->findCategorieByPost($post->getId());
$next_article = $this->getDoctrine()->getRepository(Post::class)->findPostPrevOrNext($categoiesPosts,$post->getId());
$prev_article = $this->getDoctrine()->getRepository(Post::class)->findPostPrevOrNext($categoiesPosts,$post->getId(),'prev');
$template_model_galerie = $modele_gallerie[0]->getTwig();
$parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
if($post->getTemplateCms()){
$template = $this->render('front/'.$this->theme.'/dynamique-page-cms.html.twig',[
'template'=> $post->getTemplateCms()->getTwig(),
'post'=> $post,
'title_home_ariane' => $title_home_ariane,
'galleries'=> $galleries_images,
'bloc_post'=> $bloc_post,
'categorieTree'=> $categorieTree,
'meta_robots'=> $meta_robots,
'schemaOrg'=> $schemaOrg,
'custom_schemaOrg'=> $custom_schemaOrg,
'parametre'=> $parametre,
'next_article'=> $next_article,
'prev_article'=> $prev_article,
'modele_galerie' => $modele_gallerie,
'template_model_gallerie' => $template_model_galerie,
]);
}else{
// Champs personnalisés
$valsChamp = [];
$labelsChamp = [];
$vCpFields = $this->getDoctrine()->getRepository(CpPostField::class)->findBy(['IdPost'=>$post->getId()]);
$labelFiels = "";
if($vCpFields){
foreach ($vCpFields as $vCpField) {
$labelFiels = $vCpField->getCpField()->translate($_locale)->getLabel();
$TypeFiels = $vCpField->getCpField()->translate($_locale)->getType();
//dump($TypeFiels);
$labelsChamp += [
$vCpField->getID()=> $labelFiels
];
if($vCpField){
$valChamp = $vCpField->getLinkValue() ? $vCpField->getLinkValue() : $vCpField->getTextareaValue();
$valsChamp += [
$vCpField->getID()=> $valChamp
];
}
}
}
$template = $this->render('front/'.$this->theme.'/page_cms.html.twig',[
'post'=> $post,
'title_home_ariane' => $title_home_ariane,
'galleries'=> $galleries_images,
'docs'=> $docs,
'blocs'=> $bloc_post,
'categorieTree'=> $categorieTree,
'meta_robots'=> $meta_robots,
'schemaOrg'=> $schemaOrg,
'custom_schemaOrg'=> $custom_schemaOrg,
'champsPersonnalises' => $valsChamp,
'lblchampsPersonnalises' => $labelsChamp,
'parametre'=> $parametre,
'next_article'=> $next_article,
'prev_article'=> $prev_article,
'modele_galerie' => $modele_gallerie,
'template_model_gallerie' => $template_model_galerie,
]);
}
return $template;
}
public function pageCatgorie($request,$slug,$page){
$module = 'category';
$resultats = [];
$schemaOrg = new Graph();
$_locale = $request->getLocale();
$categorie = $this->getDoctrine()->getRepository(Category::class)->findCategoryBySlug($slug);
$sousCategorie = $this->getDoctrine()->getRepository(Category::class)->findBy(['parent'=> $categorie->getId()],['order_by'=>'ASC']);
$home = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
$template = $categorie->getTypeAffichageHome();
$bloc_categorie = $this->renderBloc->RenderBloc($categorie,$schemaOrg,'categorie');
// Galleries
$galleries_images = [];
$modele_galerie_choisie = $categorie->getModeleGallerie() ? $categorie->getModeleGallerie()->getId() : 1;
$modele_gallerie = $this->getDoctrine()->getRepository(ModelGallerie::class)->findById($modele_galerie_choisie);
$galleries = $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$categorie->getId(),'media');
if($galleries){
foreach ($galleries as $value) {
$extension_file = pathinfo($value->getFileName(), PATHINFO_EXTENSION);
$new_galleries_images = ['id'=> $value->getId(),
'path'=> '',
'lienexterne' => $value->getLienExterne(),
'titre'=> $value->translate($_locale)->getTitre(),
'description'=> $value->translate($_locale)->getDescription(),
'extension_file' => $extension_file
];
if($extension_file != 'mp4'){
// On récupère le nom de fichier sans son extension
$nom_sans_extension = pathinfo($value->getFileName(), PATHINFO_FILENAME);
// On modifie l'extension du fichier
$nouvelle_extension = 'webp';
$nouveau_nom_fichier = $nom_sans_extension . '.' . $nouvelle_extension;
$new_galleries_images['path'] = 'storage/galleries/'.$nouveau_nom_fichier;
}else{
$new_galleries_images['path'] = 'uploads/media/'.$value->getFileName();
}
$galleries_images[] = $new_galleries_images;
}
}
$template_model_galerie = $modele_gallerie[0]->getTwig();
if ($categorie->getPagination() == true) {
$posts = $this->getDoctrine()->getRepository(Post::class)->findPostByCategory($categorie->getId(),$categorie->getPagination(),$page,$categorie->getPageSize());
if($posts->getResults()){
foreach ($posts->getResults() as $value) {
$resultats[] = [ 'id'=> $value->getId(),
'slug'=> $value->getSlug(),
'titre'=> $value->getTitle(),
'title_affichage'=> $value->getTitleAffichage(),
'content'=> $value->getContent(),
'chapeau'=> $value->getSummary(),
'image'=> $value->getImage(),
'typelien'=> $value->getTypeLien(),
'titrelien'=> $value->getTitreLien(),
'telephone'=> $value->getTelephone(),
'lieninterne'=> $value->getLienInterne(),
'lienexterne'=> $value->getLienExterne(),
];
}
}
}else{
$posts = $this->getDoctrine()->getRepository(Post::class)->findPostByCategory($categorie->getId(),false,$page,$categorie->getPageSize());
if($posts){
foreach ($posts as $value) {
// Champs personnalisés
$valsChamp = [];
$vCpFields = $this->getDoctrine()->getRepository(CpPostField::class)->findBy(['IdPost'=>$value->getId()]);
if($vCpFields){
foreach ($vCpFields as $vCpField) {
if($vCpField){
$valChamp = $vCpField->getLinkValue() ? $vCpField->getLinkValue() : $vCpField->getTextareaValue();
$valsChamp += [
$vCpField->getID()=> $valChamp
];
}
}
}
$resultats[] = [ 'id'=> $value->getId(),
'slug'=> $value->getSlug(),
'titre'=> $value->getTitle(),
'title_affichage'=> $value->getTitleAffichage(),
'content'=> $value->getContent(),
'chapeau'=> $value->getSummary(),
'image'=> $value->getImage(),
'typelien'=> $value->getTypeLien(),
'titrelien'=> $value->getTitreLien(),
'telephone'=> $value->getTelephone(),
'lieninterne'=> $value->getLienInterne(),
'lienexterne'=> $value->getLienExterne(),
'champsPersonnalises' => $valsChamp,
];
}
}
}
$title_home_ariane = $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
$meta_robots = $categorie->getMetaRobots();
$schema_breadcrumb_items = [];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(1)
->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
$schema_breadcrumb_items[] = Schema::ListItem()
->position(2)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $categorie->translate($_locale)->getSlugUrl()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $categorie->translate($_locale)->getTitreCategorie()]);
if ($schema_breadcrumb_items) {
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
}
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$schemaOrg->add(Schema::Article()
->headline($categorie->translate($_locale)->getTitreCategorie())
->datePublished($categorie->getCreatedAt())
->dateModified($categorie->getUpdatedAt())
->image($categorie->getImage()!= null?$baseurl.$categorie->getImage():'')
->publisher(Schema::Organization()
->name($this->functionService->parametreGenerale()?$this->functionService->parametreGenerale()->translate($_locale)->getTitre():'')
->logo($this->functionService->parametreGenerale()?$baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getImage():''))
->mainEntityOfPage(Schema::WebPage()->url($this->generateUrl('page', ['slug'=> $categorie->translate($_locale)->getSlugUrl()], UrlGeneratorInterface::ABSOLUTE_URL)))
);
$module = $categorie->getTypePost()->translate($_locale)->getSystemName();
$galleries = $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$categorie->getId(),'media');
$docs = $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$categorie->getId(),'doc');
$parametre = $this->functionService->parametreGenerale();
return $this->render('front/'.$this->theme.'/page_categorie.html.twig',[
'template'=> $template,
'title_home_ariane' => $title_home_ariane,
'categorie'=> $categorie,
'resultats'=> $resultats,
'blocs'=> $bloc_categorie,
'posts'=> $posts,
'meta_robots'=> $meta_robots,
'pagination'=> $categorie->getPagination(),
'schemaOrg'=> $schemaOrg,
'galleries'=> $galleries_images,
'docs'=> $docs,
'parametre'=> $parametre,
'modele_galerie' => $modele_gallerie,
'template_model_gallerie' => $template_model_galerie,
]);
}
public function pageActivite($request,$slug,$slug_info){
$_locale = $request->getLocale();
$activite = $this->getDoctrine()->getRepository(Activites::class)->findActiviteBySlug($slug);
$titre = $activite->translate($_locale)->getTitre();
$titre_activite = $activite->translate($_locale)->getTitreActivite();
$texte = $activite->translate($_locale)->getTextActivitePrincipalFinal();
$meta_tags = $this->metaService->generateMetaPage($activite,'activite');
if ($meta_tags) {
$this->basicSeo->setTitle($meta_tags['title'])
->setDescription($meta_tags['description']);
}
$secteurs = [];
$all_secteurs = $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=> true]);
if ($all_secteurs) {
foreach ($all_secteurs as $secteur) {
if(in_array($activite->getId(),explode(',',$secteur->getActivitePrimaireIds()))){
$secteurs[] = $secteur;
}
}
}
$medias = $this->getDoctrine()->getRepository(MediaCms::class)->findBy(['module'=>'Activite','module_id'=>$activite->getId()]);
$ref_pages = $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdActivite($activite->getId());
$actualites = $this->getDoctrine()->getRepository(Post::class)->findPageClientByIdActiviteOrSousActivite($activite->getId());
$parametre = $this->functionService->parametreGenerale();
$home = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
$title_home_ariane = $home->translate($_locale)->getBreadcrumb() ? $home->translate($_locale)->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]);
$title_breadcrumb_activite = $activite->translate($_locale)->getBreadcrumb() ? $activite->translate($_locale)->getBreadcrumb() : $titre_activite;
$breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=> $activite->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_breadcrumb_activite,'active'=> false];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(2)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $activite->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_breadcrumb_activite]);
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
$meta_tags = $this->refMetaTagsService->generateMetaPage($activite,'activite');
if ($meta_tags) {
$this->basicSeo->setTitle($meta_tags['title'])
->setDescription($meta_tags['description']);
}
$template = $this->render('front/'.$this->theme.'/page_activite.html.twig',[
'titre'=> $titre,
'texte'=> $texte,
'titre_activite'=> $titre_activite,
'slug'=> $slug,
'medias'=> $medias,
'ref_pages'=> $ref_pages,
'actualites'=> $actualites,
'parametre'=> $parametre,
'secteurs'=> $secteurs,
'breadcrumb'=> $breadcrumb,
'schemaOrg'=> $schemaOrg,
]);
return $template;
}
public function pageActiviteSecteur($request,$slug,$slug_info){
$_locale = $request->getLocale();
$activite_primaire_titre = null;
$activite_primaire_slug = null;
$activite_secondaire_titre = null;
$activite_secondaire_slug = null;
$activite_secteur = $this->getDoctrine()->getRepository(ListeRef::class)->findActiviteSecteurBySlug($slug);
if ($activite_secteur) {
if ($activite_secteur->getType() == 'activite_primaire') {
$activite = $this->getDoctrine()->getRepository(Activites::class)->findOneBy(['actif'=>true,'id'=>$activite_secteur->getIdActivite()]);
if($activite){
$activite_primaire_titre = $activite->translate($_locale)->getTitreActivite();
$activite_primaire_slug = $activite->translate($_locale)->getLibelleUrl();
}
}else{
$activite_secondaire = $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->findOneBy(['actif'=>true,'id'=>$activite_secteur->getIdActivite()]);
if ($activite_secondaire) {
$activite_secondaire_titre = $activite_secondaire->translate($_locale)->getTitreActiviteSecondaire();
$activite_secondaire_slug = $activite_secondaire->translate($_locale)->getLibelleUrl();
}
if ($activite_secondaire->getActivitePrimaire()) {
$activite_primaire_titre = $activite_secondaire->getActivitePrimaire()->translate($_locale)->getTitreActivite();
$activite_primaire_slug = $activite_secondaire->getActivitePrimaire()->translate($_locale)->getLibelleUrl();
}
}
}
$meta_tags = $this->metaService->generateMetaPage($activite_secteur,'activite_secteur');
if ($meta_tags) {
$this->basicSeo->setTitle($meta_tags['title'])
->setDescription($meta_tags['description']);
}
$template = $this->render('front/'.$this->theme.'/page_activite_secteur.html.twig',[
'activite_secteur'=> $activite_secteur,
'slug'=> $slug,
'activite_primaire_titre'=> $activite_primaire_titre,
'activite_primaire_slug'=> $activite_primaire_slug,
'activite_secondaire_titre'=> $activite_secondaire_titre,
'activite_secondaire_slug'=> $activite_secondaire_slug,
]);
return $template;
}
public function pageActiviteSecondaire($request,$slug,$slug_info){
$_locale = $request->getLocale();
$activite_primaire_titre = null;
$activite_primaire_slug = null;
$activite_secondaire = $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->findActiviteBySlug($slug);
if ($activite_secondaire->getActivitePrimaire()) {
$activite_primaire_titre = $activite_secondaire->getActivitePrimaire()->translate($_locale)->getTitreActivite();
$activite_primaire_slug = $activite_secondaire->getActivitePrimaire()->translate($_locale)->getLibelleUrl();
}
$titre = $activite_secondaire->translate($_locale)->getTitre();
$titre_activite = $activite_secondaire->translate($_locale)->getTitreActiviteSecondaire();
$texte = $activite_secondaire->translate($_locale)->getTextActiviteSecondaireFinal();
$meta_tags = $this->refMetaTagsService->generateMetaPage($activite_secondaire,'activite_secondaire');
if ($meta_tags) {
$this->basicSeo->setTitle($meta_tags['title'])
->setDescription($meta_tags['description']);
}
$ref_pages = $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdSousActivite($activite_secondaire->getId());
$actualites = $this->getDoctrine()->getRepository(Post::class)->findPageClientByIdActiviteOrSousActivite($activite_secondaire->getId(),'activite_secondaire');
$parametre = $this->functionService->parametreGenerale();
$secteurs = [];
$all_secteurs = $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=> true]);
if ($all_secteurs) {
foreach ($all_secteurs as $secteur) {
if(in_array($activite_secondaire->getId(),explode(',',$secteur->getActiviteSecondaireIds()))){
$secteurs[] = $secteur;
}
}
}
$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_item = 1;
if ($activite_secondaire->getActivitePrimaire()) {
$breadcrumb_item = $breadcrumb_item + 1;
$activite_primaire = $activite_secondaire->getActivitePrimaire();
$activite_primaire_titre = $activite_primaire->translate($_locale)->getTitreActivite();
$activite_primaire_slug = $activite_primaire->translate($_locale)->getLibelleUrl();
$title_breadcrumb_activite_primaire = $activite_primaire->translate($_locale)->getBreadcrumb() ? $activite_primaire->translate($_locale)->getBreadcrumb() : $activite_primaire_titre;
$breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=> $activite_primaire_slug], UrlGeneratorInterface::ABSOLUTE_URL),
"name"=> $title_breadcrumb_activite_primaire,'active'=> true];
$schema_breadcrumb_items[] = Schema::ListItem()
->position($breadcrumb_item)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $activite_primaire_slug], UrlGeneratorInterface::ABSOLUTE_URL),
"name"=> $title_breadcrumb_activite_primaire]);
}
$title_breadcrumb_activite_secondaire = $activite_secondaire->translate($_locale)->getBreadcrumb() ? $activite_secondaire->translate($_locale)->getBreadcrumb() : $activite_secondaire->translate($_locale)->getTitreActiviteSecondaire();
$breadcrumb [] = ['url'=> $this->generateUrl('page', ['slug'=> $activite_secondaire->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
'name'=> $title_breadcrumb_activite_secondaire,'active'=> false];
$schema_breadcrumb_items[] = Schema::ListItem()
->position($breadcrumb_item + 1)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $activite_secondaire->translate($_locale)->getLibelleUrl()], UrlGeneratorInterface::ABSOLUTE_URL),
"name"=> $title_breadcrumb_activite_secondaire]);
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
$template = $this->render('front/'.$this->theme.'/page_activite_secondaire.html.twig',[
'titre'=> $titre,
'texte'=> $texte,
'titre_activite'=>$titre_activite,
'activite_primaire_titre'=> $activite_primaire_titre,
'activite_primaire_slug'=> $activite_primaire_slug,
'slug'=> $slug,
'schemaOrg'=> $schemaOrg,
'ref_pages'=> $ref_pages,
'actualites'=> $actualites,
'parametre'=> $parametre,
'secteurs'=> $secteurs,
'breadcrumb'=> $breadcrumb
]);
return $template;
}
function MetaModulePostOrCategory($request,$slug,$slug_info){
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$url = $this->generateUrl('page', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL);
// $metaService = $this->metaService->meta($slug,$slug_info->getType());
$title_seo = isset($metaService['title'])?$metaService['title']:null;
$description_seo = isset($metaService['description'])?$metaService['description']:null;
$metacle = isset($metaService['metacle'])?$metaService['metacle']:null;
if($title_seo != '' || $description_seo != ''){
$this->basicSeo->setTitle($title_seo)
->setDescription($description_seo)
->setkeywords($metacle);
$this->seo->setTitle($title_seo)
->setDescription($description_seo)
->setUrl($url);
if ($this->functionService->parametreGenerale()) {
if ($this->functionService->parametreGenerale()->getApercuImageLien()) {
$this->seo->setImage($baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getApercuImageLien());
}
}
}
}
}