src/Controller/PartialController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use App\Controller\AbstractController;
  6. use App\Entity\Categorie;
  7. use App\Entity\Demande;
  8. use App\Entity\Page;
  9. use Sabre\Xml\Reader as XmlReader;
  10. class PartialController extends AbstractController
  11. {
  12. public function categoriesMenu()
  13. {
  14. /** @var PageRepository $repository */
  15. $repository = $this->getPageRepository();
  16. $pages = $repository->getCategorieTree();
  17. return $this->render('Partial/categories_menu.html.twig', array(
  18. 'pages' => $pages
  19. ));
  20. }
  21. public function preDemande()
  22. {
  23. $preForm = $this->getDemandeForm(new Demande(), true);
  24. return $this->render('Partial/pre_demande.html.twig', array(
  25. 'demande_form' => $preForm->createView()
  26. ));
  27. }
  28. public function bandeau()
  29. {
  30. $em = $this->getEm();
  31. $page = $em->getRepository(Page::class)->find(205);
  32. return $this->render('Partial/bandeau.html.twig', ['page' => $page]);
  33. }
  34. public function lastDemandes()
  35. {
  36. $demandes = $this->getDemandeRepository()->getLastDemandes($this->getParameter('last_demandes_count'));
  37. return $this->render('Partial/last_demandes.html.twig', array(
  38. 'demandes' => $demandes,
  39. ));
  40. }
  41. public function indexCategories()
  42. {
  43. $pages = $this->getPageRepository()->getCategorieTree();
  44. return $this->render('Partial/categories_index.html.twig', array(
  45. 'pages' => $pages,
  46. 'groups' => array_flip($this->getParameter('category_groups'))
  47. ));
  48. }
  49. public function lastActus()
  50. {
  51. $curl = curl_init("https://blog.exacompare.fr/feed/");
  52. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  53. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  54. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0');
  55. $xml = curl_exec($curl);
  56. curl_close($curl);
  57. $reader = new XmlReader();
  58. $reader->xml($xml);
  59. $result = $reader->parse();
  60. foreach ($result['value'][0]['value'] ?? [] as $value):
  61. if ($value['name'] === '{}item'):
  62. $rss[] = $value;
  63. endif;
  64. endforeach;
  65. $feedCount = 0;
  66. $rssData = [];
  67. foreach ($rss as $entry) {
  68. foreach ($entry['value'] ?? [] as $element):
  69. if (ltrim($element['name'], '{}') === 'description'):
  70. $element['value'] = html_entity_decode(strip_tags($element['value']), ENT_QUOTES);
  71. endif;
  72. $news[ltrim($element['name'], '{}')] = $element['value'];
  73. endforeach;
  74. if ($feedCount == $this->getParameter('last_actus_count')) {
  75. break;
  76. }
  77. $rssData[] = [
  78. 'title' => $news['title'],
  79. 'description' => substr($news['description'], 0, strpos($news['description'], ' Lire la suite')),
  80. 'date_modified' => $news['pubDate'],
  81. 'authors' => $news['authors'] ?? null,
  82. 'link' => $news['link']
  83. ];
  84. $feedCount++;
  85. }
  86. return $this->render('Partial/last_actus.html.twig', array(
  87. 'rss' => $rssData ?? [],
  88. ));
  89. }
  90. public function footerMenu(Request $request)
  91. {
  92. // $texteQuiSommesNous = $this->getPageRepository()->findOneByType(Page::TYPE_INDEX)->getContent();
  93. return $this->render('Partial/footer_menu.html.twig', array(
  94. 'social_links' => array(
  95. 'facebook' => $this->getOption('facebook_url'),
  96. 'twitter' => $this->getOption('twitter_url'),
  97. // 'googleplus' => $this->getOption('googleplus_url')
  98. 'rss' => $this->getOption('rss_url')
  99. ),
  100. // 'texte_qui_sommes_nous' => $texteQuiSommesNous
  101. ));
  102. }
  103. public function preDemandeHeader(Request $request)
  104. {
  105. $session = $this->getSession();
  106. $demande = $session->get('demande');
  107. $public = $demande === null;
  108. $categorie = false;
  109. if (!$demande && $request->get('cid')) {
  110. $demande = new Demande();
  111. /** @var Demande $categorie */
  112. if ($categorie = $this->getCategorieRepository()->find($request->get('cid'))) {
  113. $demande->setCategorie($categorie);
  114. }
  115. } elseif ($demande && $request->get('cid')) {
  116. if ($demande->getCategorie()) {
  117. if ($demande->getCategorie()->getParent()) {
  118. $idCategorie = $demande->getCategorie()->getParent()->getId();
  119. } else {
  120. $idCategorie = $demande->getCategorie()->getId();
  121. }
  122. if ($request->get('cid') == $idCategorie) {
  123. $categorie = $demande->getCategorie();
  124. } else {
  125. $categorie = $this->getCategorieRepository()->find($request->get('cid'));
  126. $demande->setCategorie($categorie);
  127. }
  128. }
  129. } elseif (!$demande) {
  130. $demande = new Demande();
  131. }
  132. // Default categorie
  133. if (!$categorie) {
  134. $categorie = $this->getCategorieRepository()->find(72);
  135. }
  136. if ($categorie->getParent()) {
  137. $categorie = $this->getCategorieRepository()->find($categorie->getParent()->getId())->getNom();
  138. // $categorie = $categorie->getParent()->getNom();
  139. }
  140. $catGroup = strtok($categorie, " ");
  141. $unwanted_array = array( 'Š' => 'S', 'š' => 's', 'Ž' => 'Z', 'ž' => 'z', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E',
  142. 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U',
  143. 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c',
  144. 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o',
  145. 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'þ' => 'b', 'ÿ' => 'y' );
  146. $catGroup = strtr($catGroup, $unwanted_array);
  147. $demande->setBienType(null);
  148. $preForm = $this->getDemandeForm($demande, true, header: true);
  149. return $this->render('Partial/pre_demande_header.html.twig', array(
  150. 'demande_form' => $preForm->createView(),
  151. 'categorie' => $categorie,
  152. 'catGroup' => $catGroup
  153. ));
  154. }
  155. public function sideCategories(Request $request)
  156. {
  157. $pid = $request->get('pid');
  158. if (!$pid) {
  159. $parentId = $this->getCategorieRepository()->getPageIdByCatId($this->getParameter('group_diagnostics'));
  160. $parent = true;
  161. } else {
  162. /** @var Categorie $categorie */
  163. $page = $this->getPageRepository()->find($pid);
  164. if ($page->getParent()) {
  165. $parentId = $page->getParent()->getId();
  166. $parent = false;
  167. } else {
  168. $parentId = $page->getId();
  169. $parent = true;
  170. }
  171. }
  172. if ($parentId == 122) {
  173. $diag = true;
  174. } else {
  175. $diag = false;
  176. }
  177. // echo 'PARENT : ' . $parentId;
  178. $pages = $this->getPageRepository()->getCategoriesForSidebar($parentId);
  179. return $this->render('Partial/side_categories.html.twig', array(
  180. 'pages' => $pages,
  181. 'diag' => $diag,
  182. 'parent' => $parent,
  183. 'pid' => $request->get('pid')
  184. ));
  185. }
  186. public function localSidebar(Request $request)
  187. {
  188. $pid = $request->get('pid');
  189. if ($pid) {
  190. /** @var Page $page */
  191. $page = $this->getPageRepository()->find($pid);
  192. $parentId = $this->getCategorieRepository()->getPageIdByCatId($this->getParameter('group_diagnostics'));
  193. if ($page->getId() != $parentId && (!$page->getParent() || $page->getParent()->getId() != $parentId)) {
  194. return new Response('', Response::HTTP_NO_CONTENT);
  195. }
  196. }
  197. $pages = $this->getPageRepository()->getLocalPagesByCP(array(
  198. '33000', '59000', '69000', '13000', '34000', '44000', '06000', '75000', '67000', '31000'
  199. ));
  200. return $this->render('Partial/local_sidebar.html.twig', array(
  201. 'pages' => $pages
  202. ));
  203. }
  204. }