<?php
namespace App\Controller\Front;
use App\Entity\Menu;
use App\Entity\Post;
use App\Entity\Contact;
use App\Entity\Country;
use App\Entity\Language;
use App\Entity\ListeRef;
use App\Entity\Secteurs;
use App\Entity\Activites;
use App\Entity\GroupBloc;
use App\Entity\ListeMenu;
use App\Service\BuildTree;
use Spatie\SchemaOrg\Graph;
use App\Entity\ParamContact;
use App\Entity\ParametreRef;
use App\Entity\ThemeOptions;
use App\Service\MetaService;
use Spatie\SchemaOrg\Schema;
use App\Entity\ParametreSite;
use App\Entity\ProduitOption;
use App\Entity\ReseauSociaux;
use App\Entity\TextParametrable;
use App\Entity\CategoriesProduct;
use App\Entity\ActiviteSecondaire;
use App\Service\RenderDefaultBloc;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\TextParametrableTranslation;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ActivitesController extends AbstractController
{
public $basicSeo;
public $metaService;
public function __construct(string $theme,MetaService $metaService,HttpClientInterface $client,BasicSeoGenerator $basicSeo,string $projectDirr)
{
$this->theme = $theme;
$this->client = $client;
$this->projectDirr = $projectDirr;
$this->basicSeo = $basicSeo;
$this->metaService = $metaService;
}
/**
* @Route("/activites", name="page_activites", options={"sitemap" = true},priority=10)
*/
public function index(Request $request,EntityManagerInterface $entityManager)
{
$_locale = $request->getLocale();
$resultat= [];
$date_now = new \DateTime("now");
$activites = $this->getDoctrine()->getRepository(Activites::class)->findBy(['actif'=> true]);
if ($activites) {
foreach($activites as $value) {
$data_url = [];
$data_activite_secondaire = [];
$page_refs = $this->getDoctrine()->getRepository(Post::class)->findBy(['id_activite'=> $value->getId(),'type_page_ref'=> 'activite']);
if($page_refs){
foreach ($page_refs as $page_item) {
if ($page_item->getDatePublication() == null || strtotime($page_item->getDatePublication()->format('Y-m-d')) <= strtotime($date_now->format('Y-m-d'))) {
$data_url [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
'slug'=> $page_item->translate($_locale)->getSlug(),
'type'=> 'page_ref',
];
}
}
}
$page_actulaites = $this->getDoctrine()->getRepository(Post::class)->findBy(['id_activite'=> $value->getId(),'type_page_ref'=> null]);
if($page_actulaites){
foreach ($page_actulaites as $page_item) {
if ($page_item->getDatePublication() == null || strtotime($page_item->getDatePublication()->format('Y-m-d')) <= strtotime($date_now->format('Y-m-d'))) {
$data_url [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
'slug'=> $page_item->translate($_locale)->getSlug(),
'type'=> 'page_actualite',
];
}
}
}
$activite_secondaires = $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->findActiviteSecondaire($value->getId());
if($activite_secondaires){
foreach ($activite_secondaires as $act_secondaire) {
$data_url_activite_secondaire = [];
$page_ref_sec = $this->getDoctrine()->getRepository(Post::class)->findBy(['id_sous_activite'=> $act_secondaire->getId(),'type_page_ref'=> 'activite_secondaire']);
if($page_ref_sec){
foreach ($page_ref_sec as $page_item) {
if ($page_item->getDatePublication() == null || strtotime($page_item->getDatePublication()->format('Y-m-d')) <= strtotime($date_now->format('Y-m-d'))) {
$data_url_activite_secondaire [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
'slug'=> $page_item->translate($_locale)->getSlug(),
'type'=> 'page_ref',
];
}
}
}
$data_activite_secondaire[] = ['titre'=> $act_secondaire->translate($_locale)->getTitreActiviteSecondaire(),
'slug'=> $act_secondaire->translate($_locale)->getLibelleUrl(),
'urls'=> $data_url_activite_secondaire
];
}
}
$resultat[] = ['titre'=> $value->translate($_locale)->getTitre(),
'slug'=> $value->translate($_locale)->getLibelleUrl(),
'urls_principal'=> $data_url,
'activite_secondiare'=> $data_activite_secondaire,
];
}
}
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'hub_activite']);
$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() : "Activite";
$schemaOrg = new Graph();
$breadcrumb = [];
$schema_breadcrumb_items = [];
$breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(1)
->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
$breadcrumb [] = ['url'=> $this->generateUrl('page_activites', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page,'active'=> false];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(2)
->item(["@id"=> $this->generateUrl('page_activites', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page]);
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
if ($parametreRef) {
$meta_tags = $this->metaService->generateMetaPage($parametreRef,'hub_activite');
if ($meta_tags) {
$this->basicSeo->setTitle($meta_tags['title'])
->setDescription($meta_tags['description']);
}
}
return $this->render('front/'.$this->theme.'/activites.html.twig',[
'activites'=> $resultat,
'breadcrumb'=> $breadcrumb,
'schemaOrg'=> $schemaOrg,
'parametreRef'=> $parametreRef,
'title_page'=> $title_page
]);
}
}