<?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 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 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 Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ActivitesController extends AbstractController
{
public function __construct(string $theme,HttpClientInterface $client,string $projectDirr)
{
$this->theme = $theme;
$this->client = $client;
$this->projectDirr = $projectDirr;
}
/**
* @Route("/activites", name="page_activites", options={"sitemap" = true},priority=10)
*/
public function index(Request $request)
{
$_locale = $request->getLocale();
$resultat= [];
$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) {
$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) {
$data_url [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
'slug'=> $page_item->translate($_locale)->getSlug(),
'type'=> 'page_actualite',
];
}
}
$activite_secondaires = $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->findActiviteSecondiare($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) {
$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,
];
}
}
$home = $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
$title_home_ariane = $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
$schemaOrg = new Graph();
$breadcrumb = [];
$schema_breadcrumb_items = [];
$breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(1)
->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
$breadcrumb [] = ['url'=> $this->generateUrl('page_activites', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Activites','active'=> false];
$schema_breadcrumb_items[] = Schema::ListItem()
->position(2)
->item(["@id"=> $this->generateUrl('page_activites', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Activites']);
$schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
return $this->render('front/'.$this->theme.'/activites.html.twig',[
'activites'=> $resultat,
'breadcrumb'=> $breadcrumb,
'schemaOrg'=> $schemaOrg,
]);
}
}