src/Controller/AppController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\AppHelper;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class AppController extends AbstractController
  11. {
  12.     private $requestStack;
  13.     public function __construct(RequestStack $requestStack)
  14.     {
  15.         $this->requestStack $requestStack;
  16.         // Accessing the session in the constructor is *NOT* recommended, since
  17.         // it might not be accessible yet or lead to unwanted side-effects
  18.         // $this->session = $requestStack->getSession();
  19.     }
  20.     
  21.     /**
  22.      * @Route("/", name="app")
  23.      */
  24.     public function index(String $accountToken): Response
  25.     {
  26.         $curl curl_init();
  27.         curl_setopt_array($curl, array(
  28.             CURLOPT_URL            => $this->getParameter('map_url''').'/api/gp_type.json',
  29.             CURLOPT_RETURNTRANSFER => true,
  30.             CURLOPT_ENCODING       => '',
  31.             CURLOPT_MAXREDIRS      => 10,
  32.             CURLOPT_TIMEOUT        => 0,
  33.             CURLOPT_FOLLOWLOCATION => true,
  34.             CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
  35.             CURLOPT_SSL_VERIFYPEER => 0,
  36.             CURLOPT_CUSTOMREQUEST  => 'POST',
  37.             CURLOPT_HTTPHEADER => array(
  38.                 'Content-Type: application/json',
  39.                 'X-i42AccountToken: '.$accountToken
  40.             )
  41.         ));
  42.         
  43.         $response   curl_exec($curl);
  44.         curl_close($curl);
  45.         $resp_type       json_decode($responsetrue);
  46.         $postFields '{
  47.             "data" : {
  48.                 "language": "de",
  49.             }
  50.             }';
  51.         $curl curl_init();
  52.         curl_setopt_array($curl, array(
  53.             CURLOPT_URL            => $this->getParameter('map_url''').'/api/specializationlist.json',
  54.             CURLOPT_RETURNTRANSFER => true,
  55.             CURLOPT_ENCODING       => '',
  56.             CURLOPT_MAXREDIRS      => 10,
  57.             CURLOPT_TIMEOUT        => 0,
  58.             CURLOPT_FOLLOWLOCATION => true,
  59.             CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
  60.             CURLOPT_SSL_VERIFYPEER => 0,
  61.             CURLOPT_CUSTOMREQUEST  => 'POST',
  62.             CURLOPT_POSTFIELDS     => $postFields,
  63.             CURLOPT_HTTPHEADER => array(
  64.                 'Content-Type: application/json',
  65.                 'X-i42AccountToken: '.$accountToken
  66.             )
  67.         ));
  68.         
  69.         $response   curl_exec($curl);
  70.         curl_close($curl);
  71.         $resp       json_decode($responsetrue);
  72.         
  73.         return $this->render('app/index.html.twig', ['types' => $resp_type'specializations' => $resp]);
  74.     }
  75.     
  76.     /**
  77.      * @Route("/fdrdr/{page}", name="filter_doctor_doctor", defaults={"page"=0})
  78.      */
  79.     public function fdrdr(Request $requestAppHelper $appHelperString $accountToken$page): Response
  80.     {
  81.         $html      '<div>Keine Einträge gefunden</div>';
  82.         $arrFilter $request->get('filter', array());
  83.         $session $this->requestStack->getSession();
  84.         $offset intval($page);
  85.         if ($page==0){
  86.             $offset=1;
  87.             $session->set('location''');
  88.             $session->set('results', array());
  89.             if (
  90.                 isset($arrFilter['radius']) && ctype_digit($arrFilter['radius']) &&
  91.                 isset($arrFilter['zipcity']) && !empty($arrFilter['zipcity'])
  92.             )
  93.             {
  94.                 if (is_numeric($arrFilter['zipcity'])){
  95.                     $location $appHelper->getPositionByZipcodeFromGoogle($this->getParameter('gmap_apikey'''), $arrFilter['zipcity']);
  96.                 } else {
  97.                     $location $appHelper->getPositionByAddressFromGoogle($this->getParameter('gmap_apikey'''), $arrFilter['zipcity']);
  98.                 }
  99.                 if (count($location) && isset($location['lat']) && isset($location['lng']))
  100.                 {
  101.                     $postFields '{ "type": "'.$arrFilter['type'].'", "lat": '.$location['lat'].', "lng": '.$location['lng'].', "distance": '.$arrFilter['radius'];
  102.                         if (isset($arrFilter['specialist']) && $arrFilter['specialist']==='on'){
  103.                             $postFields .= ', "specialist": true';
  104.                         }
  105.                         if (isset($arrFilter['gender']) && !empty($arrFilter['gender'])){
  106.                             $postFields .= ', "gender": "' $arrFilter['gender'] . '" ';
  107.                         }
  108.                         if (isset($_POST['filter_specialization']) && !empty($_POST['filter_specialization']) && $_POST['filter_specialization'][0]!==''){
  109.                         $postFields .= ', "specialization": {';
  110.                             $i           0;
  111.                             foreach ($_POST['filter_specialization'] as $specialization) {
  112.                                 if ($i 0) {
  113.                                     $postFields .= ', ' ;
  114.                                 }
  115.                                 $postFields .= '"'.$i.'": '.$specialization;
  116.                                 $i++;
  117.                             }
  118.                             $postFields .= '}';
  119.                         }
  120.                     $postFields .= '}';    
  121.                     //var_dump($postFields)    ;
  122.                     //die;
  123.                     $curl curl_init();
  124.                     curl_setopt_array($curl, array(
  125.                         CURLOPT_URL            => $this->getParameter('map_url''').'/api/places.json',
  126.                         CURLOPT_RETURNTRANSFER => true,
  127.                         CURLOPT_ENCODING       => '',
  128.                         CURLOPT_MAXREDIRS      => 10,
  129.                         CURLOPT_TIMEOUT        => 0,
  130.                         CURLOPT_FOLLOWLOCATION => true,
  131.                         CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
  132.                         CURLOPT_SSL_VERIFYPEER => 0,
  133.                         CURLOPT_CUSTOMREQUEST  => 'POST',
  134.                         CURLOPT_POSTFIELDS     => $postFields,
  135.                         CURLOPT_HTTPHEADER => array(
  136.                             'Content-Type: application/json',
  137.                             'X-i42AccountToken: '.$accountToken
  138.                         )
  139.                     ));
  140.                     $response   curl_exec($curl);
  141.                     curl_close($curl);
  142.                     $resp       json_decode($responsetrue);
  143.                     if (is_array($resp) && isset($resp['results']) && count($resp['results']))
  144.                     {
  145.                         $session->set('location'$location);
  146.                         $session->set('results'$resp['results']);
  147.                     }
  148.                 }
  149.             } else {
  150.                 $html      '<div>PLZ / Ort und Umkreis muss eingetragen sein!</div>';
  151.             }
  152.         }
  153.         if (count($session->get('results'))){
  154.             $limit=10;
  155.             $results=array();
  156.             $resultsSession=$session->get('results');
  157.             $maxOffset=ceil(count($resultsSession)/$limit);
  158.             if ($offset*$limit>=count($resultsSession)){
  159.                 $loopLength intval(count($resultsSession));
  160.             } else {
  161.                 $loopLength $offset*$limit;
  162.             }
  163.             for ($i=($offset-1)*$limit;$i<$loopLength;$i++){
  164.                 $results[$i] = $resultsSession[$i];
  165.             }
  166.             $html $this->renderView('app/__data_detail.html.twig', array(
  167.                 'data'     => $results,
  168.                 'location' => $session->get('location'),
  169.                 'maxOffset' => $maxOffset
  170.                 'page' => $offset
  171.             ));
  172.         }
  173.         
  174.         return new JsonResponse(array('html' => $html));
  175.     }
  176. }