36,7 → 36,6 |
private $niveaux = null; |
|
private $masque = null; |
private $limite = 1; |
|
public function __construct(Bdd $bdd) { |
$this->bdd = $bdd; |
46,7 → 45,6 |
$this->parametres = $parametres; |
$this->verifierParametres(); |
$this->masque = isset($this->parametres['masque']) ? $this->parametres['masque'] : null; |
$this->limite = isset($this->parametres['limite']) ? intval($this->parametres['limite']) : $this->limite; |
$this->lat = isset($this->parametres['lat']) ? $this->parametres['lat'] : null; |
$this->lon = isset($this->parametres['lon']) ? $this->parametres['lon'] : null; |
$this->zone = isset($this->parametres['zone']) ? $this->parametres['zone'] : null; |
53,7 → 51,7 |
$this->niveaux = isset($this->parametres['niveau']) ? explode(',', $this->parametres['niveau']) : null; |
|
if($this->masque != null) { |
$corps = $this->rechercherZoneGeoParNom($this->masque, $this->niveaux, $this->limite); |
$corps = $this->rechercherZoneGeoParNom($this->masque); |
} else { |
$zoneTrouveeInfos = $this->localiserPointLatLon(); |
$corps = $this->formaterResultats($zoneTrouveeInfos); |
174,48 → 172,23 |
return sprintf($urlTpl, $lang, $pageEncode); |
} |
|
public function rechercherZoneGeoParNom($masque, $niveaux = null, $limite = 1) { |
public function rechercherZoneGeoParNom($masque) { |
$masque_fmt = str_replace(array(' ', '-'), '_', $masque); |
// Cas d'une recherche pour autocompletion |
$masque_fmt = ($limite > 1) ? $masque_fmt.'%' : $masque_fmt; |
|
$champs = 'id_zone_geo, osm_id, intitule, centre_lat, centre_lng, '. |
'zone, niveau, code_iso_3166_1, code_iso_3166_2, code_insee, '. |
'nom, nom_fr, nom_en, nom_es, wikipedia'; |
|
$champs_tri = 'IF(ISNULL(nom_fr), 0, 1) as nom_fr_present, '. |
'IF(ISNULL(nom_en), 0, 1) as nom_en_present, '. |
'IF(ISNULL(nom_es), 0, 1) as nom_es_present, '. |
'IF(ISNULL(intitule), 0, 1) as intitule_present, '. |
'IF(ISNULL(nom), 0, 1) as nom_present '; |
$requete = "SELECT $champs FROM osm_zones_admin WHERE nom_fr LIKE ".$this->bdd->proteger($masque_fmt).' '. |
"ORDER BY NIVEAU DESC LIMIT 1"; |
|
$ordre = 'nom_present DESC, nom_fr_present DESC, nom_fr_present DESC, '. |
'nom_es_present DESC, intitule_present DESC, niveau DESC'; |
|
$niveau_str = array(); |
foreach ($niveaux as $niveau) { |
$niveau_str[] = $this->bdd->proteger($niveau); |
} |
|
$requete = "SELECT $champs, $champs_tri FROM osm_zones_admin ". |
"WHERE ". |
(!empty($niveau_str) ? ("niveau IN (".implode(',', $niveau_str).") AND ") : ""). |
"(nom LIKE ".$this->bdd->proteger($masque_fmt).' OR '. |
"intitule LIKE ".$this->bdd->proteger($masque_fmt).' OR '. |
"nom_fr LIKE ".$this->bdd->proteger($masque_fmt).' OR '. |
"nom_en LIKE ".$this->bdd->proteger($masque_fmt).' OR '. |
"nom_es LIKE ".$this->bdd->proteger($masque_fmt).') '. |
"ORDER BY ".$ordre." LIMIT ".$limite; |
|
$resultat = $this->bdd->recupererTous($requete); |
if (empty($resultat)) { |
$msgTpl = "Service '%s' : aucune zone correspondant au nom : %s ."; |
$msg = sprintf($msgTpl, get_class($this), $masque); |
throw new Exception($msg, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE); |
} else { |
$resultat = ($limite == 1) ? $resultat[0] : $resultat; |
} |
|
return $resultat; |
return $resultat[0]; |
} |
} |