src/Controller/Front/ActivitesController.php line 142

Open in your IDE?
  1. <?php 
  2. namespace App\Controller\Front;
  3. use App\Entity\Menu;
  4. use App\Entity\Post;
  5. use App\Entity\Contact;
  6. use App\Entity\Country;
  7. use App\Entity\Language;
  8. use App\Entity\ListeRef;
  9. use App\Entity\Secteurs;
  10. use App\Entity\Activites;
  11. use App\Entity\GroupBloc;
  12. use App\Entity\ListeMenu;
  13. use App\Service\BuildTree;
  14. use Spatie\SchemaOrg\Graph;
  15. use App\Entity\ParamContact;
  16. use App\Entity\ParametreRef;
  17. use App\Entity\ThemeOptions;
  18. use App\Service\MetaService;
  19. use Spatie\SchemaOrg\Schema;
  20. use App\Entity\ParametreSite;
  21. use App\Entity\ProduitOption;
  22. use App\Entity\ReseauSociaux;
  23. use App\Entity\TextParametrable;
  24. use App\Entity\CategoriesProduct;
  25. use App\Entity\ActiviteSecondaire;
  26. use App\Service\RenderDefaultBloc;
  27. use Doctrine\ORM\EntityManagerInterface;
  28. use App\Entity\TextParametrableTranslation;
  29. use Symfony\Component\Filesystem\Filesystem;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Component\HttpFoundation\Response;
  32. use Symfony\Component\Routing\Annotation\Route;
  33. use Symfony\Contracts\HttpClient\HttpClientInterface;
  34. use Symfony\Component\Translation\TranslatorInterface;
  35. use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator;
  36. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  37. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  38. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  39. class ActivitesController  extends AbstractController
  40. {
  41.     public $basicSeo;
  42.     public $metaService;
  43.     public function __construct(string $theme,MetaService $metaService,HttpClientInterface $client,BasicSeoGenerator $basicSeo,string $projectDirr)
  44.     {
  45.         $this->theme $theme;
  46.         $this->client $client;
  47.         $this->projectDirr $projectDirr;
  48.         $this->basicSeo $basicSeo;
  49.         $this->metaService $metaService;
  50.     }
  51.     /**
  52.      * @Route("/activites", name="page_activites", options={"sitemap" = true},priority=10)
  53.      */
  54.     public function index(Request $request,EntityManagerInterface $entityManager)
  55.     {
  56.         $_locale $request->getLocale();
  57.         $resultat= [];
  58.         $date_now = new \DateTime("now");
  59.         $activites $this->getDoctrine()->getRepository(Activites::class)->findBy(['actif'=> true]);
  60.         if ($activites) {
  61.            foreach($activites as $value) {
  62.                 $data_url = [];
  63.                 $data_activite_secondaire = [];
  64.                 $page_refs $this->getDoctrine()->getRepository(Post::class)->findBy(['id_activite'=> $value->getId(),'type_page_ref'=> 'activite']);
  65.           
  66.                 if($page_refs){
  67.                     foreach ($page_refs as $page_item) {
  68.                         if ($page_item->getDatePublication() == null || strtotime($page_item->getDatePublication()->format('Y-m-d')) <= strtotime($date_now->format('Y-m-d'))) {
  69.                             $data_url [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
  70.                                             'slug'=> $page_item->translate($_locale)->getSlug(),
  71.                                             'type'=> 'page_ref',
  72.                                             ];
  73.                         }
  74.                     }
  75.                 }
  76.     
  77.                 $page_actulaites $this->getDoctrine()->getRepository(Post::class)->findBy(['id_activite'=> $value->getId(),'type_page_ref'=> null]);
  78.                 if($page_actulaites){
  79.                     foreach ($page_actulaites as $page_item) {
  80.                         if ($page_item->getDatePublication() == null || strtotime($page_item->getDatePublication()->format('Y-m-d')) <= strtotime($date_now->format('Y-m-d'))) {
  81.                             $data_url [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
  82.                                             'slug'=> $page_item->translate($_locale)->getSlug(),
  83.                                             'type'=> 'page_actualite',
  84.                                             ];
  85.                         }
  86.                     }
  87.                 }
  88.                 
  89.                 $activite_secondaires $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->findActiviteSecondaire($value->getId());
  90.                 if($activite_secondaires){
  91.                     foreach ($activite_secondaires as $act_secondaire) {
  92.                         $data_url_activite_secondaire = [];
  93.                         $page_ref_sec $this->getDoctrine()->getRepository(Post::class)->findBy(['id_sous_activite'=> $act_secondaire->getId(),'type_page_ref'=> 'activite_secondaire']);
  94.                         if($page_ref_sec){
  95.                             foreach ($page_ref_sec as $page_item) {
  96.                                 if ($page_item->getDatePublication() == null || strtotime($page_item->getDatePublication()->format('Y-m-d')) <= strtotime($date_now->format('Y-m-d'))) {
  97.                                     $data_url_activite_secondaire  [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
  98.                                                                         'slug'=> $page_item->translate($_locale)->getSlug(),
  99.                                                                         'type'=> 'page_ref',
  100.                                                                         ];
  101.                                 }
  102.                             }
  103.                         }
  104.                         $data_activite_secondaire[] = ['titre'=> $act_secondaire->translate($_locale)->getTitreActiviteSecondaire(),
  105.                                                        'slug'=> $act_secondaire->translate($_locale)->getLibelleUrl(),
  106.                                                        'urls'=> $data_url_activite_secondaire
  107.                                                       ];
  108.                     }
  109.                 }
  110.                 $resultat[] = ['titre'=> $value->translate($_locale)->getTitre(),
  111.                                'slug'=> $value->translate($_locale)->getLibelleUrl(),
  112.                                'urls_principal'=> $data_url,
  113.                                'activite_secondiare'=> $data_activite_secondaire,
  114.                               ]; 
  115.  
  116.            } 
  117.         }
  118.         $parametreRef $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'hub_activite']);
  119.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  120.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  121.         $title_page $parametreRef && $parametreRef->translate($_locale)->getBreadcrumb() ? $parametreRef->translate($_locale)->getBreadcrumb() : "Activite";
  122.         $schemaOrg = new Graph();
  123.         $breadcrumb = [];
  124.         $schema_breadcrumb_items = [];
  125.         
  126.         $breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
  127.         $schema_breadcrumb_items[] = Schema::ListItem()
  128.                                      ->position(1)
  129.                                      ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  130.         
  131.         $breadcrumb [] = ['url'=> $this->generateUrl('page_activites', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page,'active'=> false];
  132.         $schema_breadcrumb_items[] = Schema::ListItem()
  133.                                     ->position(2)
  134.                                     ->item(["@id"=> $this->generateUrl('page_activites', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_page]);
  135.    
  136.         $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  137.         if ($parametreRef) {
  138.             $meta_tags $this->metaService->generateMetaPage($parametreRef,'hub_activite');
  139.             if ($meta_tags) {
  140.                 $this->basicSeo->setTitle($meta_tags['title'])
  141.                                ->setDescription($meta_tags['description']);
  142.             }
  143.         }
  144.         return $this->render('front/'.$this->theme.'/activites.html.twig',[
  145.             'activites'=> $resultat,
  146.             'breadcrumb'=> $breadcrumb,
  147.             'schemaOrg'=> $schemaOrg,
  148.             'parametreRef'=> $parametreRef,
  149.             'title_page'=> $title_page
  150.         ]);
  151.     }
  152.     
  153. }