Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 1148 → Rev 1149

/trunk/services/modules/0.1/osm/ZoneAdmin.php
36,6 → 36,7
private $niveaux = null;
private $masque = null;
private $limite = 1;
 
public function __construct(Bdd $bdd) {
$this->bdd = $bdd;
45,6 → 46,7
$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;
51,7 → 53,7
$this->niveaux = isset($this->parametres['niveau']) ? explode(',', $this->parametres['niveau']) : null;
if($this->masque != null) {
$corps = $this->rechercherZoneGeoParNom($this->masque);
$corps = $this->rechercherZoneGeoParNom($this->masque, $this->niveaux, $this->limite);
} else {
$zoneTrouveeInfos = $this->localiserPointLatLon();
$corps = $this->formaterResultats($zoneTrouveeInfos);
172,15 → 174,38
return sprintf($urlTpl, $lang, $pageEncode);
}
public function rechercherZoneGeoParNom($masque) {
public function rechercherZoneGeoParNom($masque, $niveaux = null, $limite = 1) {
$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';
$requete = "SELECT $champs FROM osm_zones_admin WHERE nom_fr LIKE ".$this->bdd->proteger($masque_fmt).' '.
"ORDER BY NIVEAU DESC LIMIT 1";
$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 ';
$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)) {
187,8 → 212,10
$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[0];
return $resultat;
}
}