src\Controller\CartoController.php line 124

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use App\Service\PlatformService;
  9. use Firebase\JWT\JWT;
  10. /**
  11. * Class CartoController
  12. * @package App\Controller
  13. */
  14. class CartoController extends AbstractController
  15. {
  16. /**
  17. * @param Request $request
  18. * @return Response
  19. * @throws \Twig\Error\LoaderError
  20. * @throws \Twig\Error\RuntimeError
  21. * @throws \Twig\Error\SyntaxError
  22. * @Route("/", name="home")
  23. */
  24. public function renderInterface(Request $request) : Response
  25. {
  26. $atlasParams = $this->getParameter('atlasparam');
  27. return $this->render('index.html.twig', [
  28. 'atlas' => $atlasParams
  29. ]
  30. );
  31. }
  32. /**
  33. * @param Request $request
  34. * @return Response
  35. * @throws \Twig\Error\LoaderError
  36. * @throws \Twig\Error\RuntimeError
  37. * @throws \Twig\Error\SyntaxError
  38. * @Route("/query", name="query")
  39. */
  40. public function searchQuery(Request $request, PlatformService $platformService) : Response
  41. {
  42. $q = $request->query->get('q');
  43. $dataCompCommune = $this->getParameter('dc_commune');
  44. $q = str_replace("'", "''", $q);
  45. $query = "select \"id\", \"com_nom\", \"code_dep\" from com_dept where REPLACE(unaccent(LOWER(com_nom)), '-', ' ') like REPLACE(unaccent(LOWER('".$q."%')), '-', ' ')";
  46. $response = $platformService->callApiDC($dataCompCommune, $query);
  47. $output['results'] = [];
  48. foreach($response as $data){
  49. $output['results'][] = ['id' => $data[0], 'text' => $data[1] . " (". $data[2] .")", 'search' => $data[2]];
  50. }
  51. $output['pagination'] = ["more" => false ];
  52. return new JsonResponse($output);
  53. }
  54. /**
  55. * @param Request $request
  56. * @return Response
  57. * @throws \Twig\Error\LoaderError
  58. * @throws \Twig\Error\RuntimeError
  59. * @throws \Twig\Error\SyntaxError
  60. * @Route("/carto", name="carto")
  61. */
  62. public function renderInterfaceCarto(Request $request, PlatformService $platformService) : Response
  63. {
  64. $atlasParams = $this->getParameter('atlasparam');
  65. $token = $this->getParameter('token');
  66. $atlasParams['token'] = $token;
  67. $atlasParams['search'] = $request->query->get('q');
  68. $dataCompBase = $this->getParameter('dc_base');
  69. $query ="select \"code_insee\", \"Name\" ,\"code_dep\" from \"BA_DA_EAR\"";
  70. $response = $platformService->callApiDC($dataCompBase, $query);
  71. $output = [];
  72. $output['bases'] = [];
  73. foreach($response as $data){
  74. $output['bases'][] = ['id' => $data[0], 'text' => $data[1], 'search' => $data[2]];
  75. }
  76. $dataCompSSAFem = $this->getParameter('dc_ssa_fem');
  77. $query2 = "select \"Code Insee /FEM-Geo\", \"Libelle Long /FEM\", code_dep from \"Sites_SSA_FEM\" order by \"Libelle Long /FEM\"";
  78. $response2 = $platformService->callApiDC($dataCompSSAFem, $query2);
  79. $output['fem'] = [];
  80. foreach($response2 as $data){
  81. $output['fem'][] = ['id' => $data[0], 'text' => $data[1], 'search' => $data[2]];
  82. }
  83. $dataCompSSAFer = $this->getParameter('dc_ssa_fer');
  84. $query3 = "select \"Code Insee /FER-Geo\", \"Libelle Long /FER\", code_dep from \"Sites_SSA_FER\" order by \"Libelle Long /FER\"";
  85. $response3 = $platformService->callApiDC($dataCompSSAFer, $query3);
  86. $output['fer'] = [];
  87. foreach($response3 as $data){
  88. $output['fer'][] = ['id' => $data[0], 'text' => $data[1], 'search' => $data[2]];
  89. }
  90. return $this->render('carto.html.twig',
  91. [
  92. 'atlas' => $atlasParams,
  93. 'bases' => json_encode($output['bases']),
  94. 'ssa_fem' => json_encode($output['fem']),
  95. 'ssa_fer' => json_encode($output['fer'])
  96. ]);
  97. }
  98. /**
  99. * @param Request $request
  100. * @return Response
  101. * @throws \Twig\Error\LoaderError
  102. * @throws \Twig\Error\RuntimeError
  103. * @throws \Twig\Error\SyntaxError
  104. * @Route("/sources", name="sources")
  105. */
  106. public function renderSourcesPage(Request $request) : Response
  107. {
  108. return $this->render('sources.html.twig');
  109. }
  110. }