src/Controller/ServiceorlController.php line 80

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\CenterZipcode;
  4. use App\Entity\Centers;
  5. use App\Entity\Cities;
  6. use App\Entity\Doctors;
  7. use App\Entity\EventsCategory;
  8. use App\Entity\Geocode;
  9. use App\Entity\Hospitals;
  10. use App\Entity\Image;
  11. use App\Entity\Lookup;
  12. use App\Entity\Maps;
  13. use App\Entity\ServiceDoctors;
  14. use App\Entity\Services;
  15. use App\Entity\Zipcode;
  16. use App\Repository\DoctorsRepository;
  17. use App\Repository\ServicesRepository;
  18. use Knp\Component\Pager\PaginatorInterface;
  19. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. class ServiceorlController extends AbstractController
  25. {
  26.   /**
  27.    * @Route("/service-hospitalier-orl/{id}", name="redirect_id_hopital", requirements={"id"="\d+"})
  28.    */
  29.   public function redirectIdOnly($id)
  30.   {
  31.     $hopital $this->getDoctrine()->getRepository(Hospitals::class)->find($id);
  32.     if ($hopital && ($hopital->getLocalisation()->getCountry() == "FRANCE" || $hopital->getLocalisation()->getCountry() == "")) {
  33.       $url $this->router->generate(
  34.         'page_service_hospitalier',
  35.         array('ville' => $this->slugify->slugify($hopital->getLocalisation()->getCity()), 'zipcode' => $hopital->getLocalisation()->getZipcode(), 'nomhopital' => $this->slugify->slugify($hopital->getCorporateName()), 'idhopital' => $id)
  36.       );
  37.     } else {
  38.       $url $this->router->generate(
  39.         'liste_service'
  40.       );
  41.     }
  42.     return $this->redirect($url301);
  43.   }
  44.   /**
  45.    * @Route("/service-hospitalier-orl/page/{page}", name="redirect_page_service")
  46.    */
  47.   public function redirectPage($page null)
  48.   {
  49.     if ($page) {
  50.       $url $this->router->generate(
  51.         'liste_service'
  52.       );
  53.     }
  54.     return $this->redirect($url301);
  55.   }
  56.   /**
  57.    * @Route("/service-hospitalier-orl", name="liste_service")
  58.    */
  59.   public function renderDefault(): Response
  60.   {
  61.     $this->setTemplateParameters(array('title_seo' => 'Services ORL'));
  62.     $this->setInternalLinkage('serviceListe');
  63.     return $this->renderTemplate('pages/annuaire_search_ORLServices.twig');
  64.   }
  65.   /**
  66.    * @Route("/service-hospitalier-orl-{zipcode}-{ville}.html", name="results_service_audio_by_city", requirements={"zipcode"="\d{5}"}, defaults={"page" = 1})
  67.    * @Route("/service-hospitalier-orl-{zipcode}-{ville}/filtre-resultats/implantcochleaire-{implant}.html", name="results_service_by_city_filter_implant", requirements={"zipcode"="\d{5}"}, defaults={"page" = 1})
  68.    * @Route("/service-hospitalier-orl-{zipcode}-{ville}/filtre-resultats/centre-pour-laryngectomise-{laryng}.html", name="results_service_by_city_filter_laryng", requirements={"zipcode"="\d{5}"}, defaults={"page" = 1})
  69.    * @Route("/service-hospitalier-orl-{departementCode}-{departementTexte}.html", name="results_service_by_departement", requirements={"departementCode"="[0-9]{1,2}[0-9A-B]{1}"}, defaults={"page" = 1})
  70.    * @Route("/service-hospitalier-orl-{departementCode}-{departementTexte}/filtre-resultats/implantcochleaire-{implant}.html", name="results_service_by_departement_filter_implant", requirements={"departementCode"="[0-9]{1,2}[0-9A-B]{1}"}, defaults={"page" = 1})
  71.    * @Route("/service-hospitalier-orl-{departementCode}-{departementTexte}/filtre-resultats/centre-pour-laryngectomise-{laryng}.html", name="results_service_by_departement_filter_laryng", requirements={"departementCode"="[0-9]{1,2}[0-9A-B]{1}"}, defaults={"page" = 1})
  72.    * 
  73.    */
  74.   public function renderList($zipcode null$ville null$departementCode null$departementTexte null$implant null$laryng nullRequest $requestPaginatorInterface $paginator): Response
  75.   {
  76.     $result = [];
  77.     $searchtype = [];
  78.     $search_by null;
  79.     $hospitals = array();
  80.     $hospitals_filtered = array();
  81.     $service_title_seo $service_description_seo null;
  82.     if ($zipcode) {
  83.       /************* Description seo ****************/
  84.       $description_seo "Services ORL à " $this->dataProvider->wordUpperCaseFirstLetter($ville) . " (" $zipcode ") : Trouvez un service ORL proche de chez vous, consultez ses coordonnées et prenez rendez-vous avec l'Annuaire de l'Audition.";
  85.       $search_by 'zipcode';
  86.       $localisation $this->getDoctrine()->getRepository(Zipcode::class)->findOneBy(array(
  87.         'zipcode' => $zipcode,
  88.         'city' => strtoupper($ville)
  89.       ));
  90.       if (!$localisation) {
  91.         $localisation $this->getDoctrine()->getRepository(Zipcode::class)->findByZipCodeAndCityLike($zipcode$ville);
  92.       }
  93.       if (!$localisation) {
  94.         $localisation $this->getDoctrine()->getRepository(Zipcode::class)->findOneBy(array(
  95.           'zipcode' => $zipcode,
  96.           'city' => strtoupper(str_replace('-'' '$ville))
  97.         ));
  98.       }
  99.       if (!$localisation) {
  100.         $localisation $this->getDoctrine()->getRepository(Zipcode::class)->findOneBy(['zipcode' => $zipcode]);
  101.       }
  102.       if (!$localisation) {
  103.         throw new NotFoundHttpException();
  104.       }
  105.       if ($ville != $this->slugify->slugify($localisation->getCity())) {
  106.         return $this->redirectProvider->redirect301('results_service_audio_by_city', array('ville' => $this->slugify->slugify($localisation->getCity()), 'zipcode' => $zipcode));
  107.       }
  108.       $departementTexte "";
  109.       $cities $localisation->getCities();
  110.       if (!$cities) {
  111.         $cities $this->geoProvider->addCities($ville$zipcode$localisation);
  112.       }
  113.       if (!empty($localisation->getCities())) {
  114.         $departementTexte $localisation->getCities()->getDeptTxt();
  115.         $depcode $localisation->getCities()->getDeptcode();
  116.       } else {
  117.         $dep $localisation->getDepartment();
  118.         $departementTexte substr($dep7);
  119.         $depcode substr($dep02);
  120.       }
  121.       // PREFOOTER 
  122.       $searchtype['departementCode'] = $depcode;
  123.       $searchtype['departementTexte'] = $this->slugify->slugify($departementTexte);
  124.       $searchtype['zipcode'] = $zipcode;
  125.       $searchtype['ville'] = $ville;
  126.       // BREADCRUMB
  127.       $this->breadDatas['type'] = 'city';
  128.       $this->breadDatas['final'] = $localisation->getCity() . " (" $zipcode ")";
  129.       $this->breadDatas['final_url'] = $this->router->generate(
  130.         'results_service_audio_by_city',
  131.         array('zipcode' => $zipcode'ville' => $this->slugify->slugify($ville))
  132.       );
  133.       $this->breadDatas['departementTxt'] = $departementTexte;
  134.       $this->breadDatas['departementCode'] = $depcode;
  135.       $hospitals $this->getDoctrine()->getRepository(Hospitals::class)->findByLocalisationId($localisation->getId());
  136.       $total_results count($hospitals);
  137.       $limit 30 $total_results;
  138.       if ($total_results 30) {
  139.         $hospitals_proximite = [];
  140.         // ------- Récupération coordonnées de la ville courante
  141.         $lat $localisation->getCities()->getLat();
  142.         $lng $localisation->getCities()->getLng();
  143.         $idLoc $localisation->getCities()->getId();
  144.         $cities_proximite $this->getDoctrine()->getRepository(Zipcode::class)->findCitiesByProximite($lat$lng$idLoc);
  145.         foreach ($cities_proximite as $city) {
  146.           if ($zip_pro $this->getDoctrine()->getRepository(Zipcode::class)->find($city[0]->getId())) {
  147.             $zip_pro_id $zip_pro->getId();
  148.             if ($total_results 30) {
  149.               $hospitals_proximite $this->getDoctrine()->getRepository(Hospitals::class)->findByLocalisationId($city[0]->getId());
  150.               foreach ($hospitals_proximite as $hospital_proximite) {
  151.                 if (!in_array($hospital_proximite$hospitals) && $total_results 30) {
  152.                   $hospital_proximite->zip_pro $zip_pro->getZipcode();
  153.                   $hospital_proximite->zip_pro $zip_pro->getCity();
  154.                   array_push($hospitals$hospital_proximite);
  155.                   $total_results count($hospitals);
  156.                   $limit 30 $total_results;
  157.                 }
  158.               }
  159.             }
  160.           }
  161.         }
  162.       }
  163.       $datasFilters = array('ville' => $ville'zipcode' => $zipcode);
  164.       $arrondissement false;
  165.       if ($ville == "paris" || $ville == "marseille" || $ville == "lyon") {
  166.         $arrondissement " " $this->dataProvider->getArrondissement($zipcode);
  167.         if ($ville != "paris")
  168.           $this->breadDatas['villeArrondissement'] = $ville;
  169.       }
  170.       $title_seo "Hôpitaux à " $this->dataProvider->wordUpperCaseFirstLetter($localisation->getCity()) . $arrondissement " (" $zipcode ") - Services ORL";
  171.       // Description seo //
  172.       if ($localisation) {
  173.         $service_title_seo $localisation->getServicesTitleSeo();
  174.         $service_description_seo html_entity_decode(strip_tags($localisation->getServicesDescriptionSeo()), ENT_QUOTES);
  175.       }
  176.       $canonical_url $this->router->generate('results_service_audio_by_city', array('zipcode' => $zipcode'ville' => $this->slugify->slugify($ville)));
  177.       //$searchtype['exceptZipCode'] = $zipcode;
  178.       $this->setTemplateParameters(array('zipcode' => $zipcode));
  179.       $this->setTemplateParameters(array('ville' => $ville));
  180.     } elseif ($departementCode) {
  181.       /************* Description seo ****************/
  182.       $description_seo "Services ORL " $this->dataProvider->wordUpperCaseFirstLetter($departementTexte) . " (" $departementCode ") : Trouvez un service ORL proche de chez vous, consultez ses coordonnées et prenez rendez-vous avec l'Annuaire de l'Audition.";
  183.       $search_by 'depcode';
  184.       $localisation $this->getDoctrine()->getRepository(Cities::class)->findOneBy(array('deptCode' => $departementCode));
  185.       $ville $localisation->getVille();
  186.       $zipcode $localisation->getZipCode();
  187.       $depcode $localisation->getDeptcode();
  188.       $checkDept $this->slugify->slugify($localisation->getDeptTxt());
  189.       if ($checkDept != $departementTexte && ($departementTexte != 'lyon' && $departementTexte != 'paris' && $departementTexte != 'marseille')) {
  190.         return $this->redirectProvider->redirect301('results_service_by_departement', array('departementCode' => $departementCode'departementTexte' => $checkDept));
  191.       }
  192.       //$departementTexte = $localisation->getDeptTxt();
  193.       $hospitals = array();
  194.       // PREFOOTER 
  195.       $searchtype['departementCode'] = $departementCode;
  196.       $searchtype['departementTexte'] = $this->slugify->slugify($departementTexte);
  197.       // BREADCRUMB
  198.       $this->breadDatas['type'] = 'dept';
  199.       $this->breadDatas['final'] = $localisation->getDeptTxt() . " (" $departementCode ")";
  200.       $this->breadDatas['final_url'] = $this->router->generate(
  201.         'results_service_by_departement',
  202.         array('departementCode' => $departementCode'departementTexte' => $this->slugify->slugify($departementTexte))
  203.       );
  204.       $title_seo "Hôpitaux " $this->dataProvider->wordUpperCaseFirstLetter($localisation->getDeptTxt()) . " (" $departementCode ") - Service ORL";
  205.       // TOUTES LES VILLES DU DEPARTEMENT 
  206.       if ($departementTexte == 'lyon' || $departementTexte == 'paris' || $departementTexte == 'marseille') {
  207.         $this->breadDatas['type'] = 'city';
  208.         $title_seo "Hôpitaux à " $this->dataProvider->wordUpperCaseFirstLetter($departementTexte) . " (" $departementCode ") - Service ORL";
  209.         $this->breadDatas['final'] = $this->dataProvider->wordUpperCaseFirstLetter($departementTexte) . " (" $departementCode ")";
  210.         $citiesInDept $this->getDoctrine()->getRepository(Zipcode::class)->findBy(['city' => $departementTexte]);
  211.         // BREADCRUMB SPECIFIQUE
  212.         switch ($departementTexte) {
  213.           case 'paris':
  214.             $this->breadDatas['departementTxt'] = 'Paris';
  215.             $this->breadDatas['departementCode'] = 75;
  216.             break;
  217.           case 'lyon':
  218.             $this->breadDatas['departementTxt'] = 'Rhône';
  219.             $this->breadDatas['departementCode'] = 69;
  220.             break;
  221.           case 'marseille':
  222.             $this->breadDatas['departementTxt'] = 'Bouches-du-Rhône';
  223.             $this->breadDatas['departementCode'] = 13;
  224.             break;
  225.         }
  226.       } else {
  227.         $citiesInDept $this->getDoctrine()->getRepository(Zipcode::class)->findCitiesInDept($departementCode);
  228.       }
  229.       // TOUS LES DOCTEURS DE TOUTES LES VILLES
  230.       foreach ($citiesInDept as $city) {
  231.         $hospitalsincity $this->getDoctrine()->getRepository(Hospitals::class)->findByLocalisationId($city->getId());
  232.         foreach ($hospitalsincity as $hospitalincity) {
  233.           if (!in_array($hospitalincity$hospitals)) {
  234.             $hospitalincity->zip_pro $city->getZipcode();
  235.             $hospitalincity->city_pro $city->getCity();
  236.             array_push($hospitals$hospitalincity);
  237.           }
  238.         }
  239.       }
  240.       $datasFilters = array('departementCode' => $departementCode'departementTexte' => $departementTexte);
  241.       // Description seo //
  242.       //---- On cherche l'objet Map ayant le nom qui commence par depcode %
  243.       $maps $this->getDoctrine()->getRepository(Maps::class)->findOneMapByDepCode($departementCode);
  244.       if ($maps && isset($maps[0])) {
  245.         $service_title_seo $maps[0]->getServicesTitleSeo();
  246.         $service_description_seo html_entity_decode(strip_tags($maps[0]->getServicesDescriptionSeo()), ENT_QUOTES);
  247.       }
  248.       $canonical_url $this->router->generate('results_service_by_departement', array('departementCode' => $departementCode'departementTexte' => $this->slugify->slugify($departementTexte)));
  249.     }
  250.     // Récupération des filtres implants
  251.     $implant_filters $this->FiltersProvider->getServiceImplantFilters($hospitals$datasFilters);
  252.     // Récupération des filtres Laryngtomisé
  253.     $laryng_filters $this->FiltersProvider->getServiceLaryngFilters($hospitals$datasFilters);
  254.     $filtered false;
  255.     // SI filtre par implant
  256.     if ($implant) {
  257.       foreach ($hospitals as $hospital) {
  258.         $services $this->getDoctrine()->getRepository(Services::class)->findBy(['hospital' => $hospital->getId()]);
  259.         foreach ($services as $service) {
  260.           if (($service->getCochlearImplant() && $implant == "oui") || (!$service->getCochlearImplant() && $implant == "non")) {
  261.             if (!in_array($hospital$hospitals_filtered)) {
  262.               $hospitals_filtered[] = $hospital;
  263.             }
  264.           }
  265.         }
  266.       }
  267.       $filtered true;
  268.     }
  269.     // SI filtre par laryng
  270.     if ($laryng) {
  271.       foreach ($hospitals as $hospital) {
  272.         if (($hospital->getCenterForLaryngectomy() && $laryng == "oui") || (!$hospital->getCenterForLaryngectomy() && $laryng == "non")) {
  273.           $hospitals_filtered[] = $hospital;
  274.         }
  275.       }
  276.       $filtered true;
  277.     }
  278.     if ($filtered) {
  279.       $result $this->cardProvider->getHospitalCards($hospitals_filtered);
  280.     } else {
  281.       $result $this->cardProvider->getHospitalCards($hospitals);
  282.     }
  283.     $results_paginated $paginator->paginate(
  284.       $result,
  285.       $request->query->getInt('page'1),
  286.       30
  287.     );
  288.     $map = array();
  289.     foreach ($results_paginated as $result_paginated) {
  290.       if ($marker $this->geoProvider->getHospitalCoords($result_paginated['hospital'], $result_paginated['img_src'], 'ServiceOrl')) {
  291.         $map['markers'][] = $marker;
  292.       }
  293.     }
  294.     if ($search_by == 'zipcode') :
  295.       $location['text'] = $ville;
  296.       $location['code'] = $zipcode;
  297.     else :
  298.       $location['text'] = $departementTexte;
  299.       $location['code'] = $depcode;
  300.     endif;
  301.     $this->setTemplateParameters(array(
  302.       'searchresult' => array(
  303.         'services' => $results_paginated,
  304.         'location' => $location,
  305.       ),
  306.       'filter' => array(
  307.         'implant' => $implant_filters,
  308.         'laryng' => $laryng_filters,
  309.       )
  310.     ));
  311.     // Breadcrumb //
  312.     $this->breadDatas['departementTexte'] = $departementTexte;
  313.     $this->breadDatas['departementCode'] = $depcode;
  314.     $this->setBreadcrumb('services''list');
  315.     $deptForPreFooter = ($departementTexte == "paris" || $ville == "paris" || $departementTexte == "marseille" || $ville == "marseille" || $departementTexte == "lyon" || $ville == "lyon") ? "à " $departementTexte "en " $departementTexte;
  316.     $this->setTemplateParameters(array('dept' => $deptForPreFooter));
  317.     $this->setTitleSearch();
  318.     $this->setTemplateParameters(array('map' => $map));
  319.     $this->setInternalLinkage('serviceListe'$searchtype);
  320.     $this->setTemplateParameters(array('title_seo' => ($title_seo) ?? 'Service ORL'));
  321.     $this->setTemplateParameters(array('description_seo' => $description_seo));
  322.     $this->setTemplateParameters(array('canonical_url' => $canonical_url));
  323.     $this->setTemplateParameters(array('seo_text' => array('title' => $service_title_seo'text' => $service_description_seo)));
  324.     $this->setPrevNextRel(count($result), $request->query->getInt('page'), $request->getSchemeAndHttpHost() . $request->getPathInfo());
  325.     return $this->renderTemplate('pages/annuaire_searchResults_ORLServices.twig');
  326.   }
  327.   /**
  328.    * @Route("/service-hospitalier-orl/{ville}-{zipcode}/{nomhopital}-{idhopital}/{nomservice}-{idservice}.html", name="page_service_hospitalier_avec_service", requirements={"zipcode"="\d{5}", "ville"="[a-zA-Z0-9\-_\/]+", "nomhopital"="[a-zA-Z0-9\-_\/]+", "nomservice"="[a-zA-Z0-9\-_\/]+"})
  329.    * @Route("/service-hospitalier-orl/{ville}-{zipcode}/{nomhopital}-{idhopital}.html", name="page_service_hospitalier", requirements={"ville"="[a-zA-Z0-9\-_\/]+", "nomhopital"="[a-zA-Z0-9\-_\/]+"})
  330.    *
  331.    */
  332.   public function renderPage(
  333.     $ville,
  334.     $zipcode,
  335.     $idhopital,
  336.     $nomhopital null,
  337.     $nomservice null,
  338.     $idservice null,
  339.     ServicesRepository $servicesRepository
  340.   ) {
  341.     $lat "";
  342.     $lng "";
  343.     $nom_service "";
  344.     $hospital $this->getDoctrine()->getRepository(Hospitals::class)->find($idhopital);
  345.     if (!$hospital) {
  346.       return $this->redirectProvider->redirect301('results_service_audio_by_city', array(
  347.         'zipcode' => $zipcode,
  348.         'ville' => $ville
  349.       ));
  350.     }
  351.     if ($hospital) {
  352.       // Si aucun service passé en paramètre, alors dans ce cas on récupère le premier service lié dans la BD
  353.       if (!$idservice) {
  354.         $service $this->getDoctrine()->getRepository(Services::class)->findOneBy(['hospital' => $idhopital]);
  355.         if ($service) {
  356.           return $this->redirectProvider->redirect301('page_service_hospitalier_avec_service', array('ville' => $ville'zipcode' => $zipcode'nomhopital' => $nomhopital'idhopital' => $idhopital'nomservice' => $this->slugify->slugify($service->getName()), 'idservice' => $service->getId()));
  357.         } else {
  358.           return $this->redirectProvider->redirect301('results_service_audio_by_city', array(
  359.             'zipcode' => $zipcode,
  360.             'ville' => $ville
  361.           ));
  362.         }
  363.       } else {
  364.         $service $this->getDoctrine()->getRepository(Services::class)->find($idservice);
  365.         if (!$service) {
  366.           return $this->redirectProvider->redirect301('page_service_hospitalier', array('ville' => $ville'zipcode' => $zipcode'nomhopital' => $nomhopital'idhopital' => $idhopital));
  367.         }
  368.       }
  369.       $slugCheck $this->slugify->slugify($hospital->getCorporateName());
  370.       if ($slugCheck != $nomhopital) {
  371.         return $this->redirectProvider->redirect301('page_service_hospitalier_avec_service', array('ville' => $ville'zipcode' => $zipcode'nomhopital' => $slugCheck'idhopital' => $idhopital'nomservice' => $nomservice'idservice' => $idservice));
  372.       }
  373.       $slugCheckService $this->slugify->slugify($service->getName());
  374.       if ($slugCheckService != $nomservice) {
  375.         return $this->redirectProvider->redirect301('page_service_hospitalier_avec_service', array('ville' => $ville'zipcode' => $zipcode'nomhopital' => $nomhopital'idhopital' => $idhopital'nomservice' => $slugCheckService'idservice' => $idservice));
  376.       }
  377.       $localisation null;
  378.       if ($hospital->getLocalisation()) {
  379.         $localisation $hospital->getLocalisation();
  380.       }
  381.       if (!$localisation) {
  382.         $localisation $this->getDoctrine()->getRepository(Zipcode::class)->findOneBy(array('zipcode' => $zipcode));
  383.       }
  384.       if (!$localisation) {
  385.         throw new NotFoundHttpException();
  386.       }
  387.       if ($zipcode != $localisation->getZipcode() || $ville != $this->slugify->slugify($localisation->getCity())) {
  388.         preg_match('/^[0-9]{5}/'$localisation->getZipcode(), $matches);
  389.         if ($matches) {
  390.           return $this->redirectProvider->redirect301('page_service_hospitalier_avec_service', array(
  391.             'ville' => $this->slugify->slugify($localisation->getCity()),
  392.             'zipcode' => $localisation->getZipcode(),
  393.             'nomhopital' => $nomhopital,
  394.             'idhopital' => $idhopital,
  395.             'nomservice' => $nomservice,
  396.             'idservice' => $idservice
  397.           ));
  398.         }
  399.       }
  400.       //Geolocalisation
  401.       $cities $localisation->getCities();
  402.       if (!$cities) {
  403.         $cities $this->geoProvider->addCities($ville$zipcode$localisation);
  404.       }
  405.       if ($geocode $this->getDoctrine()->getRepository(Geocode::class)->findOneBy(['class' => 'Hospitals''id' => $idhopital])) {
  406.         $lat $geocode->getLat();
  407.         $lng $geocode->getLng();
  408.       } else {
  409.         $lat $localisation->getCities()->getLat();
  410.         $lng $localisation->getCities()->getLng();
  411.       }
  412.       if (!empty($localisation->getCities())) {
  413.         $departementTexte $localisation->getCities()->getDeptTxt();
  414.         $depcode $localisation->getCities()->getDeptcode();
  415.       } else {
  416.         $dep $localisation->getDepartment();
  417.         $departementTexte substr($dep7);
  418.         $depcode substr($dep02);
  419.       }
  420.       $ville $localisation->getCity();
  421.       $localisationId $localisation->getId();
  422.       if (!empty($localisation->getCities())) {
  423.         $departementTexte $localisation->getCities()->getDeptTxt();
  424.         $depcode $localisation->getCities()->getDeptcode();
  425.       } else {
  426.         $dep $localisation->getDepartment();
  427.         $departementTexte substr($dep7);
  428.         $depcode substr($dep02);
  429.       }
  430.       $slugHopital $this->slugify->slugify($hospital->getCorporateName());
  431.       // Logo //
  432.       $logoPersonne $this->dataProvider->getAvatar('ServiceOrl');
  433.       if ($logoId $this->getDoctrine()->getRepository(Image::class)->findOneBy(['class' => 'Hospitals''entityId' => $idhopital'cover' => 1])) {
  434.         $file $this->bo_url "images/" $logoId->getId() . "-medium.jpg";
  435.         $logoPersonne $file;
  436.       }
  437.       // Website
  438.       $website $hospital->getWebsite() ?? '';
  439.       // On récupère les autres service liés
  440.       $otherServices $servicesRepository->findBy(['hospital' => $hospital]);
  441.       $buttons = [];
  442.       $relatedServices = [];
  443.       $i 1;
  444.       $idsServices = array();
  445.       foreach ($otherServices as $otherService) {
  446.         $idsServices[] = $otherService->getId();
  447.         $current = ($otherService->getId() == $idservice) ? true false;
  448.         $serviceLink $this->generateUrl('page_service_hospitalier_avec_service', [
  449.           'ville' => $this->slugify->slugify($hospital->getLocalisation()->getCity()),
  450.           'zipcode' => $hospital->getLocalisation()->getZipcode(),
  451.           'nomhopital' => $this->slugify->slugify($hospital->getCorporateName()),
  452.           'idhopital' => $hospital->getId(),
  453.           'nomservice' => $this->slugify->slugify($otherService->getName()),
  454.           'idservice' => $otherService->getId()
  455.         ]);
  456.         if ($otherService->getName() && $ville && $zipcode) {
  457.           array_push($buttons, array(
  458.             "title" => "Service ORL " $i,
  459.             "url" => $serviceLink,
  460.             "current" => $current,
  461.           ));
  462.           $i++;
  463.         }
  464.         if ($current) continue;
  465.         $coords = array(
  466.           "items" => array(
  467.             "address" => $hospital->getAddress() . " \n" $hospital->getAdditionalAddress(),
  468.             "zip" => $hospital->getLocalisation()->getZipcode(),
  469.             "city" => $hospital->getLocalisation()->getCity(),
  470.             "bp" => $hospital->getPoBox(),
  471.             "zipcedex" => $hospital->getCedex(),
  472.             "citycedex" => $hospital->getCityCedex()
  473.           ),
  474.           "coordTitle" => $otherService->getName(),
  475.           'link' => $serviceLink,
  476.         );
  477.         for ($k 1$k <= 3$k++) {
  478.           $tel $service->{'getTitle' $k}();
  479.           if (!empty($tel)) $tel .= "\n";
  480.           $tel .= $service->{'getDescription' $k}();
  481.           $coords['items']['tel' $k] = $tel;
  482.         }
  483.         $relatedServices[] = $coords;
  484.       }
  485.       if (!in_array($idservice$idsServices)) {
  486.         return $this->redirectProvider->redirect301('page_service_hospitalier', array('ville' => $this->slugify->slugify($ville), 'zipcode' => $zipcode'nomhopital' => $nomhopital'idhopital' => $idhopital));
  487.       }
  488.       // LES MÉDECINS ORL RATTACHÉS AU SERVICE //
  489.       $teamDesordre = [];
  490.       $team = [];
  491.       $doctors $this->getDoctrine()->getRepository(ServiceDoctors::class)->findBy(['service' => $idservice]);
  492.       foreach ($doctors as $doctor) {
  493.         //$doctor = $doctor->getDoctor();
  494.         $rolePerson null;
  495.         if ($lookup $this->getDoctrine()->getRepository(Lookup::class)->findOneBy(['code' => $doctor->getStatusGrade(), 'type' => 'StatusGrade'])) {
  496.           $rolePerson $lookup->getName();
  497.           $rolePos $lookup->getPosition();
  498.         } else {
  499.           $rolePos 99999;
  500.         }
  501.         if ($doctor->getSpecialty()) {
  502.           $rolePerson .= " (" $doctor->getSpecialty() . ")";
  503.         }
  504.         $doctor $this->getDoctrine()->getRepository(Doctors::class)->findOneBy(['id' => $doctor->getDoctor(), 'visible' => 1]);
  505.         // Logo //
  506.         if ($doctor) {
  507.           // Logo //
  508.           $logo $this->dataProvider->getAvatar('Docteur'$doctor->getTitle());
  509.           if ($logoId $this->getDoctrine()->getRepository(Image::class)->findOneBy(['class' => 'Doctors''entityId' => $doctor->getId(), 'cover' => 1])) {
  510.             $file $this->bo_url "images/" $logoId->getId() . "-medium.jpg";
  511.             $logo $file;
  512.           }
  513.           // Diplômes //
  514.           $diplomas = [];
  515.           $diplomes $this->getDoctrine()->getRepository(Doctors::class)->getDoctorDegrees($doctor->getId());
  516.           foreach ($diplomes as $diplome) {
  517.             $diplomas[] = $diplome->getName();
  518.           }
  519.           array_push($teamDesordre, array(
  520.             "lastName" => $doctor->getName(),
  521.             "name" => $doctor->getTitle() . ' ' $doctor->getFirstName() . ' ' $doctor->getName(),
  522.             "image" => $logo,
  523.             "job" => $this->dataProvider->getDoctorSpecialities($doctor->getId()),
  524.             "diploma" => $diplomas,
  525.             "rolePerson" => $rolePerson,
  526.             "rolePos" => $rolePos,
  527.             "link" => $this->router->generate(
  528.               'page_single_medecin_with_service',
  529.               array(
  530.                 'ville' => $this->slugify->slugify($ville),
  531.                 'zipcode' => $zipcode,
  532.                 'nomMedecin' => $this->slugify->slugify($doctor->getFirstName() . '-' $doctor->getName()),
  533.                 'idMedecin' => $doctor->getId(),
  534.                 'idService' => $idservice
  535.               )
  536.             )
  537.           ));
  538.         }
  539.       }
  540.       // TRI PAR POSITION
  541.       $pos array_column($teamDesordre'rolePos');
  542.       $name array_column($teamDesordre'lastName');
  543.       array_multisort($posSORT_ASC$nameSORT_ASC$teamDesordre);
  544.       foreach ($teamDesordre as $r) {
  545.         $team[] = $r;
  546.       }
  547.       // LES CENTRES D'AUDIOPROTHÈSE À PROXIMITÉ DU SERVICE //
  548.       $centre_proximite = [];
  549.       if ($lat && $lng) {
  550.         $centersCity $this->getDoctrine()->getRepository(Centers::class)->findBy([
  551.           'localisation' => $localisation->getId(),
  552.           'advertiser' => 1,
  553.           'visible' => 1
  554.         ]);
  555.         shuffle($centersCity);
  556.         foreach ($centersCity as $c) {
  557.           array_push($centre_proximite$c);
  558.         }
  559.         $centersRelated $this->getDoctrine()->getRepository(CenterZipcode::class)->findBy(['zipcodeId' => $localisation->getId()]);
  560.         shuffle($centersRelated);
  561.         foreach ($centersRelated as $c) {
  562.           $cr $this->getDoctrine()->getRepository(Centers::class)->findOneBy([
  563.             'id' => $c->getCenterId(),
  564.             'advertiser' => 1,
  565.             'visible' => 1
  566.           ]);
  567.           if ($cr) {
  568.             array_push($centre_proximite$cr);
  569.           }
  570.         }
  571.         if (count($centre_proximite) < 6) {
  572.           $limit count($centre_proximite);
  573.           $proximites $this->getDoctrine()->getRepository(Centers::class)->findCentersByProximiteCity(array('lat' => $lat'lng' => $lng), $localisation->getId(), $limit);
  574.           shuffle($proximites);
  575.           foreach ($proximites as $proximite) {
  576.             $centerPro $this->getDoctrine()->getRepository(Centers::class)->findOneBy([
  577.               'id' => $proximite[0]->getId(),
  578.               'visible' => 1
  579.             ]);
  580.             if ($centerPro && !in_array($centerPro$centre_proximite)) {
  581.               array_push($centre_proximite$centerPro);
  582.             }
  583.           }
  584.         }
  585.         $centersLiesTab $this->cardProvider->getCenterCards($centre_proximitenulltrue);
  586.       }
  587.       // PROCHAINS ÉVENEMENTS DU SERVICES ORL //
  588.       $events = [];
  589.       $evenements $this->getDoctrine()->getRepository(Services::class)->getEvents($idservice);
  590.       $events $this->cardProvider->getEventsCards($evenements);
  591.       // Coordonnées du service //
  592.       $coords = [];
  593.       if ($service) {
  594.         $nom_service $service->getName();
  595.         $coords = array(
  596.           "items" => array(
  597.             "address" => $hospital->getAddress() . " \n" $hospital->getAdditionalAddress(),
  598.             "zip" => $hospital->getLocalisation()->getZipcode(),
  599.             "city" => $hospital->getLocalisation()->getCity(),
  600.             "bp" => $hospital->getPoBox(),
  601.             "zipcedex" => $hospital->getCedex(),
  602.             "citycedex" => $hospital->getCityCedex()
  603.           ),
  604.           "coordTitle" => $nom_service,
  605.         );
  606.         for ($i 1$i <= 3$i++) {
  607.           $tel $service->{'getTitle' $i}();
  608.           if (!empty($tel)) $tel .= "\n";
  609.           $tel .= $service->{'getDescription' $i}();
  610.           $coords['items']['tel' $i] = $tel;
  611.         }
  612.       }
  613.       $header = array(
  614.         "image" => $logoPersonne,
  615.         "name" => $hospital->getCorporateName(),
  616.         "name2" => $hospital->getCorporateName2(),
  617.         "websites" => [["link" => $website]],
  618.       );
  619.       $this->setTemplateParameters(array(
  620.         'page_orl_service' => array(
  621.           'header' => $header,
  622.           'nom_service' => $nom_service,
  623.           'team' => $team,
  624.           'centers' => $centersLiesTab,
  625.           'events' => $events,
  626.           'city' => $ville,
  627.           'coords' => $coords,
  628.           'relatedServices' => $relatedServices,
  629.         ),
  630.         'search' => ['filter' => $buttons],
  631.         'title' => $hospital->getCorporateName()
  632.       ));
  633.       $map['markers'][] = array(
  634.         "lat" => $lat,
  635.         "lon" => $lng,
  636.         "premium" => true,
  637.         "src" => "url(" $logoPersonne ")"
  638.       );
  639.       /************** Title & Description seo *****************/
  640.       $title_seo $hospital->getCorporateName() . ' à ' $this->dataProvider->wordUpperCaseFirstLetter($ville) . ' (' $zipcode ') - Service ' $nom_service;
  641.       if ($hospital->getCorporateName2()) {
  642.         $title_seo .= ' - ' $hospital->getCorporateName2();
  643.       }
  644.       $description_seo "Prenez rendez-vous avec le service " $nom_service " " $hospital->getCorporateName() . " à " $this->dataProvider->wordUpperCaseFirstLetter($ville) . " (" $zipcode "). Consultez ses coordonnées et son adresse sur l'Annuaire de l'Audition.";
  645.       // Breadcrumb //
  646.       $this->breadDatas['departementTexte'] = $departementTexte;
  647.       $this->breadDatas['departementCode'] = $depcode;
  648.       $this->breadDatas['ville'] = $ville;
  649.       $this->breadDatas['zipcode'] = $zipcode;
  650.       $this->breadDatas['final'] = $hospital->getCorporateName();
  651.       $this->setBreadcrumb('services''single');
  652.       $searchtype['lat'] = $lat;
  653.       $searchtype['lng'] = $lng;
  654.       $searchtype['currentCityId'] = $localisation->getCities()->getId();
  655.       $this->setInternalLinkage('servicePage'$searchtype);
  656.       $this->setTemplateParameters(array('map' => $map));
  657.       $this->setTemplateParameters(array('title_seo' => $title_seo));
  658.       $this->setTemplateParameters(array('description_seo' => $description_seo));
  659.       $this->setTemplateParameters(array('dataLayerCenters' => $centersLiesTab'creative' => 'services-orl'));
  660.       if ($idservice) {
  661.         $this->setTemplateParameters(array('idService' => $idservice));
  662.         // on cherche le cache des parkings
  663.         if (file_exists('overpass/parkings/service/service-' intval($idservice) . '.json')) {
  664.           $data json_decode(file_get_contents('overpass/parkings/service/service-' intval($idservice) . '.json'));
  665.           $parkings $this->renderView('modules/map/nearby.html.twig', array(
  666.             'type' => "parkings",
  667.             'parkings' => (array)$data
  668.           ));
  669.           $this->setTemplateParameters(array('parkings' => $parkings));
  670.         }
  671.         $transport_communs = [];
  672.         // on cherche le cache des bus
  673.         if (file_exists('overpass/buses/service/service-' intval($idservice) . '.json')) {
  674.           $data json_decode(file_get_contents('overpass/buses/service/service-' intval($idservice) . '.json'));
  675.           if ($data) {
  676.             $transport_communs['buses'] = $data;
  677.           }
  678.           $buses $this->renderView('modules/map/nearby.html.twig', array(
  679.             'type' => "transport",
  680.             'subtype' => "buses",
  681.             'buses' => (array)$data
  682.           ));
  683.           $this->setTemplateParameters(array('buses' => $buses));
  684.         }
  685.         // on cherche le cache des métros/trains
  686.         if (file_exists('overpass/subways/service/service-' intval($idservice) . '.json')) {
  687.           $data json_decode(file_get_contents('overpass/subways/service/service-' intval($idservice) . '.json'));
  688.           if ($data) {
  689.             $transport_communs['subways'] = $data;
  690.           }
  691.           $subways $this->renderView('modules/map/nearby.html.twig', array(
  692.             'type' => "transport",
  693.             'subtype' => "subways",
  694.             'subways' => (array)$data
  695.           ));
  696.           $this->setTemplateParameters(array('subways' => $subways));
  697.         }
  698.         // on cherche le cache des métros/trains
  699.         if (file_exists('overpass/trams/service/service-' intval($idservice) . '.json')) {
  700.           $data json_decode(file_get_contents('overpass/trams/service/service-' intval($idservice) . '.json'));
  701.           if ($data) {
  702.             $transport_communs['trams'] = $data;
  703.           }
  704.           $trams $this->renderView('modules/map/nearby.html.twig', array(
  705.             'type' => "transport",
  706.             'subtype' => "trams",
  707.             'trams' => (array)$data
  708.           ));
  709.           $this->setTemplateParameters(array('trams' => $trams));
  710.         }
  711.         // FAQ //
  712.         $faqs = [];
  713.         if ($service) {
  714.           $hospital $service->getHospital();
  715.           if ($hospital) {
  716.             //dd($service);
  717.             $address $hospital->getAddress();
  718.             $localisation $hospital->getLocalisation();
  719.             if ($localisation) {
  720.               $address .= " " $localisation->getZipcode() . " " $localisation->getcity();
  721.               $faqs[] = [
  722.                 "question" => "Quelle est l'adresse du service " $service->getName() . " - " $hospital->getCorporateName() . " ?",
  723.                 "response" => "L'adresse du service " $service->getName() . " - " $hospital->getCorporateName() . " est " $address
  724.               ];
  725.             }
  726.             $response_phone "";
  727.             $response_phone1 "";
  728.             $response_phone2 "";
  729.             if ($service->getDescription1()) $response_phone1 .= $service->getDescription1();
  730.             if ($service->getTitle1()) $response_phone1 $service->getTitle1() . " - " $response_phone1;
  731.             if ($service->getDescription2()) $response_phone2 .= $service->getDescription2();
  732.             if ($service->getTitle2()) $response_phone2 $service->getTitle2() . " - " $response_phone2;
  733.             $response_phone .= $response_phone1 "<li>" $response_phone1 "</li>" "";
  734.             $response_phone .= $response_phone2 "<li>" $response_phone2 "</li>" "";
  735.             $faqs[] = [
  736.               "question" => "Comment contacter le service " $service->getName() . " - " $hospital->getCorporateName() . " ?",
  737.               "response" => "Le service " $service->getName() . " - " $hospital->getCorporateName() . " peut être contacté par téléphone au :<ul>" $response_phone "</ul>"
  738.             ];
  739.           }
  740.           if ($team) {
  741.             $response_txt "";
  742.             foreach ($team as $doctor) {
  743.               $response_txt .= "<li>" $doctor['name'] . " (" $doctor['rolePerson'] . ")</li>";
  744.             }
  745.             $faqs[] = [
  746.               "question" => "Quels médecins ORL exercent dans le service " $service->getName() . " - " $hospital->getCorporateName() . " ?",
  747.               "response" => "Les médecins ORL suivants sont rattachés au service " $service->getName() . " - " $hospital->getCorporateName() . " : <ul>" $response_txt "</ul>"
  748.             ];
  749.           }
  750.           if ($transport_communs) {
  751.             $response_txt "<ul>";
  752.             foreach ($transport_communs as $type => $tc) {
  753.               $type $type == 'buses' 'Bus - ' : ($type == 'subways' 'Métro - ' 'Tram - ');
  754.               foreach ($tc as $value) {
  755.                 $response_txt .= "<li>" $type $value->name "</li>";
  756.               }
  757.             }
  758.             $response_txt .= "</ul>";
  759.             $faqs[] = [
  760.               "question" => "Comment accéder au service " $service->getName() . " - " $hospital->getCorporateName() . " par les transports en commun ?",
  761.               "response" => "Le service " $service->getName() . " - " $hospital->getCorporateName() . " est situé à proximité des arrêts suivants :<ul>" $response_txt "</ul>"
  762.             ];
  763.           }
  764.           $this->setTemplateParameters(array('faqs' => $faqs));
  765.         }
  766.       }
  767.       return $this->renderTemplate('pages/annuaire_page_ORLServices.twig');
  768.     }
  769.   }
  770. }