src/Service/RenderBloc.php line 175

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Entity\Faqs;
  4. use App\Entity\Post;
  5. use App\Entity\Forms;
  6. use App\Entity\Videos;
  7. use App\Entity\CpField;
  8. use App\Entity\PostFaq;
  9. use App\Entity\Product;
  10. use App\Entity\MediaCms;
  11. use App\Entity\PostBloc;
  12. use App\Entity\Secteurs;
  13. use App\Entity\Activites;
  14. use App\Entity\BlocService;
  15. use App\Entity\CategoryFaq;
  16. use App\Entity\CpPostField;
  17. use App\Entity\FormsFields;
  18. use App\Entity\Partenaires;
  19. use App\Entity\CategoryBloc;
  20. use App\Entity\MediaGallery;
  21. use App\Entity\ParametreRef;
  22. use App\Entity\PostCategory;
  23. use App\Entity\Testimonials;
  24. use Spatie\SchemaOrg\Schema;
  25. use App\Entity\ModelGallerie;
  26. use App\Entity\ParametrePost;
  27. use App\Entity\ParametreSite;
  28. use App\Entity\ProduitOption;
  29. use App\Service\ImageService;
  30. use App\Entity\GallerieBlocPost;
  31. use App\Entity\CategoriesProduct;
  32. use App\Entity\ActiviteSecondaire;
  33. use Symfony\Component\Intl\Locale;
  34. use App\Entity\ParametrePartenaires;
  35. use Doctrine\ORM\EntityManagerInterface;
  36. use Symfony\Component\HttpClient\HttpClient;
  37. use Symfony\Component\HttpFoundation\RequestStack;
  38. use Symfony\Contracts\HttpClient\HttpClientInterface;
  39. class RenderBloc
  40. {
  41.     private $em;
  42.     private $templating;
  43.     private $theme;
  44.     private $client;
  45.     private $requestStack;
  46.     private $imageService;
  47.     private $affichageGallerieService;
  48.     private $functionService;
  49.     private $bloc_service_renderd;
  50.     public function __construct(EntityManagerInterface $em,\Twig\Environment $templating,string $theme,
  51.                                 HttpClientInterface $clientRequestStack $requestStack,ImageService $imageService,
  52.                                 AffichageGallerieService $affichageGallerieService,FunctionService $functionService,$bloc_service_renderd false)
  53.     {
  54.         $this->templating $templating;
  55.         $this->em $em;
  56.         $this->theme $theme;
  57.         $this->client $client;
  58.         $this->requestStack $requestStack;
  59.         $this->imageService $imageService;
  60.         $this->affichageGallerieService $affichageGallerieService;
  61.         $this->functionService $functionService;
  62.         $this->bloc_service_renderd $bloc_service_renderd;
  63.     }
  64.     
  65.     public function RenderBloc($post,$schemaOrg,$type 'post') {
  66.         $_locale Locale::getDefault();
  67.   
  68.         $data_post = [];
  69.         $data_Bloc = [];
  70.         $blocs null;
  71.         if($type == 'post'){
  72.             if ($post != null) {
  73.               $blocs $this->em->getRepository(PostBloc::class)->findBlocNotDeleted($post->getId());
  74.             }
  75.         }else{
  76.             if($post != null){
  77.               $blocs $this->em->getRepository(CategoryBloc::class)->findBlocNotDeleted($post->getId());
  78.             }            
  79.         }
  80.     
  81.         if($blocs != null){
  82.             array_filter($blocs, function($blocItem) {
  83.                if ($blocItem->getTypeBloc() == '11' && $blocItem->getActif() == true) {
  84.                   $bloc_service_existe $this->em->getRepository(BlocService::class)->findOneBy(['actif'=> true,'id'=> $blocItem->getIdBlocService()]);
  85.                   if ($bloc_service_existe && $bloc_service_existe->getAlias() == 'bloc_travaux') {
  86.                     $this->bloc_service_renderd true;
  87.                   }
  88.                }
  89.             });
  90.             foreach($blocs as $bloc){
  91.                 $data = [];
  92.                 if($bloc->getTypeBloc() == '5' && $bloc->getActif() == true){
  93.                   $Media $this->em->getRepository(MediaGallery::class)->findGalleryActif($bloc->getMediaGallery());
  94.                   $data_gallerie = [];
  95.                   if($Media){
  96.                       $media_cms $this->em->getRepository(MediaCms::class)->findBy(['module'=> 'gallerie','module_id'=>$Media->getId()],['position'=> 'ASC']);
  97.                       foreach($media_cms as $gallerie){
  98.                         $data_gallerie[] = [
  99.                                            'id'=> $gallerie->getId(),
  100.                                            'position'=> $gallerie->getPosition(),
  101.                                            'path'=> $gallerie->getLocation().$gallerie->getPath().$gallerie->getFileName(),  
  102.                                            'title'=> $gallerie->translate($_locale)->gettitre(), 
  103.                                            'fileExtension' => $gallerie->getType(),
  104.                                            'description'=> $gallerie->translate($_locale)->getDescription(),
  105.                                            'description2'=> $gallerie->translate($_locale)->getDescription2(),  
  106.                                           ];
  107.                       }
  108.                       $data = [
  109.                                 'id' => $Media->getId(),
  110.                                 'actif'=> $Media->getActif(),
  111.                                 'type' => 'slider',
  112.                                 'title'=> $Media->translate($_locale)->getTitre(),     
  113.                                 'description'=> $Media->translate($_locale)->getDescription(),    
  114.                                 'images'=> $data_gallerie,  
  115.                                 'mobile'=> $bloc->getActifMobile(), 
  116.                                 'desktop'=> $bloc->getActifDesktop(), 
  117.                       ];
  118.                   }
  119.                   
  120.                 }elseif($bloc->getTypeBloc() == '6' && $bloc->getActif() == true){
  121.                     $form $this->em->getRepository(Forms::class)->findOneBy(['id'=>$bloc->getForm()]);
  122.                     $formField $this->em->getRepository(FormsFields::class)->findOneBy(['form'=>$form,'local'=>$_locale]);
  123.                     
  124.                     // update nbr visit
  125.                     $form->setNbrVisit($form->getNbrVisit() + 1);
  126.                     $this->em->persist($form);
  127.                     $this->em->flush();
  128.    
  129.                     $data_Form = [
  130.                           'id'=> $form->getId(),
  131.                           'name'=> $form->getName(),
  132.                           'methode'=> $form->getMethode(),   
  133.                           'success_message'=>  $form->getSuccessMessage(), 
  134.                           'identifier'=>  $form->getIdentifier(), 
  135.                           'type_form'=> $form->getFormBuilder(),
  136.                           'data'=> $formField?unserialize($formField->getData()):null,
  137.                           'data_form_step'=> $formField?unserialize($formField->getDataFormMutiStep()):null,
  138.                           'titre'=> $form->getTitreContent(),
  139.                           'texte'=> $form->getTexteContent(),
  140.                           'image'=> $form->getImage(),
  141.                           'alt_image'=> $form->getAltImage(),
  142.                     ]; 
  143.                        
  144.                     $data = [ 'id' => $bloc->getId(),
  145.                               'actif' => $bloc->getActif(),
  146.                               'type'  => $bloc->getTypeBloc() == ?'form':$bloc->getTypeBloc(),
  147.                               'title' => $bloc->translate($_locale)->getTitle(),
  148.                               'content' => $bloc->translate($_locale)->getContent(),
  149.                               'content2' => $bloc->translate($_locale)->getContent2(),
  150.                               'link'=> $bloc->translate($_locale)->getLink(),
  151.                               'form'  => $data_Form
  152.                               'mobile'=> $bloc->getActifMobile(), 
  153.                               'desktop'=> $bloc->getActifDesktop(), 
  154.                             ];
  155.                 }elseif($bloc->getTypeBloc() == '7' && $bloc->getActif()  == true){
  156.   
  157.                   $data = [ 'id' => $bloc->getId(),
  158.                             'actif' => $bloc->getActif(),
  159.                             'type'  => 'template',
  160.                             'template' => $bloc->translate($_locale)->getTemplate(),
  161.                             'mobile'=> $bloc->getActifMobile(), 
  162.                             'desktop'=> $bloc->getActifDesktop(), 
  163.                           ];
  164.                 }elseif($bloc->getTypeBloc() == '8' && $bloc->getActif() == true){
  165.                   
  166.                   $template $this->renderTemplate($bloc,$schemaOrg);
  167.                   $data = [ 'id' => $bloc->getId(),
  168.                             'actif' => $bloc->getActif(),
  169.                             'type'  => 'template',
  170.                             'template' => $template,
  171.                             'mobile'=> $bloc->getActifMobile(), 
  172.                             'desktop'=> $bloc->getActifDesktop(), 
  173.                           ];
  174.                 }elseif($bloc->getTypeBloc() == '9' && $bloc->getActif()  == true){
  175.                   $data = [ 'id' => $bloc->getId(),
  176.                             'actif' => $bloc->getActif(),
  177.                             'type'  => 'video',
  178.                             'url_video' => $bloc->getVideoUrl(),
  179.                             'mobile'=> $bloc->getActifMobile(), 
  180.                             'desktop'=> $bloc->getActifDesktop(), 
  181.                           ];
  182.                 }elseif($bloc->getTypeBloc() == '3' && $bloc->getActif()  == true){
  183.                           $data = [ 'id' => $bloc->getId(),
  184.                                     'actif' => $bloc->getActif(),
  185.                                     'type'  => 'image',
  186.                                     'title' => $bloc->translate($_locale)->getTitle(),
  187.                                     'bgimage' => $bloc->getImage(),
  188.                                     'mobile'=> $bloc->getActifMobile(), 
  189.                                     'desktop'=> $bloc->getActifDesktop(), 
  190.                                   ];
  191.                 }elseif($bloc->getTypeBloc() == '4' && $bloc->getActif()  == true){
  192.                     $data = [ 'id' => $bloc->getId(),
  193.                               'actif' => $bloc->getActif(),
  194.                               'type'  => 'titre',
  195.                               'title' => $bloc->translate($_locale)->getContent2(),
  196.                               'mobile'=> $bloc->getActifMobile(), 
  197.                               'desktop'=> $bloc->getActifDesktop(), 
  198.                             ];
  199.                 }elseif($bloc->getTypeBloc() == '1' && $bloc->getActif()  == true){
  200.                     $data = [ 'id' => $bloc->getId(),
  201.                               'actif' => $bloc->getActif(),
  202.                               'type'  => 'text',
  203.                               'bg_color'=> $bloc->getBgColor(),
  204.                               'title' => $bloc->translate($_locale)->getTitle(),
  205.                               'content' => $bloc->translate($_locale)->getContent(),
  206.                               'libelle_lien'=> $bloc->translate($_locale)->getTitreLien(),
  207.                               'type_lien'=> $bloc->translate($_locale)->getTypeLien(),
  208.                               'lien_interne'=> $bloc->translate($_locale)->getLienInterne(),
  209.                               'lien_externe'=> $bloc->translate($_locale)->getLienExterne(),
  210.                               'telephone'=> $bloc->translate($_locale)->getTelephone(),
  211.                               'mobile'=> $bloc->getActifMobile(), 
  212.                               'desktop'=> $bloc->getActifDesktop(), 
  213.                             ];
  214.                 }elseif($bloc->getTypeBloc() == '10' && $bloc->getActif()  == true){
  215.                     $data = [ 'id' => $bloc->getId(),
  216.                               'actif' => $bloc->getActif(),
  217.                               'type'  => 'text2',
  218.                               'title' => $bloc->translate($_locale)->getTitle(),
  219.                               'content' => $bloc->translate($_locale)->getContent(),
  220.                               'position'=> $bloc->getPositionText(),
  221.                               'image'=> $bloc->getImage(),
  222.                               'url_video' => $bloc->getVideoUrl(),
  223.                               'grid'=> $bloc->getGridCarousel(),
  224.                               'mobile'=> $bloc->getActifMobile(), 
  225.                               'desktop'=> $bloc->getActifDesktop(), 
  226.                             ];
  227.                 }elseif($bloc->getTypeBloc() == '11' && $bloc->getActif() == true){
  228.                      $bloc_service $this->em->getRepository(BlocService::class)->findOneBy(['actif'=> true,'id'=>$bloc->getIdBlocService()]);
  229.                      $data = [  'id' => $bloc->getId(),
  230.                                 'actif' => $bloc->getActif(),
  231.                                 'type'  => 'bloc-service',
  232.                                 'data' => $bloc_service,
  233.                                 'mobile'=> $bloc->getActifMobile(), 
  234.                                 'desktop'=> $bloc->getActifDesktop(), 
  235.                               ];
  236.                      // $this->bloc_service_renderd = true;
  237.                       
  238.                 }elseif($bloc->getTypeBloc() == '12' && $bloc->getActif() == true){
  239.                      // $parametreSite = $this->em->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'ASC']);
  240.                       $param_partenaire $this->em->getRepository(ParametrePartenaires::class)->findOneBy(['actif'=> true]);
  241.                       $liste_partenaire $this->em->getRepository(Partenaires::class)->findBy(['actif'=> true],null,10);
  242.                       // $client = HttpClient::create();
  243.                       $request $this->requestStack->getCurrentRequest();
  244.                       $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  245.                       $partenaires null;
  246.                       // try {
  247.                       //     $response_api = $client->request('GET',
  248.                       //         $parametreSite->getDomainApiHrz().'/api/custom/all-partners-domain',
  249.                       //         [ 'headers' => ['Accept' => 'application/json'],
  250.                       //           'query' => [
  251.                       //             'domain' => $baseurl,
  252.                       //             'token' => $parametreSite->getTokenApiHrz(),
  253.                       //             ],
  254.                       //         ]);
  255.                       //     if ($response_api->getStatusCode() === 200) {
  256.                       //         $partenaires = $response_api->toArray()['data'];
  257.                       //     }
  258.                       // } catch (\Throwable $th) {
  259.                       //     //throw $th;
  260.                       //     //dump($th);
  261.                       // }
  262.                       $data = [ 'id' => $bloc->getId(),
  263.                                 'actif' => $bloc->getActif(),
  264.                                 'type'  => 'bloc-partenaire',
  265.                                 'data' => ['parametre'=> $param_partenaire,'liste_partenaire'=> $liste_partenaire,'partenaires'=> $partenaires,'baseurl' => $baseurl],
  266.                                 'mobile'=> $bloc->getActifMobile(), 
  267.                                 'desktop'=> $bloc->getActifDesktop(), 
  268.                               ];
  269.                 }elseif($bloc->getTypeBloc() == '13' && $bloc->getActif() == true){
  270.                   $activite_principal $this->em->getRepository(Activites::class)->findBy(['actif'=> true,'afficher_home'=> true]);
  271.                   $parametre $this->em->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'DESC']);
  272.                   $parametreRef $this->em->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
  273.                   $data = [ 'id' => $bloc->getId(),
  274.                             'actif'=> $bloc->getActif(),
  275.                             'type'=> 'bloc-activite',
  276.                             'type_affichage'=> $bloc->getAffichageBloc(),
  277.                             'activite_principal'=> $activite_principal,
  278.                             'parametreRef'=> $parametreRef,
  279.                             'parametre'=> $parametre,
  280.                             'mobile'=> $bloc->getActifMobile(), 
  281.                             'desktop'=> $bloc->getActifDesktop()];
  282.                 }elseif($bloc->getTypeBloc() == '14' && $bloc->getActif() == true){
  283.                   $secteurs $this->em->getRepository(Secteurs::class)->findBy(['actif'=> true]);
  284.                   $parametre $this->em->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'DESC']);
  285.                   $parametreRef $this->em->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
  286.                   $data = [ 'id' => $bloc->getId(),
  287.                             'actif'=> $bloc->getActif(),
  288.                             'type'=> 'bloc-secteur',
  289.                             'type_affichage'=> $bloc->getAffichageBloc(),
  290.                             'secteurs'=> $secteurs,
  291.                             'parametreRef'=> $parametreRef,
  292.                             'parametre'=> $parametre,
  293.                             'mobile'=> $bloc->getActifMobile(), 
  294.                             'desktop'=> $bloc->getActifDesktop()];
  295.                 }elseif($bloc->getTypeBloc() == '15' && $bloc->getActif() == true){
  296.                   $data_ref_page null;
  297.                   $ids_activite_secondaires $this->em->getRepository(ActiviteSecondaire::class)->findIdsActiviteSecondaireActif();
  298.                   if ($ids_activite_secondaires) {
  299.                     $data_ref_page $this->em->getRepository(Post::class)->findPageRefByIdsSousActivite($ids_activite_secondaires);
  300.                   }
  301.                   $parametre $this->em->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'DESC']);
  302.                   $parametreRef $this->em->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
  303.                   $data = [ 'id' => $bloc->getId(),
  304.                             'actif'=> $bloc->getActif(),
  305.                             'type'=> 'bloc-sous-activite',
  306.                             'type_affichage'=> $bloc->getAffichageBloc(),
  307.                             'activite_secondaires'=> $data_ref_page,
  308.                             'parametreRef'=> $parametreRef,
  309.                             'parametre'=> $parametre,
  310.                             'mobile'=> $bloc->getActifMobile(), 
  311.                             'desktop'=> $bloc->getActifDesktop()];
  312.                 }elseif($bloc->getTypeBloc() == '16' && $bloc->getActif() == true){
  313.                     $images = [];
  314.                     $ids_images explode(","$bloc->getIdsImagesGaleries());
  315.                     if ($ids_images) {
  316.                         foreach ($ids_images as $id) {
  317.                             if(!empty($id)){
  318.                                 $image $this->em->getRepository(MediaCms::class)->find($id);
  319.                                 if ($image) {
  320.                                    $path '/'.$image->getLocation().$image->getPath().$image->getFileName();
  321.                                    $this->imageService->thumbnail($path);
  322.                                    $images[] = ['id'=> $image->getId(),
  323.                                                 'path'=> $path,
  324.                                                 'lienexterne' => $image->getLienExterne(),
  325.                                                 'titre'=> $image->translate($_locale)->getTitre(),
  326.                                                 'description'=> $image->translate($_locale)->getDescription(),
  327.                                                 'description2'=> $image->translate($_locale)->getDescription2(),
  328.                                                 'extension_file' => pathinfo($image->getFileName(), PATHINFO_EXTENSION),
  329.                                                 'filter'=> 'asset_image'
  330.                                                ];
  331.                                 }
  332.                             }
  333.                         }
  334.                     }
  335.                     $template_model_galerie null;
  336.                     $modele_gallerie $this->em->getRepository(ModelGallerie::class)->findModelGallerie($bloc->getModelAffichageGaleries());
  337.                     if($modele_gallerie){
  338.                       $template_model_galerie $modele_gallerie['twig'];
  339.                     }
  340.                
  341.                     
  342.                     $data = [ 'id' => $bloc->getId(),
  343.                               'actif'=> $bloc->getActif(),
  344.                               'type'=> 'bloc-gallerie',
  345.                               'model_galerie'=> $template_model_galerie,
  346.                               'galleries'=> $images,
  347.                               'modele_galerie'=> $bloc->getModelAffichageGaleries(),
  348.                               'mobile'=> $bloc->getActifMobile(), 
  349.                               'desktop'=> $bloc->getActifDesktop()];
  350.                 }else{
  351.                     if($bloc->getActif() == true){
  352.                       $data = [ 'id' => $bloc->getId(),
  353.                                 'actif' => $bloc->getActif(),
  354.                                 'type'  => $bloc->getTypeBloc(),
  355.                                 'title' => $bloc->translate($_locale)->getTitle(),
  356.                                 'content' => $bloc->translate($_locale)->getContent(),
  357.                                 'content2' => $bloc->translate($_locale)->getContent2(),
  358.                                 'link'=> $bloc->translate($_locale)->getLink(),
  359.                                 'mobile'=> $bloc->getActifMobile(), 
  360.                                 'desktop'=> $bloc->getActifDesktop(), 
  361.                               ];
  362.                     }
  363.    
  364.                 }
  365.   
  366.                 if(!empty($data)){
  367.                   $data_Bloc[] = $data
  368.                 }
  369.             }
  370.         }
  371.         if($post){
  372.             if ($type == 'post') {
  373.               $data_post = [
  374.                 'id' => $post->getId(),
  375.                 'actif'=> $post->getActif(),
  376.                 'image'=> $post->getImage(),
  377.                 'title'=> $post->translate($_locale)->getTitle(),
  378.                 'slug'=> $post->translate($_locale)->getSlug(),
  379.                 'summary'=> $post->translate($_locale)->getSummary(),
  380.                 'content'=> $post->translate($_locale)->getContent(),
  381.                 'MetaTitle'=> $post->translate($_locale)->getMetaTitle(),
  382.                 'MetaDescription'=> $post->translate($_locale)->getMetaDescription(),
  383.                 'MetaKeys'=> $post->translate($_locale)->getMetaKeys(),
  384.                 'TagManagerhead'=> $post->getTagManagerhead(),
  385.                 'TagManagerbody'=> $post->getTagManagerbody(),
  386.                 'Bloc'=> $data_Bloc,
  387.               ];
  388.             }else{
  389.               $data_post = [
  390.                 'id' => $post->getId(),
  391.                 'actif'=> $post->getActif(),
  392.                 'image'=> $post->getImage(),
  393.                 'title'=> $post->translate($_locale)->getTitreCategorie(),
  394.                 'slug'=> $post->translate($_locale)->getSlugUrl(),
  395.                 'summary'=> $post->translate($_locale)->getChapeauCategorie(),
  396.                 'content'=> $post->translate($_locale)->getTexteCategorie(),
  397.                 'MetaTitle'=> $post->translate($_locale)->getMetaTitle(),
  398.                 'MetaDescription'=> $post->translate($_locale)->getMetaDescription(),
  399.                 'MetaKeys'=> $post->translate($_locale)->getMetaKeywords(),
  400.                 'TagManagerhead'=> $post->getTagManagerhead(),
  401.                 'TagManagerbody'=> $post->getTagManagerbody(),
  402.                 'Bloc'=> $data_Bloc,
  403.               ];
  404.             }
  405.         }
  406.         return $data_post;
  407.     }
  408.     public function renderTemplate($bloc,$schemaOrg){
  409.         $_locale Locale::getDefault();
  410.         $widget $bloc->getWidget();
  411.         $singel_post  $widget->getSingelPost();
  412.         $module $widget->getModules();
  413.         $template null;
  414.         $parametre $this->em->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
  415.         
  416.         if ($module == 'Poste') {
  417.             if($singel_post === false){
  418.               $type $widget->getTypePost();
  419.               $option $widget->getOptionAffichage(); 
  420.               $nb $widget->getNbPost();
  421.               $resultat = [];
  422.               $posts $this->em->getRepository(Post::class)->findPostActifsHomeByType($type,$option,$nb,$widget->getAllArticle());
  423.               
  424.               if ($posts) {
  425.                   foreach ($posts as $value) {
  426.                       $categorie_principal $this->em->getRepository(PostCategory::class)->findOneBy(['Post'=> $value->getId()],['id'=> 'asc']);
  427.                       $galleries_first_image $this->affichageGallerieService->FirstGallerieImagePost($value);
  428.                       // Champs personnalisés
  429.                       $champsPersonnalisesPost = [];
  430.                       $champsPersonnalisesPost $this->functionService->getChampsPersonnalisesPost($value);
  431.                       $resultat[] = ['image'=> $value->getImage(),
  432.                                     'imagealt'=> $value->translate($_locale)->getImageAlt(),
  433.                                     'image_couverture'=> $value->getImageCouverture(),
  434.                                     'summary'=> $value->translate($_locale)->getSummary(),
  435.                                     'slug_categorie_parent'=> $categorie_principal?$categorie_principal->getCategory()->translate($_locale)->getSlugUrl():null,
  436.                                     'page_produit'=> $type->translate($_locale)->getSystemName() == 'produits'?true:false,
  437.                                     'slug'=> $value->translate($_locale)->getSlug(),
  438.                                     'titre'=> $value->translate($_locale)->getTitle(),
  439.                                     'title_affichage'=> $value->translate($_locale)->getTitleAffichage(),
  440.                                     'typelien'=> $value->translate($_locale)->getTypeLien(),
  441.                                     'titrelien'=> $value->translate($_locale)->getTitreLien(),
  442.                                     'telephone'=> $value->translate($_locale)->getTelephone(),
  443.                                     'lieninterne'=> $value->translate($_locale)->getLienInterne(),
  444.                                     'lienexterne'=> $value->translate($_locale)->getLienExterne(),
  445.                                     'content'=> $value->translate($_locale)->getContent(),
  446.                                     'galleries_first_image'=> $galleries_first_image,
  447.                                     'champsPersonnalisesPost' => $champsPersonnalisesPost
  448.                                     ];
  449.                   }
  450.               }
  451.               if ($widget->getWidgetModelId() == 1) {
  452.                   $affiche $widget->getTypeAffichageHome();
  453.                   
  454.                   $template $this->templating->render('front/'.$this->theme.'/modele/bloc_articles.html.twig',[
  455.                     'resultats'=> $resultat,
  456.                     'widget'=> $widget
  457.                     'parametre' => $parametre,
  458.                     'template' =>$affiche
  459.                   ]);
  460.               }elseif($widget->getWidgetModelId() == 18){
  461.                   $template $this->templating->render('front/'.$this->theme.'/modele/bloc_associes.html.twig',[
  462.                     'widget'=> $widget
  463.                     'resultat'=> $resultat,
  464.                     'parametre' => $parametre,
  465.                     'widget'=> $widget,      
  466.                   ]);
  467.               }elseif($widget->getWidgetModelId() == 19){
  468.                   $template $this->templating->render('front/'.$this->theme.'/modele/bloc_faqs_random.html.twig',[
  469.                     'widget'=> $widget
  470.                     'resultat'=> $resultat,
  471.                     'widget'=> $widget,      
  472.                   ]);
  473.               }elseif ($widget->getWidgetModelId() == 20) {
  474.                   
  475.                   $affiche $widget->getTypeAffichageHome();
  476.                   $template $this->templating->render('front/'.$this->theme.'/modele/bloc_produits.html.twig',[
  477.                     'widget'=> $widget
  478.                     'resultats'=> $resultat,
  479.                     'widget'=> $widget,  
  480.                     'template' => $affiche    
  481.                   ]);
  482.               }
  483.            
  484.             }elseif ($singel_post === true &&  $widget->getWidgetModelId() == 2) {
  485.               $template $this->templating->render('front/'.$this->theme.'/modele/parallax.html.twig',[
  486.                 'widget'=> $widget,      
  487.               ]);
  488.             }elseif($singel_post === true &&  $widget->getWidgetModelId() == 3){
  489.                 $template $this->templating->render('front/'.$this->theme.'/modele/bloc_content.html.twig',[
  490.                   'widget'=> $widget,    
  491.                   'bloc_service_existe'=> $this->bloc_service_renderd       
  492.                 ]);
  493.             }elseif($singel_post === true &&  $widget->getWidgetModelId() == 4){
  494.               $template $this->templating->render('front/'.$this->theme.'/modele/bloc_presentation.html.twig',[
  495.                 'widget'=> $widget
  496.                 'bloc_service_existe'=> $this->bloc_service_renderd     
  497.               ]);
  498.           }elseif ($singel_post === true &&  $widget->getWidgetModelId() == 5) {
  499.             $template $this->templating->render('front/'.$this->theme.'/modele/bandeau_image.html.twig',[
  500.               'widget'=> $widget,      
  501.             ]);
  502.             }
  503.         }elseif($module == 'Faqs') {
  504.             $option $widget->getOptionAffichage(); 
  505.             $nb $widget->getNbPost();
  506.             $id_module $widget->getIdModule();
  507.             $faqs = [];
  508.             if($widget->getAlias() == "questions-reponses-automatiques"){
  509.    
  510.                 if ($bloc instanceof CategoryBloc) {
  511.                   $CategoryFaq $this->em->getRepository(CategoryFaq::class)->findFaqsAutomatiqueByWidget($option$bloc->getCategory()->getId());
  512.                   if($CategoryFaq){
  513.                     foreach ($CategoryFaq as $CategoryFaqItem) {
  514.                       if ($CategoryFaqItem->getFaq()->translate($_locale)->getActif()) {
  515.                         $faqs[] = $CategoryFaqItem->getFaq();
  516.                       }
  517.                  
  518.                     }
  519.                   }
  520.                 }else{
  521.                   $PostFaq $this->em->getRepository(PostFaq::class)->findFaqsAutomatiqueByWidget($option$bloc->getPost()->getId());
  522.                   if($PostFaq){
  523.                     foreach ($PostFaq as $PostFaqItem) {
  524.                       if ($PostFaqItem->getFaq()->translate($_locale)->getActif()) {
  525.                         $faqs[] = $PostFaqItem->getFaq();
  526.                       }
  527.             
  528.                     }
  529.                   }
  530.                 }
  531.           
  532.             }else{
  533.               if ($singel_post) {
  534.                 $faqs $this->em->getRepository(Faqs::class)->findFaqsByWidget($option,$nb,$id_module);
  535.               }else{
  536.                 $faqs $this->em->getRepository(Faqs::class)->findFaqsByWidget($option,$nb,null,$widget->getAllArticle());
  537.               }
  538.             }
  539.             if ($faqs && $schemaOrg != null) {
  540.                 $schemaOrg_faq_items = [];
  541.                 foreach ($faqs as $value) {
  542.                   $schemaOrg_faq_items[] = Schema::Question()
  543.                                                 ->name($value->getQuestion())
  544.                                                 ->acceptedAnswer(Schema::Answer()->text(strip_tags(str_replace("\"""'"$value->getReponse()))));
  545.                 }
  546.                 if (!empty($schemaOrg_faq_items) && !array_key_exists("Spatie\SchemaOrg\FAQPage"$schemaOrg->getNodes())) {
  547.                     $schemaOrg->add(Schema::FAQPage()->mainEntity($schemaOrg_faq_items));
  548.                 }  
  549.             }
  550.             if ($widget->getWidgetModelId() == 15) {
  551.               $template $this->templating->render('front/'.$this->theme.'/modele/bloc_questions_reponse_carousel.html.twig',[
  552.                 'faqs'=> $faqs,
  553.                 'widget'=> $widget
  554.               ]);
  555.             }elseif ($widget->getWidgetModelId() == 17) {
  556.               $template $this->templating->render('front/'.$this->theme.'/modele/bloc_questions_reponse_collapse.html.twig',[
  557.                 'faqs'=> $faqs,
  558.                 'widget'=> $widget
  559.               ]);
  560.             }
  561.         }elseif($module == 'Videos'){
  562.             $option $widget->getOptionAffichage(); 
  563.             $nb $widget->getNbPost();
  564.             $id_module $widget->getIdModule();
  565.             if ($singel_post) {
  566.               $videos $this->em->getRepository(Videos::class)->findVideosByWidget($option,$nb,$id_module);
  567.             }else{
  568.               $videos $this->em->getRepository(Videos::class)->findVideosByWidget($option,$nb,null,$widget->getAllArticle());
  569.             }
  570.             $key_api_youtube 'AIzaSyCEZzFBZ_SGHsZgPrBgq4wYhx2YlgvHpUA';
  571.             if ($videos && $schemaOrg != null) {
  572.                 $list_items_video = [];
  573.                 $position_items_video 1;
  574.                 foreach ($videos as $value) {
  575.                   preg_match("/.*v=(.*)/"$value->getVideo(),$match);
  576.                   if (isset($match[1])) {
  577.                        $id_video $match[1];
  578.                        try {
  579.                         $response_api_youtube $this->client->request(
  580.                             'GET',
  581.                             'https://www.googleapis.com/youtube/v3/videos?id='.$id_video.'&key='.$key_api_youtube.'&part=snippet,statistics&fields=items(id,snippet,statistics)'
  582.                         );
  583.                         
  584.                         if ($response_api_youtube->getStatusCode() == 200) {
  585.                                 $content $response_api_youtube->toArray();
  586.                                 $data_video $content['items'][0]['snippet'];
  587.                                 $list_items_video[] = Schema::ListItem()
  588.                                                     ->position($position_items_video)
  589.                                                     ->item(Schema::VideoObject()
  590.                                                             ->name($data_video['title'])
  591.                                                             ->description($data_video['description'])
  592.                                                             ->thumbnailUrl($data_video['thumbnails']['default']['url'])
  593.                                                             ->uploadDate($data_video['publishedAt'])
  594.                                                             ->embedUrl("https://www.youtube.com/embed/".$id_video)
  595.                                                             ->contentUrl("https://www.youtube.com/watch?v=".$id_video));
  596.                                 $position_items_video++;
  597.                             }
  598.                         } catch (\Throwable $th) {
  599.                         }
  600.                   }
  601.                 }
  602.                 if (!empty($list_items_video)) {
  603.                    $schemaOrg->add(Schema::ItemList()->itemListElement($list_items_video));
  604.                 }  
  605.             }
  606.             $template $this->templating->render('front/'.$this->theme.'/modele/bloc_videos.html.twig',[
  607.               'videos'=> $videos,
  608.               'widget'=> $widget
  609.             ]);
  610.         }
  611.         return $template;
  612.     }
  613. }