src/Controller/Front/FunctionController.php line 49

Open in your IDE?
  1. <?php 
  2. namespace App\Controller\Front;
  3. use App\Entity\Menu;
  4. use App\Entity\Country;
  5. use App\Entity\Language;
  6. use App\Entity\Secteurs;
  7. use App\Entity\GroupBloc;
  8. use App\Entity\ListeMenu;
  9. use App\Service\BuildTree;
  10. use App\Entity\ParametreRef;
  11. use App\Entity\ThemeOptions;
  12. use App\Entity\ParametreSite;
  13. use App\Entity\ProduitOption;
  14. use App\Entity\ReseauSociaux;
  15. use App\Entity\Contact;
  16. use App\Entity\Forms;
  17. use App\Entity\FormsData;
  18. use App\Entity\FormsFields;
  19. use App\Entity\ParamContact;
  20. use App\Entity\TelephonesClick;
  21. use App\Entity\TextParametrable;
  22. use App\Entity\TextParametrableTranslation;
  23. use App\Service\RenderDefaultBloc;
  24. use Symfony\Component\Filesystem\Filesystem;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. use Symfony\Contracts\HttpClient\HttpClientInterface;
  29. use Symfony\Component\Translation\TranslatorInterface;
  30. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  31. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  32. use Symfony\Component\HttpFoundation\JsonResponse;
  33. class FunctionController  extends AbstractController
  34. {
  35.     private $theme;
  36.     private $client;
  37.     private $projectDirr;
  38.     
  39.     public function __construct(string $theme,HttpClientInterface $client,string $projectDirr)
  40.     {
  41.         $this->theme $theme;
  42.         $this->client $client;
  43.         $this->projectDirr $projectDirr;
  44.     }
  45.     public function renderMenu(Request $request,BuildTree $buildTree,$className){
  46.         $_locale $request->getLocale();
  47.         $data_menu_right = [];
  48.         $theme_option $this->getDoctrine()->getRepository(ThemeOptions::class)->findOneBy(['theme'=> $this->theme]);
  49.         $languages $this->getDoctrine()->getRepository(Language::class)->findActifLang();
  50.         $Menu_right $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=>'Header-right','IdSite'=> '1']);
  51.         
  52.         $contacts $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  53.         $contacts_noms = [];
  54.         if($contacts){
  55.             foreach ($contacts as $contact) {
  56.                 $contacts_noms[] = ['id'=> $contact->getId(),
  57.                                     'nomContact'=> $contact->translate($_locale)->getNomContact(),
  58.                                    ];
  59.             }
  60.         }
  61.         
  62.         $social $this->getDoctrine()->getRepository(ReseauSociaux::class)->findBy(['site'=> '1']);
  63.         
  64.         if($Menu_right){
  65.             $ListMenu_rigth $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_right->getId());
  66.             $data_menu_right $buildTree->buildMenu($ListMenu_rigth);
  67.         }
  68.       
  69.         return $this->render('front/'.$this->theme.'/partials/header/header.html.twig',[
  70.             'menu_right'=> $data_menu_right,
  71.             'languages'=> $languages,
  72.             'className'=> $className,
  73.             'theme_option'=> $theme_option,
  74.             'contacts'=> $contacts,
  75.             'contactsInfos'=> $contacts_noms,
  76.             'social'=> $social,
  77.             'menuDetails' => $ListMenu_rigth,
  78.             'locale'=>$_locale
  79.         ]);
  80.     } 
  81.     public function renderFooter(Request $request,$TypeMenu,BuildTree $buildTree){
  82.         $_locale $request->getLocale(); 
  83.         $data_menu = [];
  84.         $data_menu_footer = [];
  85.         $languages $this->getDoctrine()->getRepository(Language::class)->findActifLang();
  86.         $theme_option $this->getDoctrine()->getRepository(ThemeOptions::class)->findOneBy(['theme'=> $this->theme]);
  87.         $contacts $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  88.         $image_map $this->getDoctrine()->getRepository(ParamContact::class)->find(1)->getImageMap();
  89.         $contacts_noms = [];
  90.         if($contacts){
  91.             foreach ($contacts as $contact) {
  92.                 $contacts_noms[] = ['id'=> $contact->getId(),
  93.                                     'nomContact'=> $contact->translate($_locale)->getNomContact(),
  94.                                    ];
  95.             }
  96.         }
  97.         $Menu $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=>$TypeMenu,'IdSite'=> '1']);
  98.         $social $this->getDoctrine()->getRepository(ReseauSociaux::class)->findBy(['site'=> '1']);
  99.         
  100.         if($Menu){
  101.             $ListMenu $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu->getId());
  102.             $data_menu $buildTree->buildMenu($ListMenu);
  103.         }  
  104.         
  105.         $Menu_footer_top $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=> 'Menu-Footer','IdSite'=> '1']);
  106.         
  107.         if ($Menu_footer_top) {
  108.             $ListMenuFooter $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_footer_top->getId());
  109.             $data_menu_footer $buildTree->buildMenu($ListMenuFooter);
  110.         }
  111.        
  112.         /* $form = $this->getDoctrine()->getRepository(Forms::class)->findOneBy(['identifier' => 'form-footer']);
  113.         $formfields = $this->getDoctrine()->getRepository(FormsFields::class)->findOneBy(['form' => $form->getId()]); */
  114.         
  115.         $parametre $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
  116.         $secteurs $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=>true],['position'=>'ASC']);
  117.         $parametreRef $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
  118.         /* $formsfieldsData = [];
  119.          if($formfields){
  120.             $formsfieldsData = unserialize($formfields->getData());
  121.         } */
  122.         
  123.         return $this->render('front/'.$this->theme.'/partials/footer/footer.html.twig',[
  124.             'menus'=> $data_menu,
  125.             'social'=> $social,
  126.             'parametreRef'=> $parametreRef,
  127.             'secteurs'=> $secteurs,
  128.             'languages'=> $languages,
  129.             'parametre'=> $parametre,
  130.             'theme_option'=> $theme_option,
  131.             'contacts'=> $contacts,
  132.             'contactsInfos'=> $contacts_noms,
  133.             'data_menu_footer'=> $data_menu_footer,
  134.             'image_map' => $image_map,
  135.             /* 'form' => $form,
  136.             'formfields' => $formsfieldsData, */
  137.         ]);
  138.     } 
  139.     public function renderDefaultBloc(RenderDefaultBloc $defaultBloc){
  140.         
  141.         $default_bloc $defaultBloc->RenderBloc();
  142.         return $this->render('front/'.$this->theme.'/bloc/render_bloc_default.html.twig',[
  143.             'default_bloc'=> $default_bloc,
  144.         ]);
  145.     }
  146.     // public function renderDefaultBloc($alias,RenderDefaultBloc $defaultBloc){
  147.         
  148.     //     $data_default_bloc = null;
  149.     //     $default_bloc = $this->getDoctrine()->getRepository(GroupBloc::class)->findOneBy(['alias'=>$alias]);
  150.         
  151.     //     if($default_bloc){
  152.     //         $data_default_bloc = $defaultBloc->RenderBloc($default_bloc);
  153.     //     }
  154.     //     return $this->render('front/'.$this->theme.'/bloc/render_bloc_default.html.twig',[
  155.     //         'data_default_bloc'=> $data_default_bloc,
  156.     //     ]);
  157.     // }
  158.     public function renderTextParametrable($id){
  159.         $content_bloc $this->getDoctrine()->getRepository(TextParametrableTranslation::class)->findOneBy(['id'=>$id]);
  160.  
  161.         return $this->render('front/'.$this->theme.'/bloc/texte-parametrable.html.twig',[
  162.             'content_bloc'=> $content_bloc,
  163.         ]);
  164.     }
  165.      public function renderTemplateParametrable($id){
  166.         $content_bloc $this->getDoctrine()->getRepository(TextParametrableTranslation::class)->findOneBy(['id'=>$id]);
  167.  
  168.         return $this->render('front/'.$this->theme.'/bloc/template-parametrable.html.twig',[
  169.             'content_bloc'=> $content_bloc,
  170.         ]);
  171.     }
  172.     public function renderTextCopyright($id){
  173.         $content_bloc $this->getDoctrine()->getRepository(TextParametrableTranslation::class)->findOneBy(['id'=>$id]);
  174.  
  175.         return $this->render('front/'.$this->theme.'/bloc/texte-copyright.html.twig',[
  176.             'content_bloc'=> $content_bloc,
  177.         ]);
  178.     }
  179.     public function renderTitreMenuFooter($id){
  180.         $content_bloc $this->getDoctrine()->getRepository(TextParametrableTranslation::class)->findOneBy(['id'=>$id]);
  181.  
  182.         return $this->render('front/'.$this->theme.'/bloc/titre-menu-footer.html.twig',[
  183.             'content_bloc'=> $content_bloc,
  184.         ]);
  185.     }
  186.     public function renderContacts(){
  187.        
  188.         $param_contact $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
  189.         $content_bloc $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  190.         return $this->render('front/'.$this->theme.'/bloc/liste-contacts.html.twig',[
  191.             'content_bloc'=> $content_bloc,
  192.             'param_contact'=> $param_contact,
  193.         ]);
  194.     }
  195.     public function renderHorairesPageContact(){
  196.        
  197.         $content_bloc $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  198.         return $this->render('front/'.$this->theme.'/bloc/horaires-contacts.html.twig',[
  199.             'content_bloc'=> $content_bloc,
  200.         ]);
  201.     }
  202.     public function renderMapContact(){
  203.        
  204.         $param_contact $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
  205.         $contacts $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  206.         return $this->render('front/'.$this->theme.'/bloc/map-contact.html.twig',[
  207.             'contacts'=> $contacts,
  208.             'param_contact'=> $param_contact,
  209.         ]);
  210.     }
  211.     public function renderHeaderLp(Request $request,BuildTree $buildTree){
  212.         $_locale $request->getLocale();
  213.         $parametre $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'ASC']);
  214.       
  215.         return $this->render('front/'.$this->theme.'/landing-page/header.html.twig',[
  216.             'parametre'=> $parametre,
  217.         ]);
  218.     } 
  219.     public function renderFooterLp(Request $request,$TypeMenu,BuildTree $buildTree){
  220.         $_locale $request->getLocale(); 
  221.         $data_menu = [];
  222.         $data_menu_footer = [];
  223.         $languages $this->getDoctrine()->getRepository(Language::class)->findActifLang();
  224.         $theme_option $this->getDoctrine()->getRepository(ThemeOptions::class)->findOneBy(['theme'=> $this->theme]);
  225.         $contacts $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  226.         $image_map $this->getDoctrine()->getRepository(ParamContact::class)->find(1)->getImageMap();
  227.         if($contacts){
  228.             foreach ($contacts as $contact) {
  229.                 $contacts_noms[] = ['id'=> $contact->getId(),
  230.                                     'nomContact'=> $contact->translate($_locale)->getNomContact(),
  231.                                    ];
  232.             }
  233.         }
  234.         $Menu $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=>$TypeMenu,'IdSite'=> '1']);
  235.         $social $this->getDoctrine()->getRepository(ReseauSociaux::class)->findBy(['site'=> '1']);
  236.         
  237.         if($Menu){
  238.             $ListMenu $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu->getId());
  239.             $data_menu $buildTree->buildMenu($ListMenu);
  240.         }  
  241.         
  242.         $Menu_footer_top $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=> 'Menu-Footer','IdSite'=> '1']);
  243.         
  244.         if ($Menu_footer_top) {
  245.             $ListMenuFooter $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_footer_top->getId());
  246.             $data_menu_footer $buildTree->buildMenu($ListMenuFooter);
  247.         }
  248.        
  249.         /* $form = $this->getDoctrine()->getRepository(Forms::class)->findOneBy(['identifier' => 'form-footer']);
  250.         $formfields = $this->getDoctrine()->getRepository(FormsFields::class)->findOneBy(['form' => $form->getId()]); */
  251.         
  252.         $parametre $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
  253.         $secteurs $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=>true],['position'=>'ASC']);
  254.         $parametreRef $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
  255.         /* $formsfieldsData = [];
  256.          if($formfields){
  257.             $formsfieldsData = unserialize($formfields->getData());
  258.         } */
  259.         
  260.         return $this->render('front/'.$this->theme.'/landing-page/footer.html.twig',[
  261.             'menus'=> $data_menu,
  262.             'social'=> $social,
  263.             'parametreRef'=> $parametreRef,
  264.             'secteurs'=> $secteurs,
  265.             'languages'=> $languages,
  266.             'parametre'=> $parametre,
  267.             'theme_option'=> $theme_option,
  268.             'contacts'=> $contacts,
  269.             'contactsInfos'=> $contacts_noms,
  270.             'data_menu_footer'=> $data_menu_footer,
  271.             'image_map' => $image_map,
  272.             /* 'form' => $form,
  273.             'formfields' => $formsfieldsData, */
  274.         ]);
  275.     } 
  276.     /**
  277.      * @Route("/clic-telephone", name="click_telephone")
  278.      */
  279.     public function EnregistrerClickTel(Request $request)
  280.     {
  281.         $numTel $request->request->get('phoneNumber');
  282.         $clientIp $request->getClientIp();
  283.         $dateClick = new \DateTime();
  284.         $checkClickTelByIpDate $this->getDoctrine()->getRepository(TelephonesClick::class)->findBy(['ip'=>$clientIp,'telephone'=>$numTel]);
  285.         $clickByIpAfterTime true;
  286.         if($checkClickTelByIpDate){
  287.             foreach ($checkClickTelByIpDate as $element) {
  288.                 if($dateClick->diff($element->getDate())-><= 24){
  289.                     $clickByIpAfterTime false;
  290.                     return new JsonResponse('Veillez essayer après une durée');
  291.                 }
  292.             }
  293.         }
  294.         if($clickByIpAfterTime){
  295.             $clickTel = new TelephonesClick();
  296.             $em $this->getDoctrine()->getManager();
  297.             $clickTel->setIp($clientIp);
  298.             $clickTel->setDate($dateClick);
  299.             $clickTel->setTelephone($numTel);
  300.             $em->persist($clickTel);
  301.             $em->flush(); 
  302.         }
  303.         return new JsonResponse('Click enregistré');
  304.     }
  305. }