src/Controller/rechercheController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Contracts\HttpClient\HttpClientInterface;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. class rechercheController extends AbstractController
  9. {
  10.     private $client;
  11.     public function __construct(HttpClientInterface $client)
  12.     {
  13.         $this->client $client;
  14.     }
  15.     
  16.     /**
  17.      * @Route("/search")
  18.      */
  19.     public function renderRecherchePage(Request $request)
  20.     {   
  21.         // Creating a variable to store the
  22. // server address
  23. $ip_server $_SERVER['SERVER_ADDR'];
  24. //dd($ip_server);
  25.       /*  $formattedAddress = "21,avenue du Maine,70015 Paris";
  26.         $response = $this->client->request('GET','https://maps.googleapis.com/maps/api/geocode/json', [
  27.             'query' => [
  28.                 'address' => $formattedAddress,
  29.                 'key' => 'AIzaSyCRmNV4VerjHHrsOoQOMmRWwpKL_ekzJrc'
  30.             ]
  31.         ]);
  32.     
  33.         $data = $response->toArray();
  34.        // dd($data);*/
  35.          if (isset($_GET['latitude'])) {
  36.             $page $_GET['page'] ?? 1// Get the current page from the request, default to 1 if not provided
  37.             $limit 80// Number of results per page
  38.             
  39.             $queryParams = [
  40.                 //'name' => $_GET['name'],
  41.                 'latitude' => $_GET['latitude'],
  42.                 'longitude' => $_GET['longitude'],
  43.                 'ville' => $_GET['ville'],
  44.                 'page' => $page,
  45.                 'limit' => $limit
  46.             ];
  47.             
  48.             $url $_ENV['BASE_API'] . 'centres?' http_build_query($queryParams);
  49.         
  50.             $response $this->client->request('GET'$url);
  51.             $data $response->toArray();
  52.             
  53.             $centresImported $data['centerImported'];
  54.           $totalPages $data['totalPages'];
  55.           $centres $response->toArray()["content"];
  56.          // dd($centresImported);
  57.         }
  58.         else if (isset($_GET['address'])) {
  59.             $page $_GET['page'] ?? 1// Get the current page from the request, default to 1 if not provided
  60.             $limit 80// Number of results per page
  61.             if($_GET['address'] == "")
  62.             {
  63.                 $queryParams = [
  64.                     'latitude' => "48.856614",
  65.                     'address' => $_GET['address'],
  66.                     'longitude' => "2.3522219",
  67.                      'ville' => "paris",
  68.                     'page' => $page,
  69.                     'limit' => $limit
  70.                 ];
  71.             }
  72.             else{
  73.             $queryParams = [
  74.                 //'name' => $_GET['name'],
  75.                 'address' => $_GET['address'],
  76.                 //'longitude' => $_GET['longitude'],
  77.                // 'ville' => $_GET['ville'],
  78.                 'page' => $page,
  79.                 'limit' => $limit
  80.             ];
  81.         }
  82.             $url $_ENV['BASE_API'] . 'centres?' http_build_query($queryParams);
  83.         
  84.             $response $this->client->request('GET'$url);
  85.             $data $response->toArray();
  86.             
  87.             $centresImported $data['centerImported'];
  88.           $totalPages $data['totalPages'];
  89.           $centres $response->toArray()["content"];
  90.         }
  91.         else if (isset($_GET['name']) && isset($_GET['latitude'])){
  92.             $response $this->client->request(
  93.                 'GET',
  94.                 "{$_ENV['BASE_API']}centres?name=".$_GET['name']."&latitude=".$_GET['latitude']."&longitude=".$_GET['longitude']."&ville=".$_GET['ville']
  95.             );
  96.         }
  97.         else {
  98.             if (isset($_GET['name'])){
  99.               /*  $response = $this->client->request(
  100.                     'GET',
  101.                     "{$_ENV['BASE_API']}centres?name=".$_GET['name']
  102.                 );*/
  103.                 $page $_GET['page'] ?? 1// Get the current page from the request, default to 1 if not provided
  104.             $limit 80// Number of results per page
  105.             
  106.             $queryParams = [
  107.                 'name' => $_GET['name'],
  108.                 //'latitude' => $_GET['latitude'],
  109.                 //'longitude' => $_GET['longitude'],
  110.                 //'ville' => $_GET['ville'],
  111.                 'page' => $page,
  112.                 'limit' => $limit
  113.             ];
  114.             
  115.             $url $_ENV['BASE_API'] . 'centres?' http_build_query($queryParams);
  116.         
  117.             $response $this->client->request('GET'$url);
  118.             $data $response->toArray();
  119.             
  120.             $centresImported $data['centerImported'];
  121.           $totalPages $data['totalPages'];
  122.           $centres $response->toArray()["content"];
  123.             } elseif (isset($_GET['latitude'])) {
  124.                 $response $this->client->request(
  125.                     'GET',
  126.                     "{$_ENV['BASE_API']}centres?latitude=".$_GET['latitude']."&longitude=".$_GET['longitude']."&ville=".$_GET['ville']
  127.                 );
  128.                 $centres $response->toArray()["content"];
  129.             } else {
  130.                 $response $this->client->request(
  131.                     'GET',
  132.                     "{$_ENV['BASE_API']}centres"
  133.                 );
  134.                 $data $response->toArray();
  135.                 $totalPages $data['totalPages'];
  136.                 $centres $response->toArray()["content"];
  137.             }
  138.         }
  139.         
  140.         $centresImported $response->toArray()["centerImported"];
  141.         
  142.      //   dd($response->toArray());
  143.         $resp$this->client->request(
  144.             'GET',
  145.             "{$_ENV['BASE_API']}specialites"
  146.         );
  147.         $specialites $resp->toArray()["specialites"];
  148.         $presta$this->client->request(
  149.             'GET',
  150.             "{$_ENV['BASE_API']}prestations"
  151.         );
  152.         $prestations $presta->toArray()["prestations"];
  153.       
  154.         $page $request->query->getInt('page'1);
  155.         $limit 10// Number of results per page
  156.     
  157.       //dd($centresImported);
  158.         return $this->render('./recherche/recherche.html.twig', array(
  159.             "centres" => $centres,
  160.             "specialites" => $specialites,
  161.             "prestations" => $prestations,
  162.             "centresImported" => $centresImported,
  163.             'page' => $page,
  164.             'limit' => $limit,
  165.             'totalPages' => $totalPages
  166.         ));
  167.         
  168.     }
  169.     /**
  170.      * @Route("/searchResult")
  171.      */
  172.     public function renderRechercheResultPage()
  173.     {   
  174.         $specialites '';
  175.         $prestations ='';
  176.         if(isset($_GET['specialites'])){
  177.             $specialites $_GET['specialites'];
  178.         }
  179.         if(isset($_GET['prestations'])){
  180.             $prestations $_GET['prestations'];
  181.         }
  182.         if ((isset($_GET['name'])) && (isset($_GET['latitude']))){
  183.             $page $_GET['page'] ?? 1// Get the current page from the request, default to 1 if not provided
  184.             $limit 80// Number of results per page
  185.             
  186.             $queryParams = [
  187.                 'name' => $_GET['name'],
  188.              
  189.                 'specialities' => $specialites,
  190.                 'prestations' => $prestations,
  191.                 'isDomicile' => $_GET['isDomicile'],
  192.                 'day' => $_GET['disponibilite'],               
  193.                 'ville' => $_GET['ville'],
  194.                 'page' => $page,
  195.                 'limit' => $limit
  196.             ];
  197.             
  198.             $url $_ENV['BASE_API'] . 'centres?' http_build_query($queryParams);
  199.         
  200.             $response $this->client->request('GET'$url);
  201.             $data $response->toArray();
  202.             
  203.             $centresImported $data['centerImported'];
  204.   
  205.           $totalPages $data['totalPages'];
  206.         }
  207.         /*if ((isset($_GET['name'])) && (isset($_GET['latitude']))){
  208.             $response = $this->client->request(
  209.                 'GET',
  210.                 "{$_ENV['BASE_API']}centres?name=".$_GET['name']."&latitude=".$_GET['latitude']."&longitude=".$_GET['longitude']."&specialities=".$specialites."&prestations=".$prestations."&isDomicile=".$_GET['isDomicile']."&disponibilite=".$_GET['disponibilite']
  211.             );
  212.         }*/ else
  213.         /*if (isset($_GET['name']))  {
  214.             $response = $this->client->request(
  215.                 'GET',
  216.                 "{$_ENV['BASE_API']}centres?name=".$_GET['name']."&specialities=".$specialites."&prestations=".$prestations."&isDomicile=".$_GET['isDomicile']."&disponibilite=".$_GET['disponibilite']
  217.             );
  218.         } */
  219.         if (isset($_GET['name'])){
  220.             /*  $response = $this->client->request(
  221.                   'GET',
  222.                   "{$_ENV['BASE_API']}centres?name=".$_GET['name']
  223.               );*/
  224.               $page $_GET['page'] ?? 1// Get the current page from the request, default to 1 if not provided
  225.           $limit 80// Number of results per page
  226.           
  227.           $queryParams = [
  228.               'name' => $_GET['name'],
  229.            
  230.               'specialities' => $specialites,
  231.               'prestations' => $prestations,
  232.               'isDomicile' => $_GET['isDomicile'],
  233.               'day' => $_GET['disponibilite'],               
  234.               'ville' => $_GET['ville'],
  235.               'page' => $page,
  236.               'limit' => $limit
  237.           ];
  238.           
  239.           $url $_ENV['BASE_API'] . 'centres?' http_build_query($queryParams);
  240.       
  241.           $response $this->client->request('GET'$url);
  242.           $data $response->toArray();
  243.           
  244.           $centresImported $data['centerImported'];
  245.         $totalPages $data['totalPages'];
  246.         
  247.           }
  248.         else
  249.         /*if (isset($_GET['latitude'])){
  250.             $response = $this->client->request(
  251.                 'GET',
  252.                 "{$_ENV['BASE_API']}centres?latitude=".$_GET['latitude']."&longitude=".$_GET['longitude']."&specialities=".$specialites."&prestations=".$prestations."&isDomicile=".$_GET['isDomicile']."&disponibilite=".$_GET['disponibilite']
  253.             );
  254.         } */
  255.         
  256.         if (isset($_GET['latitude'])){
  257.             $page $_GET['page'] ?? 1// Get the current page from the request, default to 1 if not provided
  258.             $limit 80// Number of results per page
  259.             
  260.             $queryParams = [
  261.                 //'name' => $_GET['name'],
  262.                 'latitude' => $_GET['latitude'],
  263.                 'longitude' => $_GET['longitude'],
  264.                 'specialities' => $specialites,
  265.                 'prestations' => $prestations,
  266.                 'isDomicile' => $_GET['isDomicile'],
  267.                 'day' => $_GET['disponibilite'],               
  268.                 'ville' => $_GET['ville'],
  269.                 'page' => $page,
  270.                 'limit' => $limit
  271.             ];
  272.             
  273.             $url $_ENV['BASE_API'] . 'centres?' http_build_query($queryParams);
  274.         
  275.             $response $this->client->request('GET'$url);
  276.             $data $response->toArray();
  277.             
  278.             $centresImported $data['centerImported'];
  279.   
  280.           $totalPages $data['totalPages'];
  281.         } 
  282.         
  283.         else {
  284.             $response $this->client->request(
  285.                 'GET',
  286.                 "{$_ENV['BASE_API']}centres?specialities=".$specialites."&prestations=".$prestations."&isDomicile=".$_GET['isDomicile']."&disponibilite=".$_GET['disponibilite']
  287.             );
  288.         }
  289.         
  290.         $centres $response->toArray()["content"];
  291.         $centresImported $data['centerImported'];
  292.       //  dd($centresImported);
  293.         // Extract the "codePostal" values into a separate array for sorting
  294.        
  295.         // Sort the $centresImported array based on the "codePostal" values
  296.         $postalCodes array_column($centresImported'codePostal');
  297.         
  298.         //dd($postalCodes);
  299.        // array_multisort($postalCodes, SORT_ASC, $centresImported);
  300.       // dd($centresImported);
  301.     //  dd($$totalPages);
  302.       
  303.         return $this->render('./recherche/recherchMap.html.twig', array(
  304.             "centres" => $centres,
  305.             "centresImported" => $centresImported,
  306.             'page' => $page,
  307.             'limit' => $limit,
  308.             'totalPages' => $totalPages
  309.         ));
  310.         
  311.     }
  312. }
  313. ?>