src/Controller/FrontEnd/FeatureController.php line 141

Open in your IDE?
  1. <?php
  2. namespace App\Controller\FrontEnd;
  3. use App\Entity\Menu;
  4. use App\Entity\Forms;
  5. use App\Entity\Contact;
  6. use App\Entity\Country;
  7. use App\Entity\Language;
  8. use App\Entity\Secteurs;
  9. use App\Entity\FormsData;
  10. use App\Entity\GroupBloc;
  11. use App\Entity\ListeMenu;
  12. use App\Entity\FormsFields;
  13. use App\Entity\ParamContact;
  14. use App\Entity\ParametreRef;
  15. use App\Entity\ThemeOptions;
  16. use App\Entity\ParametreSite;
  17. use App\Entity\ProduitOption;
  18. use App\Entity\ReseauSociaux;
  19. use App\Entity\TelephonesClick;
  20. use App\Entity\TextParametrable;
  21. use App\Service\NestedTreeStructure;
  22. use Doctrine\ORM\EntityManagerInterface;
  23. use App\Entity\TextParametrableTranslation;
  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\Component\HttpFoundation\JsonResponse;
  29. use Symfony\Contracts\HttpClient\HttpClientInterface;
  30. use Symfony\Component\Translation\TranslatorInterface;
  31. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  32. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  33. class FeatureController extends AbstractController
  34. {
  35. private $theme;
  36. private $client;
  37. private $projectDirr;
  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("lang/{language}", name="setlocale_langauge")
  46. */
  47. public function setLocaleLangAction(Request $request,$language = null)
  48. {
  49. if($language != null)
  50. {
  51. $request->getSession()->set('_locale', $language);
  52. }
  53. return $this->redirectToRoute('index_page_home',['_locale'=> $language]);
  54. }
  55. /**
  56. * @Route("/track-phone-click", methods={"POST"}, name="track_phone_click", condition="request.isXmlHttpRequest()")
  57. */
  58. public function trackPhoneClick(Request $request,EntityManagerInterface $em)
  59. {
  60. if ($request->isXmlHttpRequest()) {
  61. $_locale = $request->getLocale();
  62. $parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'ASC']);
  63. if($parametre){
  64. $nb_click = $parametre->getNbClickTel() != null ?$parametre->getNbClickTel():'0';
  65. $parametre->setNbClickTel($nb_click + 1);
  66. $em->flush();
  67. }
  68. return new JsonResponse(['message'=> 'Phone click saved successfully']);
  69. }
  70. }
  71. public function renderMenu(Request $request,NestedTreeStructure $buildTree,$className= ''){
  72. $_locale = $request->getLocale();
  73. $data_menu_right = [];
  74. $ListMenu_rigth = [];
  75. $data_menu_left = [];
  76. $ListMenu_left = [];
  77. $theme_option = $this->getDoctrine()->getRepository(ThemeOptions::class)->findOneBy(['theme'=> $this->theme]);
  78. $languages = $this->getDoctrine()->getRepository(Language::class)->findActifLang();
  79. $Menu_right = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=>'Header-right','IdSite'=> '1']);
  80. $Menu_left = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=>'Header-left','IdSite'=> '1']);
  81. $contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  82. $contacts_noms = [];
  83. if($contacts){
  84. foreach ($contacts as $contact) {
  85. $contacts_noms[] = ['id'=> $contact->getId(),
  86. 'nomContact'=> $contact->translate($_locale)->getNomContact(),
  87. ];
  88. }
  89. }
  90. $socials = $this->getDoctrine()->getRepository(ReseauSociaux::class)->findAll();
  91. if($Menu_right){
  92. $ListMenu_rigth = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_right->getId());
  93. $data_menu_right = $buildTree->buildMenu($ListMenu_rigth);
  94. }
  95. if($Menu_left){
  96. $ListMenu_left = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_left->getId());
  97. $data_menu_left = $buildTree->buildMenu($ListMenu_left);
  98. }
  99. return $this->render('theme/'.$this->theme.'/partials/_header.html.twig',[
  100. 'menu_right'=> $data_menu_right,
  101. 'menu_left'=> $data_menu_left,
  102. 'languages'=> $languages,
  103. 'className'=> $className,
  104. 'theme_option'=> $theme_option,
  105. 'contacts'=> $contacts,
  106. 'contactsInfos'=> $contacts_noms,
  107. 'socials'=> $socials,
  108. 'menuDetails' => $ListMenu_rigth,
  109. 'locale'=> $_locale
  110. ]);
  111. }
  112. public function renderFooter(Request $request,$TypeMenu,NestedTreeStructure $buildTree){
  113. $_locale = $request->getLocale();
  114. $menusFooter = null;
  115. $menusFooterBas = null;
  116. $contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  117. $parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'ASC']);
  118. $data_menu_footer = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=> 'Footer']);
  119. if ($data_menu_footer) {
  120. $menu_items = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($data_menu_footer->getId());
  121. $menusFooterBas = $buildTree->buildMenu($menu_items);
  122. };
  123. $data_menu_footer_bas = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=> 'Menu-Footer']);
  124. if ($data_menu_footer_bas) {
  125. $menu_items = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($data_menu_footer_bas->getId());
  126. $menusFooter = $buildTree->buildMenu($menu_items);
  127. }
  128. $socials = $this->getDoctrine()->getRepository(ReseauSociaux::class)->findAll();
  129. return $this->render('theme/'.$this->theme.'/partials/_footer.html.twig',[
  130. 'contacts'=> $contacts,
  131. 'parametre'=> $parametre,
  132. 'menusFooter'=> $menusFooter,
  133. 'menusFooterBas'=> $menusFooterBas,
  134. 'socials'=> $socials
  135. ]);
  136. }
  137. public function displayContactsList(){
  138. $param_contact = $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
  139. $content_bloc = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  140. return $this->render('theme/'.$this->theme.'/component-blocks/contacts-listing-block.html.twig',[
  141. 'content_bloc'=> $content_bloc,
  142. 'param_contact'=> $param_contact,
  143. ]);
  144. }
  145. public function displayContactHoursPage(){
  146. $content_bloc = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  147. return $this->render('theme/'.$this->theme.'/component-blocks/contact-hours-block.html.twig',[
  148. 'content_bloc'=> $content_bloc,
  149. ]);
  150. }
  151. public function displayContactMap(){
  152. $param_contact = $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
  153. $contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  154. return $this->render('theme/'.$this->theme.'/component-blocks/contact-map-block.html.twig',[
  155. 'contacts'=> $contacts,
  156. 'param_contact'=> $param_contact,
  157. ]);
  158. }
  159. public function displayOpenStreetMapWithContacts(){
  160. $param_contact = $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
  161. $contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
  162. return $this->render('theme/'.$this->theme.'/component-blocks/osm-map-block.html.twig',[
  163. 'contacts'=> $contacts,
  164. 'param_contact'=> $param_contact,
  165. ]);
  166. }
  167. }