src/Controller/Front/ActivitesController.php line 44

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 Spatie\SchemaOrg\Schema;
  19. use App\Entity\ParametreSite;
  20. use App\Entity\ProduitOption;
  21. use App\Entity\ReseauSociaux;
  22. use App\Entity\TextParametrable;
  23. use App\Entity\CategoriesProduct;
  24. use App\Entity\ActiviteSecondaire;
  25. use App\Service\RenderDefaultBloc;
  26. use App\Entity\TextParametrableTranslation;
  27. use Symfony\Component\Filesystem\Filesystem;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpFoundation\Response;
  30. use Symfony\Component\Routing\Annotation\Route;
  31. use Symfony\Contracts\HttpClient\HttpClientInterface;
  32. use Symfony\Component\Translation\TranslatorInterface;
  33. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  34. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  35. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  36. class ActivitesController  extends AbstractController
  37. {
  38.     public function __construct(string $theme,HttpClientInterface $client,string $projectDirr)
  39.     {
  40.         $this->theme $theme;
  41.         $this->client $client;
  42.         $this->projectDirr $projectDirr;
  43.     }
  44.     /**
  45.      * @Route("/activites", name="page_activites", options={"sitemap" = true},priority=10)
  46.      */
  47.     public function index(Request $request)
  48.     {
  49.         $_locale $request->getLocale();
  50.         $resultat= [];
  51.         $activites $this->getDoctrine()->getRepository(Activites::class)->findBy(['actif'=> true]);
  52.         if ($activites) {
  53.            foreach($activites as $value) {
  54.                 $data_url = [];
  55.                 $data_activite_secondaire = [];
  56.                 $page_refs $this->getDoctrine()->getRepository(Post::class)->findBy(['id_activite'=> $value->getId(),'type_page_ref'=> 'activite']);
  57.                 if($page_refs){
  58.                     foreach ($page_refs as $page_item) {
  59.                         $data_url [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
  60.                                         'slug'=> $page_item->translate($_locale)->getSlug(),
  61.                                         'type'=> 'page_ref',
  62.                                         ];
  63.                     }
  64.                 }
  65.                 $page_actulaites $this->getDoctrine()->getRepository(Post::class)->findBy(['id_activite'=> $value->getId(),'type_page_ref'=> null]);
  66.                 if($page_actulaites){
  67.                     foreach ($page_actulaites as $page_item) {
  68.                         $data_url [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
  69.                                         'slug'=> $page_item->translate($_locale)->getSlug(),
  70.                                         'type'=> 'page_actualite',
  71.                                         ];
  72.                     }
  73.                 }
  74.                 
  75.                 $activite_secondaires $this->getDoctrine()->getRepository(ActiviteSecondaire::class)->findActiviteSecondiare($value->getId());
  76.                 if($activite_secondaires){
  77.                     foreach ($activite_secondaires as $act_secondaire) {
  78.                         $data_url_activite_secondaire = [];
  79.                         $page_ref_sec $this->getDoctrine()->getRepository(Post::class)->findBy(['id_sous_activite'=> $act_secondaire->getId(),'type_page_ref'=> 'activite_secondaire']);
  80.                         if($page_ref_sec){
  81.                             foreach ($page_ref_sec as $page_item) {
  82.                                 $data_url_activite_secondaire  [] = ['titre'=> $page_item->translate($_locale)->getTitle(),
  83.                                                                      'slug'=> $page_item->translate($_locale)->getSlug(),
  84.                                                                       'type'=> 'page_ref',
  85.                                                                     ];
  86.                             }
  87.                         }
  88.                         $data_activite_secondaire[] = ['titre'=> $act_secondaire->translate($_locale)->getTitreActiviteSecondaire(),
  89.                                                        'slug'=> $act_secondaire->translate($_locale)->getLibelleUrl(),
  90.                                                        'urls'=> $data_url_activite_secondaire
  91.                                                       ];
  92.                     }
  93.                 }
  94.                 $resultat[] = ['titre'=> $value->translate($_locale)->getTitre(),
  95.                                'slug'=> $value->translate($_locale)->getLibelleUrl(),
  96.                                'urls_principal'=> $data_url,
  97.                                'activite_secondiare'=> $data_activite_secondaire,
  98.                               ]; 
  99.  
  100.            } 
  101.         }
  102.         $home $this->getDoctrine()->getRepository(Post::class)->findPostBySlug('Home');
  103.         $title_home_ariane $home->getBreadcrumb() ? $home->getBreadcrumb() : "Accueil";
  104.         $schemaOrg = new Graph();
  105.         $breadcrumb = [];
  106.         $schema_breadcrumb_items = [];
  107.         
  108.         $breadcrumb [] = ['url'=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane,'active'=> true];
  109.         $schema_breadcrumb_items[] = Schema::ListItem()
  110.                                      ->position(1)
  111.                                      ->item(["@id"=> $this->generateUrl('index_home', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> $title_home_ariane]);
  112.         
  113.         $breadcrumb [] = ['url'=> $this->generateUrl('page_activites', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Activites','active'=> false];
  114.         $schema_breadcrumb_items[] = Schema::ListItem()
  115.                                     ->position(2)
  116.                                     ->item(["@id"=> $this->generateUrl('page_activites', [], UrlGeneratorInterface::ABSOLUTE_URL),"name"=> 'Activites']);
  117.    
  118.         $schemaOrg->add(Schema::BreadcrumBList()->itemListElement($schema_breadcrumb_items));
  119.         return $this->render('front/'.$this->theme.'/activites.html.twig',[
  120.             'activites'=> $resultat,
  121.             'breadcrumb'=> $breadcrumb,
  122.             'schemaOrg'=> $schemaOrg,
  123.         ]);
  124.     }
  125.     
  126. }