<?php
namespace App\Controller\Front;
use App\Entity\Menu;
use App\Entity\Post;
use App\Entity\UrlRef;
use App\Entity\CpField;
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\ParametrePost;
use App\Entity\ParametreSite;
use App\Entity\ReseauSociaux;
use App\Service\MetaClePageRef;
use App\Service\FunctionService;
use App\Entity\ActiviteSecondaire;
use Symfony\Component\Intl\Locale;
use App\Service\RefMetaTagsService;
use App\Service\AffichageGallerieService;
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\HttpFoundation\Session\SessionInterface;
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;
private $affichageGallerieService;
protected $session;
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,
AffichageGallerieService $affichageGallerieService,
SessionInterface $session){
$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;
$this->affichageGallerieService = $affichageGallerieService;
$this->session = $session;
}
/**
* @Route("/{slug}", name="page",priority="-1")
*/
public function Page(Request $request,$slug,$page = 1)
{
$_locale = $request->getLocale();
if ($slug == 'home') {
return $this->redirectToRoute('index_page_home');
}
if ($slug == 'contact-envoye' || $slug == 'contact-envoye-devis' || $slug == 'contact-landing-page') {
return $this->pageTraking($request,$slug);
}
if($request->query->get('page')){
$page = $request->query->get('page');
}
$product_interesse = null;
if($request->query->get('product')){
$slug_product = $request->query->get('product');
$product_interesse = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug($slug_product);
}
$annonce_interesse = null;
if($request->query->get('annonce')){
$slug_annonce = $request->query->get('annonce');
$annonce_interesse = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug($slug_annonce);
}
$slug_info = $this->getDoctrine()->getRepository(UrlPost::class)->findUrlBySlug($slug);
if(!$slug_info){
throw new NotFoundHttpException('Sorry not existing!');
}
if ($slug_info) {
$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',['slug'=> $slug]);
}
}
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->getTypePost()->getSystemName() == 'produits') {
$render = $this->pageProduit($request,$slug);
}elseif ($post->getTypePost()->getSystemName() == 'lp') {
$render = $this->pageLanding($request,$slug);
}else{
if ($post->getTypePageRef() != null) {
$render = $this->pageRef($request,$slug);
}else{
$render = $this->pagePost($request,$slug,$product_interesse,$annonce_interesse);
}
}
}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);
}elseif ($slug_info->getType() === "Sous-categorie" || $slug_info->getType() === 'Sous-sous-categorie') {
throw new NotFoundHttpException('Sorry not existing!');
}
return $render;
}
public function pageProduit($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');
$galleries_images = $this->affichageGallerieService->GallerieImages($galleries,$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 [] = ['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();
$categories_tree = [];
$categories_principal = $this->getDoctrine()->getRepository(Category::class)->findBy(['actif'=> true,'parent'=> 0,'sousParent'=> 0,'TypePost'=> $post->getTypePost()]);
if ($categories_principal) {
foreach ($categories_principal as $value) {
$data_slug_sous_categorie = [];
$tree_sous_categorie = $this->getDoctrine()->getRepository(Category::class)->findBy(['actif'=> true,'parent'=> $value->getId()],['order_by'=>'ASC']);
if($tree_sous_categorie){
foreach ($tree_sous_categorie as $sous_categorie_items) {
$data_slug_sous_sous_categorie = [];
$tree_sous_sous_categorie = $this->getDoctrine()->getRepository(Category::class)->findBy(['actif'=> true,'parent'=> 0,'sousParent'=> $sous_categorie_items->getId()],['order_by'=>'ASC']);
if ($tree_sous_sous_categorie) {
foreach ($tree_sous_sous_categorie as $sous_sous_categorie_items) {
$data_slug_sous_sous_categorie[] = [
'id'=> $sous_sous_categorie_items->getId(),
'titre'=> $sous_sous_categorie_items->translate($_locale)->getTitreCategorie(),
'slug'=> $sous_sous_categorie_items->translate($_locale)->getSlugUrl()];
}
}
$data_slug_sous_categorie[] = ['id'=> $sous_categorie_items->getId(),
'titre'=> $sous_categorie_items->translate($_locale)->getTitreCategorie(),
'slug'=> $sous_categorie_items->translate($_locale)->getSlugUrl(),
'sous_sous_categories'=> $data_slug_sous_sous_categorie,
];
}
}
$categories_tree[] = ['id'=> $value->getId(),
'titre'=> $value->translate($_locale)->getTitreCategorie(),
'slug'=> $value->translate($_locale)->getSlugUrl(),
'sous_categories'=> $data_slug_sous_categorie,
];
}
}
$parametre = $this->functionService->parametreGenerale();
$produit_related = null;
// Find product related with default categorie
// if($post->getDefaultCategorie()){
// $canonical = $this->functionService->canonicalUrlProduit($post);
// $produit_related = $this->getDoctrine()->getRepository(Post::class)->findProductRelated($post->getTypePost(),$post->getId(),$post->getDefaultCategorie());
// }else{
// $canonical = $this->functionService->canonicalUrl($post->translate($_locale)->getCanonical());
// }
// Find product related
if ($post->getPostsAssocies()) {
$canonical = $this->functionService->canonicalUrlProduit($post);
foreach (explode(',',$post->getPostsAssocies()) as $id) {
$produit = $this->getDoctrine()->getRepository(Post::class)->find($id);
if ($produit) {
$produit_related[] = $produit;
}
}
}else{
$canonical = $this->functionService->canonicalUrl($post->translate($_locale)->getCanonical());
}
$champsPersonnalisesPost = [];
$champsPersonnalisesPost = $this->functionService->getChampsPersonnalisesPost($post);
$template = $this->render('front/'.$this->theme.'/produits/page_produit.html.twig',[
'post'=> $post,
'produit_related'=> $produit_related,
'canonical'=> $canonical,
'parametre'=> $parametre,
'categories_tree'=> $categories_tree,
'title_home_ariane' => $title_home_ariane,
'galleries'=> $galleries_images,
'docs'=> $docs,
'blocs'=> $bloc_post,
'meta_robots'=> $meta_robots,
'schemaOrg'=> $schemaOrg,
'custom_schemaOrg'=> $custom_schemaOrg,
'next_article'=> $next_article,
'prev_article'=> $prev_article,
'modele_galerie' => $modele_gallerie,
'template_model_gallerie' => $template_model_galerie,
'champsPersonnalisesPost' => $champsPersonnalisesPost,
'breadcrumb'=> $breadcrumb
]);
return $template;
}
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');
$galleries_images = $this->affichageGallerieService->GallerieImages($galleries,$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]);
$titre_activite = null;
$breadcrumb_item = 1;
if ($post->getIdActivite() != null) {
$breadcrumb_item = $breadcrumb_item + 1;
$activite = $this->getDoctrine()->getRepository(Activites::class)->find($post->getIdActivite());
if($activite){
$titre_activite = $activite->translate($_locale)->getTitreActivite();
$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());
$ref_pages = null;
$actualites_liee = [];
if($post->getIdActivite() != null and $post->getIdSousActivite() == null){
$ref_pages = $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdActivite($post->getIdActivite(),$post->getId());
$actualites_liee = $this->getDoctrine()->getRepository(Post::class)->findPageClientByIdActiviteOrSousActivite($post->getIdActivite());
}elseif($post->getIdActivite() != null and $post->getIdSousActivite() != null){
$ref_pages = $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdActiviteAndIdSousActivite($post->getIdActivite(),$post->getIdSousActivite(),$post->getId());
$actualites_liee = $this->getDoctrine()->getRepository(Post::class)->findPageClientByIdActiviteAndSousActivite($post->getIdActivite(),$post->getIdSousActivite());
}
$ref_pages_sous_activite = $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdsSousActiviteAndActivitePrincipal($post->getIdActivite(),$post->getIdSecteur());
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
$canonical = $this->functionService->canonicalUrl($post->translate($_locale)->getCanonical());
$template = $this->render('front/'.$this->theme.'/page_ref.html.twig',[
'post'=> $post,
'canonical'=> $canonical,
'ref_pages'=> $ref_pages,
'titre_activite'=> $titre_activite,
'ref_pages_sous_activite'=> $ref_pages_sous_activite,
'actualites_liee'=> $actualites_liee,
'parametreRef'=> $parametreRef,
'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,
'breadcrumb'=> $breadcrumb
]);
return $template;
}
public function pageLanding($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();
}
}
$bloc_post = $this->renderBloc->RenderBloc($post,$schemaOrg);
return $this->render('front/'.$this->theme.'/landing-page/page.html.twig',[
'blocs'=> $bloc_post,
]);
}
public function pagePost($request,$slug,$product_interesse = null,$annonce_interesse = null){
$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();
}
}
$all_posts_associes = [];
if($post->getPostsAssocies()){
$posts_associes = explode(',',$post->getPostsAssocies());
foreach ($posts_associes as $post_associe){
$all_posts_associes[] = $this->getDoctrine()->getRepository(Post::class)->findPostById($post_associe);
}
}
$all_others_posts_associes = [];
if($post->getPostsAssociesAutresTypes()){
$others_posts_associes = explode(',',$post->getPostsAssociesAutresTypes());
foreach ($others_posts_associes as $other_post_associe){
$all_others_posts_associes[] = $this->getDoctrine()->getRepository(Post::class)->findOneBy(['id' => $other_post_associe]);
}
}
$galleries_images = [];
$bloc_post = $this->renderBloc->RenderBloc($post,$schemaOrg);
$module = $post->getTypePost()->getSystemName();
$galleries = $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'media');
$galleries_images = $this->affichageGallerieService->GallerieImages($galleries,$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']);
$canonical = $this->functionService->canonicalUrl($post->translate($_locale)->getCanonical());
if($module == 'recrutement'){
$annonce_related = null;
$annonce_related = $this->getDoctrine()->getRepository(Post::class)->findRelatedAnnonces($post->getTypePost(),$post->getId());
$champs_personnalises_related_annonces = [];
if($annonce_related){
foreach($annonce_related as $annonce){
// Champs personnalisés
$champsPersonnalisesAnnonces = [];
$champsPersonnalisesAnnonces = $this->functionService->getChampsPersonnalisesPost($annonce);
$champs_personnalises_related_annonces[] = [
'id_post' => $annonce->getId(),
'champs_personnalises_post' => $champsPersonnalisesAnnonces
];
}
}
}
if($post->getTemplateCms()){
$template = $this->render('front/'.$this->theme.'/dynamique-page-cms.html.twig',[
'template'=> $post->getTemplateCms()->getTwig(),
'post'=> $post,
'canonical'=> $canonical,
'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,
'product_interesse'=> $product_interesse,
'annonce_interesse'=> $annonce_interesse,
'next_article'=> $next_article,
'prev_article'=> $prev_article,
'modele_galerie' => $modele_gallerie,
'template_model_gallerie' => $template_model_galerie,
'all_posts_associes' => $all_posts_associes,
'all_others_posts_associes' => $all_others_posts_associes
]);
}else{
// Champs personnalisés
$champsPersonnalisesPost = [];
$champsPersonnalisesPost = $this->functionService->getChampsPersonnalisesPost($post);
$ref_pages_principal = null;
$ref_pages_secondaire = null;
if ($post->getIdActivite()) {
$ref_pages_principal = $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdActivite($post->getIdActivite());
}
if ($post->getIdSousActivite()) {
$ref_pages_secondaire = $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdSousActivite($post->getIdSousActivite());
}
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
if($module == 'recrutement'){
$template = $this->render('front/'.$this->theme.'/page_annonce_detail.html.twig',[
'post'=> $post,
'canonical'=> $canonical,
'ref_pages_principal'=> $ref_pages_principal,
'parametreRef'=> $parametreRef,
'ref_pages_secondaire'=> $ref_pages_secondaire,
'title_home_ariane' => $title_home_ariane,
'galleries'=> $galleries_images,
'docs'=> $docs,
'blocs'=> $bloc_post,
'product_interesse'=> $product_interesse,
'annonce_interesse'=> $annonce_interesse,
'categorieTree'=> $categorieTree,
'meta_robots'=> $meta_robots,
'schemaOrg'=> $schemaOrg,
'custom_schemaOrg'=> $custom_schemaOrg,
'champsPersonnalisesPost'=> $champsPersonnalisesPost,
'parametre'=> $parametre,
'next_article'=> $next_article,
'prev_article'=> $prev_article,
'modele_galerie' => $modele_gallerie,
'template_model_gallerie' => $template_model_galerie,
'all_posts_associes' => $all_posts_associes,
'annonce_related'=> $annonce_related,
'champs_personnalises_related_annonces' => $champs_personnalises_related_annonces
]);
}else{
$template = $this->render('front/'.$this->theme.'/page_cms.html.twig',[
'post'=> $post,
'canonical'=> $canonical,
'ref_pages_principal'=> $ref_pages_principal,
'parametreRef'=> $parametreRef,
'ref_pages_secondaire'=> $ref_pages_secondaire,
'title_home_ariane' => $title_home_ariane,
'galleries'=> $galleries_images,
'docs'=> $docs,
'blocs'=> $bloc_post,
'product_interesse'=> $product_interesse,
'annonce_interesse'=> $annonce_interesse,
'categorieTree'=> $categorieTree,
'meta_robots'=> $meta_robots,
'schemaOrg'=> $schemaOrg,
'custom_schemaOrg'=> $custom_schemaOrg,
'champsPersonnalisesPost'=> $champsPersonnalisesPost,
'parametre'=> $parametre,
'next_article'=> $next_article,
'prev_article'=> $prev_article,
'modele_galerie' => $modele_gallerie,
'template_model_gallerie' => $template_model_galerie,
'all_posts_associes' => $all_posts_associes,
'all_others_posts_associes' => $all_others_posts_associes
]);
}
}
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);
if(!$categorie){
throw new NotFoundHttpException('Sorry not existing!');
}
$type_post = $categorie->getTypePost();
$parametrePost = $this->getDoctrine()->getRepository(ParametrePost::class)->findOneBy(['TypePost'=> $type_post]);
$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');
$galleries_images = $this->affichageGallerieService->GallerieImages($galleries,$galleries_images);
$template_model_galerie = $modele_gallerie[0]->getTwig();
$title_home_ariane = $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
$meta_robots = $categorie->getMetaRobots();
$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', ['slug'=> $categorie->translate($_locale)->getSlugUrl()], UrlGeneratorInterface::ABSOLUTE_URL),'name'=> $categorie->translate($_locale)->getTitreCategorie(),'active'=> false];
$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();
$categories_tree = [];
$categories_principal = $this->getDoctrine()->getRepository(Category::class)->findBy(['actif'=> true,'parent'=> 0,'sousParent'=> 0,'TypePost'=> $categorie->getTypepost()]);
if ($categories_principal) {
foreach ($categories_principal as $value) {
$data_slug_sous_categorie = [];
$sous_categorie = $this->getDoctrine()->getRepository(Category::class)->findBy(['actif'=> true,'parent'=> $value->getId()],['order_by'=>'ASC']);
if($sous_categorie){
foreach ($sous_categorie as $sous_categorie_items) {
$data_slug_sous_sous_categorie = [];
$sous_sous_categorie = $this->getDoctrine()->getRepository(Category::class)->findBy(['actif'=> true,'parent'=> 0,'sousParent'=> $sous_categorie_items->getId()],['order_by'=>'ASC']);
if ($sous_sous_categorie) {
foreach ($sous_sous_categorie as $sous_sous_categorie_items) {
$data_slug_sous_sous_categorie[] = ['id'=> $sous_sous_categorie_items->getId(),
'titre'=> $sous_sous_categorie_items->translate($_locale)->getTitreCategorie(),
'slug'=> $sous_sous_categorie_items->translate($_locale)->getSlugUrl()];
}
}
$data_slug_sous_categorie[] = ['id'=> $sous_categorie_items->getId(),
'titre'=> $sous_categorie_items->translate($_locale)->getTitreCategorie(),
'slug'=> $sous_categorie_items->translate($_locale)->getSlugUrl(),
'sous_sous_categories'=> $data_slug_sous_sous_categorie,
];
}
}
$categories_tree[] = ['id'=> $value->getId(),
'titre'=> $value->translate($_locale)->getTitreCategorie(),
'slug'=> $value->translate($_locale)->getSlugUrl(),
'sous_categories'=> $data_slug_sous_categorie,
];
}
}
if ($parametrePost && $parametrePost->getShowCategories()) {
$sous_categorie = $this->getDoctrine()->getRepository(Category::class)->findBy(['actif'=> true,'parent'=> $categorie->getId()],['order_by'=>'ASC']);
if ($sous_categorie) {
$posts = $this->getDoctrine()->getRepository(Category::class)->findSousCategorie($categorie,$page);
$postItems = $categorie->getPagination() == true ?$posts->getResults():$posts;
if ($postItems) {
foreach ($postItems as $value) {
$resultats[] = [ 'id'=> $value->getId(),
'slug'=> $value->translate($_locale)->getSlugUrl(),
'slug_categorie_parent'=> $categorie->translate($_locale)->getSlugUrl(),
'page_produit'=> $categorie->getTypepost()->getSystemName() == 'produits'?true:false,
'titre'=> $value->translate($_locale)->getTitreCategorie(),
'title_affichage'=> null,
'content'=> $value->translate($_locale)->getTexteCategorie(),
'chapeau'=> $value->translate($_locale)->getChapeauCategorie(),
'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)->findPostBySpecifiqueCategory($categorie,$page,$this->functionService->findRelatedIdsByCategorie($categories_tree,$categorie->getId(),'1'));
$postItems = $categorie->getPagination() == true ?$posts->getResults():$posts;
if ($postItems) {
foreach ($postItems as $value) {
$galleries_first_image = $this->affichageGallerieService->FirstGallerieImagePost($value);
// Champs personnalisés
$champsPersonnalisesPost = [];
$champsPersonnalisesPost = $this->functionService->getChampsPersonnalisesPost($value);
$resultats[] = [ 'id'=> $value->getId(),
'slug'=> $value->getSlug(),
'titre'=> $value->getTitle(),
'title_affichage'=> $value->getTitleAffichage(),
'slug_categorie_parent'=> $categorie->translate($_locale)->getSlugUrl(),
'page_produit'=> $categorie->getTypepost()->getSystemName() == 'produits'?true:false,
'content'=> $value->getContent(),
'chapeau'=> $value->getSummary(),
'image'=> $value->getImage(),
'image_couverture'=> $value->getImageCouverture(),
'galleries_first_image'=> $galleries_first_image,
'typelien'=> $value->getTypeLien(),
'titrelien'=> $value->getTitreLien(),
'telephone'=> $value->getTelephone(),
'lieninterne'=> $value->getLienInterne(),
'lienexterne'=> $value->getLienExterne(),
'prixproduit'=> $value->getPrixProduit(),
'champsPersonnalisesPost' => $champsPersonnalisesPost];
}
}
}
}else{
$posts = $this->getDoctrine()->getRepository(Post::class)->findPostBySpecifiqueCategory($categorie,$page,$this->functionService->findRelatedIdsByCategorie($categories_tree,$categorie->getId(),'1'));
$postItems = $categorie->getPagination() == true ?$posts->getResults():$posts;
if ($postItems) {
foreach ($postItems as $value) {
$galleries_first_image = $this->affichageGallerieService->FirstGallerieImagePost($value);
// Champs personnalisés
$champsPersonnalisesPost = [];
$champsPersonnalisesPost = $this->functionService->getChampsPersonnalisesPost($value);
$resultats[] = [ 'id'=> $value->getId(),
'slug'=> $value->getSlug(),
'titre'=> $value->getTitle(),
'title_affichage'=> $value->getTitleAffichage(),
'slug_categorie_parent'=> $categorie->translate($_locale)->getSlugUrl(),
'page_produit'=> $categorie->getTypepost()->getSystemName() == 'produits'?true:false,
'content'=> $value->getContent(),
'chapeau'=> $value->getSummary(),
'image'=> $value->getImage(),
'image_couverture'=> $value->getImageCouverture(),
'galleries_first_image'=> $galleries_first_image,
'typelien'=> $value->getTypeLien(),
'titrelien'=> $value->getTitreLien(),
'telephone'=> $value->getTelephone(),
'lieninterne'=> $value->getLienInterne(),
'lienexterne'=> $value->getLienExterne(),
'prixproduit'=> $value->getPrixProduit(),
'champsPersonnalisesPost' => $champsPersonnalisesPost];
}
}
}
if ($categorie->getTypepost()->getSystemName() == 'produits') {
$template = $this->render('front/'.$this->theme.'/produits/page_categorie.html.twig',[
'template'=> $template,
'title_home_ariane' => $title_home_ariane,
'categorie'=> $categorie,
'categories_tree'=> $categories_tree,
'breadcrumb'=> $breadcrumb,
'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,
'param_post' => $parametrePost,
'show_filter_categorie'=> $type_post->getFilterCategorie()
]);
}else {
$template = $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,
]);
}
return $template;
}
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']);
}
$ref_pages_sous_activite = $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdsSousActiviteAndActivitePrincipal($activite->getId());
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
$template = $this->render('front/'.$this->theme.'/page_activite.html.twig',[
'titre'=> $titre,
'texte'=> $texte,
'titre_activite'=> $titre_activite,
'slug'=> $slug,
'parametreRef'=> $parametreRef,
'activite'=> $activite,
'medias'=> $medias,
'ref_pages'=> $ref_pages,
'ref_pages_sous_activite'=> $ref_pages_sous_activite,
'actualites'=> $actualites,
'parametre'=> $parametre,
'secteurs'=> $secteurs,
'breadcrumb'=> $breadcrumb,
'schemaOrg'=> $schemaOrg,
]);
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()) {
return $this->redirectToRoute('page',['slug'=> $activite_secondaire->getActivitePrimaire()->translate($_locale)->getLibelleUrl()]);
$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');
$ref_pages_activites = null;
if ($activite_secondaire->getActivitePrimaire()) {
$ref_pages_activites = $this->getDoctrine()->getRepository(Post::class)->findPageRefByIdActivite($activite_secondaire->getActivitePrimaire()->getId());
}
$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));
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
$template = $this->render('front/'.$this->theme.'/page_activite_secondaire.html.twig',[
'titre'=> $titre,
'texte'=> $texte,
'titre_activite'=>$titre_activite,
'activite_secondaire'=> $activite_secondaire,
'parametreRef'=> $parametreRef,
'activite_primaire_titre'=> $activite_primaire_titre,
'activite_primaire_slug'=> $activite_primaire_slug,
'slug'=> $slug,
'schemaOrg'=> $schemaOrg,
'ref_pages'=> $ref_pages,
'ref_pages_activites'=> $ref_pages_activites,
'actualites'=> $actualites,
'parametre'=> $parametre,
'secteurs'=> $secteurs,
'breadcrumb'=> $breadcrumb
]);
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 pageTraking($request,$slug){
$schemaOrg = new Graph();
$_locale = $request->getLocale();
$home = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$seo_image = '';
$url = $this->generateUrl('page', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL);
if ($this->functionService->parametreGenerale()) {
if ($this->functionService->parametreGenerale()->getApercuImageLien()) {
$seo_image = $baseurl.'/public/uploads/images/'.$this->functionService->parametreGenerale()->getApercuImageLien();
}
}
$title_home_ariane = $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
$breadcrumb = [];
$schema_breadcrumb_items = [];
switch ($slug) {
case 'contact-envoye':
$title_page_ariane = "Contact envoye";
break;
case 'contact-envoye-devis':
$title_page_ariane = "Contact envoye devis";
break;
case 'contact-landing-page':
$title_page_ariane = "Contact envoye";
break;
}
$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', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page_ariane,'active'=> false];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(1)
->item(["@id"=> $this->generateUrl('page', ['slug'=> $slug], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page_ariane]);
if ($schema_breadcrumb_items) {
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
}
if ($slug == 'contact-envoye') {
$template = $this->render('front/'.$this->theme.'/form/traking-pages/contact_envoye.html.twig',[
'breadcrumb'=> $breadcrumb,
'title_page'=> $title_page_ariane
]);
}
if ($slug == 'contact-envoye-devis') {
$template = $this->render('front/'.$this->theme.'/form/traking-pages/contact_envoye_devis.html.twig',[
'breadcrumb'=> $breadcrumb,
'title_page'=> $title_page_ariane
]);
}
if ($slug == 'contact-landing-page') {
$template = $this->render('front/'.$this->theme.'/form/traking-pages/contact_landing_page.html.twig',[
'breadcrumb'=> $breadcrumb,
'title_page'=> $title_page_ariane
]);
}
if ($this->session->get('traking-page') != true) {
throw new NotFoundHttpException('Sorry not existing!');
}
$this->session->remove('traking-page');
return $template;
}
/**
* @Route("/bons-cadeaux", name="bons_cadeaux",priority="10")
*/
public function PageBonsCadeaux(Request $request)
{
$_locale = $request->getLocale();
$module = 'bons-cadeaux';
$all_galleries_posts = [];
$champs_personnalises_posts = [];
$posts = null;
$typePost = $this->getDoctrine()->getRepository(TypePost::class)->findSystemName($module);
if(!$typePost){
throw new NotFoundHttpException('Sorry not existing!');
}else{
$posts = $this->getDoctrine()->getRepository(Post::class)->findAllActivesPostsByType($_locale,$typePost->getId());
}
$parametreSite = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'DESC']);
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_bon_cadeaux']);
$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() : $parametreRef->translate($_locale)->getTitreParamRef();
if ($parametreRef) {
$meta_tags = $this->metaService->generateMetaPage($parametreRef,'param_bon_cadeaux');
if ($meta_tags) {
$this->basicSeo->setTitle($meta_tags['title'])
->setDescription($meta_tags['description']);
}
}
if($posts){
foreach($posts as $post){
// Galleries posts
$galleries_posts = [];
$galleries_images = [];
$galleries_posts = $this->getDoctrine()->getRepository(MediaCms::class)->findFileByModule($module,$post->getId(),'media');
$galleries_images = $this->affichageGallerieService->GallerieImages($galleries_posts,$galleries_images);
$all_galleries_posts[] = [
'id' => $post->getId(),
'gallerie' => $galleries_images
];
// Champs personnalisés
$champsPersonnalisesPost = [];
$champsPersonnalisesPost = $this->functionService->getChampsPersonnalisesPost($post);
if($champsPersonnalisesPost){
$champs_personnalises_posts[] = [
'id_post' => $post->getId(),
'champs_personnalises_post' => $champsPersonnalisesPost
];
}
}
}
return $this->render('front/'.$this->theme.'/page_bons_cadeaux.html.twig',[
'posts'=> $posts,
'all_galleries_posts' => $all_galleries_posts,
'champs_personnalises_posts' => $champs_personnalises_posts,
'parametre' => $parametreSite,
'parametreRef'=> $parametreRef,
'title_page'=> $title_page,
'title_home_ariane' => $title_home_ariane
]);
}
/**
* @Route("/recrutement", name="recrutement",priority="10")
*/
public function PageRecrutement(Request $request)
{
$_locale = $request->getLocale();
$module = 'recrutement';
$all_galleries_posts = [];
$champs_personnalises_posts = [];
$posts = null;
$typePost = $this->getDoctrine()->getRepository(TypePost::class)->findSystemName($module);
if(!$typePost){
throw new NotFoundHttpException('Sorry not existing!');
}else{
$posts = $this->getDoctrine()->getRepository(Post::class)->findAllActivesPostsByType($_locale,$typePost->getId());
}
$parametreSite = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'DESC']);
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_recrutement']);
$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() : $parametreRef->translate($_locale)->getTitreParamRef();
if ($parametreRef) {
$meta_tags = $this->metaService->generateMetaPage($parametreRef,'param_recrutement');
if ($meta_tags) {
$this->basicSeo->setTitle($meta_tags['title'])
->setDescription($meta_tags['description']);
}
}
if($posts){
foreach($posts as $post){
// Champs personnalisés
$champsPersonnalisesPost = [];
$champsPersonnalisesPost = $this->functionService->getChampsPersonnalisesPost($post);
$champs_personnalises_posts[] = [
'id_post' => $post->getId(),
'champs_personnalises_post' => $champsPersonnalisesPost
];
}
}
return $this->render('front/'.$this->theme.'/page_recrutement.html.twig',[
'posts'=> $posts,
'champs_personnalises_posts' => $champs_personnalises_posts,
'parametre' => $parametreSite,
'parametreRef'=> $parametreRef,
'title_page'=> $title_page,
'title_home_ariane' => $title_home_ariane
]);
}
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());
}
}
}
}
}