Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 1150 → Rev 1151

/trunk/services/modules/0.1/osm/ZoneAdmin.php
34,6 → 34,7
private $lon = null;
private $zone = null;
private $niveaux = null;
private $pays = null;
private $masque = null;
private $limite = 1;
51,9 → 52,10
$this->lon = isset($this->parametres['lon']) ? $this->parametres['lon'] : null;
$this->zone = isset($this->parametres['zone']) ? $this->parametres['zone'] : null;
$this->niveaux = isset($this->parametres['niveau']) ? explode(',', $this->parametres['niveau']) : null;
$this->pays = isset($this->parametres['pays']) ? $this->parametres['pays'] : null;
if($this->masque != null) {
$corps = $this->rechercherZoneGeoParNom($this->masque, $this->niveaux, $this->limite);
$corps = $this->rechercherZoneGeoParNom($this->masque, $this->niveaux, $this->limite, $this->pays);
} else {
$zoneTrouveeInfos = $this->localiserPointLatLon();
$corps = $this->formaterResultats($zoneTrouveeInfos);
122,6 → 124,7
(isset($zone) ? "AND zone = $zone " : '').
"AND osm_id IN ($osmIdsInClause) ".
' -- '.__FILE__.' : '.__LINE__;
$resultat = $this->bdd->recupererTous($requete);
if ($resultat === false) {
$msgTpl = "Service '%s' : aucune zone correspondant aux coordonnées : %s, %s.";
174,13 → 177,13
return sprintf($urlTpl, $lang, $pageEncode);
}
public function rechercherZoneGeoParNom($masque, $niveaux = null, $limite = 1) {
public function rechercherZoneGeoParNom($masque, $niveaux = null, $limite = 1, $pays = null) {
$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, '.
'zone, niveau, code_iso_3166_1 AS codeIso31661, code_iso_3166_2 AS codeIso31662, code_insee, '.
'nom, nom_fr, nom_en, nom_es, wikipedia';
$champs_tri = 'IF(ISNULL(nom_fr), 0, 1) as nom_fr_present, '.
192,20 → 195,29
$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);
$niveau_str = array();
if($niveaux != null) {
foreach ($niveaux as $niveau) {
$niveau_str[] = $this->bdd->proteger($niveau);
}
}
$pays_str = '';
if($pays != null) {
$pays_str = '(code_iso_3166_1 = '.$this->bdd->proteger($pays).' OR '.
'code_iso_3166_2 LIKE '.$this->bdd->proteger($pays."%").')';
}
$requete = "SELECT $champs, $champs_tri FROM osm_zones_admin ".
"WHERE ".
(!empty($niveau_str) ? ("niveau IN (".implode(',', $niveau_str).") AND ") : "").
(!empty($pays_str) ? $pays_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;
"nom_es LIKE ".$this->bdd->proteger($masque_fmt).') AND '.
"ORDER BY ".$ordre." LIMIT ".$limite;
 
$resultat = $this->bdd->recupererTous($requete);
if (empty($resultat)) {