Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1150 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1150 Rev 1154
Line 32... Line 32...
32
 
32
 
33
	private $lat = null;
33
	private $lat = null;
34
	private $lon = null;
34
	private $lon = null;
35
	private $zone = null;
35
	private $zone = null;
-
 
36
	private $niveaux = null;
Line 36... Line 37...
36
	private $niveaux = null;
37
	private $pays = null;
37
	
38
	
Line 38... Line 39...
38
	private $masque = null;
39
	private $masque = null;
Line 49... Line 50...
49
		$this->limite = isset($this->parametres['limite']) ? intval($this->parametres['limite']) : $this->limite;
50
		$this->limite = isset($this->parametres['limite']) ? intval($this->parametres['limite']) : $this->limite;
50
		$this->lat = isset($this->parametres['lat']) ? $this->parametres['lat'] : null;
51
		$this->lat = isset($this->parametres['lat']) ? $this->parametres['lat'] : null;
51
		$this->lon = isset($this->parametres['lon']) ? $this->parametres['lon'] : null;
52
		$this->lon = isset($this->parametres['lon']) ? $this->parametres['lon'] : null;
52
		$this->zone = isset($this->parametres['zone']) ? $this->parametres['zone'] : null;
53
		$this->zone = isset($this->parametres['zone']) ? $this->parametres['zone'] : null;
53
		$this->niveaux = isset($this->parametres['niveau']) ? explode(',', $this->parametres['niveau']) : null;
54
		$this->niveaux = isset($this->parametres['niveau']) ? explode(',', $this->parametres['niveau']) : null;
-
 
55
		$this->pays = isset($this->parametres['pays']) ? $this->parametres['pays'] : null;
Line 54... Line 56...
54
		
56
		
55
		if($this->masque != null) {
57
		if($this->masque != null) {
56
			$corps = $this->rechercherZoneGeoParNom($this->masque, $this->niveaux, $this->limite);
58
			$corps = $this->rechercherZoneGeoParNom($this->masque, $this->niveaux, $this->limite, $this->pays);
57
		} else {
59
		} else {
58
			$zoneTrouveeInfos = $this->localiserPointLatLon();
60
			$zoneTrouveeInfos = $this->localiserPointLatLon();
59
			$corps = $this->formaterResultats($zoneTrouveeInfos);
61
			$corps = $this->formaterResultats($zoneTrouveeInfos);
Line 120... Line 122...
120
			'FROM osm_zones_admin '.
122
			'FROM osm_zones_admin '.
121
			"WHERE st_within(GEOMFROMTEXT('POINT($this->lon $this->lat)'), polygone) = 1 ".
123
			"WHERE st_within(GEOMFROMTEXT('POINT($this->lon $this->lat)'), polygone) = 1 ".
122
			(isset($zone) ? "AND zone = $zone " : '').
124
			(isset($zone) ? "AND zone = $zone " : '').
123
			"AND osm_id IN ($osmIdsInClause) ".
125
			"AND osm_id IN ($osmIdsInClause) ".
124
			' -- '.__FILE__.' : '.__LINE__;
126
			' -- '.__FILE__.' : '.__LINE__;
-
 
127
		
125
		$resultat = $this->bdd->recupererTous($requete);
128
		$resultat = $this->bdd->recupererTous($requete);
126
		if ($resultat === false) {
129
		if ($resultat === false) {
127
			$msgTpl = "Service '%s' : aucune zone correspondant aux coordonnées : %s, %s.";
130
			$msgTpl = "Service '%s' : aucune zone correspondant aux coordonnées : %s, %s.";
128
			$msg = sprintf($msgTpl, get_class($this), $this->lat, $this->lon);
131
			$msg = sprintf($msgTpl, get_class($this), $this->lat, $this->lon);
129
			throw new Exception($msg, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
132
			throw new Exception($msg, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
Line 172... Line 175...
172
		$pageEncode = rawurlencode($page);
175
		$pageEncode = rawurlencode($page);
173
		$urlTpl = 'https://%s.wikipedia.org/wiki/%s';
176
		$urlTpl = 'https://%s.wikipedia.org/wiki/%s';
174
		return sprintf($urlTpl, $lang, $pageEncode);
177
		return sprintf($urlTpl, $lang, $pageEncode);
175
	}
178
	}
Line 176... Line 179...
176
	
179
	
177
	public function rechercherZoneGeoParNom($masque, $niveaux = null, $limite = 1) {
180
	public function rechercherZoneGeoParNom($masque, $niveaux = null, $limite = 1, $pays = null) {
178
		$masque_fmt = str_replace(array(' ', '-'), '_', $masque);
181
		$masque_fmt = str_replace(array(' ', '-'), '_', $masque);
179
		// Cas d'une recherche pour autocompletion
182
		// Cas d'une recherche pour autocompletion
Line 180... Line 183...
180
		$masque_fmt = ($limite > 1) ? $masque_fmt.'%' : $masque_fmt;
183
		$masque_fmt = ($limite > 1) ? $masque_fmt.'%' : $masque_fmt;
181
		
184
		
182
		$champs = 'id_zone_geo, osm_id, intitule, centre_lat, centre_lng, '.
185
		$champs = 'id_zone_geo, osm_id, intitule, centre_lat, centre_lng, '.
Line 183... Line 186...
183
					'zone, niveau, code_iso_3166_1, code_iso_3166_2, code_insee, '.
186
					'zone, niveau, code_iso_3166_1 AS codeIso31661, code_iso_3166_2 AS codeIso31662, code_insee, '.
184
					'nom, nom_fr, nom_en, nom_es, wikipedia';
187
					'nom, nom_fr, nom_en, nom_es, wikipedia';
185
		
188
		
186
		$champs_tri = 'IF(ISNULL(nom_fr), 0, 1) as nom_fr_present, '.
189
		$champs_tri = 'IF(ISNULL(nom_fr), 0, 1) as nom_fr_present, '.
187
				'IF(ISNULL(nom_en), 0, 1) as nom_en_present, '.
190
				'IF(ISNULL(nom_en), 0, 1) as nom_en_present, '.
-
 
191
				'IF(ISNULL(nom_es), 0, 1) as nom_es_present, '.
Line -... Line 192...
-
 
192
				'IF(ISNULL(intitule), 0, 1) as intitule_present, '.
-
 
193
				'IF(ISNULL(nom), 0, 1) as nom_present, '.
-
 
194
				'IF(zone = "north-america", 0, 1) as hors_amerique_du_nord ';
188
				'IF(ISNULL(nom_es), 0, 1) as nom_es_present, '.
195
		
189
				'IF(ISNULL(intitule), 0, 1) as intitule_present, '.
196
		// les US ont beaucoup de villes qui possèdent des noms similaires 
Line 190... Line 197...
190
				'IF(ISNULL(nom), 0, 1) as nom_present ';
197
		// à des villes européennes, ce qui entraine beaucoup de résultats vers les US
-
 
198
		// au lieu de la ville originelle, on les "déclasse" donc artificiellement
191
		
199
		$ordre = 'hors_amerique_du_nord DESC, niveau DESC, nom_present DESC, nom_fr_present DESC, nom_fr_present DESC, '.
192
		$ordre = 'nom_present DESC, nom_fr_present DESC, nom_fr_present DESC, '.
200
				 'nom_es_present DESC, intitule_present DESC';
-
 
201
		
-
 
202
		$niveau_str = array();
-
 
203
		if($niveaux != null) {
-
 
204
			foreach ($niveaux as $niveau) {
-
 
205
				$niveau_str[] = $this->bdd->proteger($niveau);
-
 
206
			}
-
 
207
		}
193
				 'nom_es_present DESC, intitule_present DESC, niveau DESC';
208
		
Line 194... Line 209...
194
		
209
		$pays_str = '';
195
		$niveau_str = array();
210
		if($pays != null) {
196
		foreach ($niveaux as $niveau) {
211
			$pays_str = '(code_iso_3166_1 = '.$this->bdd->proteger($pays).' OR  '.
-
 
212
			'code_iso_3166_2 LIKE '.$this->bdd->proteger($pays."%").')';
197
			$niveau_str[] = $this->bdd->proteger($niveau);
213
		}
198
		}
214
		
199
		
215
		$requete = "SELECT $champs, $champs_tri FROM osm_zones_admin ".
200
		$requete = "SELECT $champs, $champs_tri FROM osm_zones_admin ".
216
					"WHERE ".
201
					"WHERE ".
217
						(!empty($niveau_str) ? ("niveau IN (".implode(',', $niveau_str).") AND ") : "").
202
						(!empty($niveau_str) ? ("niveau IN (".implode(',', $niveau_str).") AND ") : "").
218
						(!empty($pays_str) ? $pays_str.' AND ' : ""). 
Line 203... Line 219...
203
						"(nom LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
219
						"(nom LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
204
						"intitule LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
220
						"intitule LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
205
						"nom_fr LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
221
						"nom_fr LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
206
						"nom_en LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
222
						"nom_en LIKE ".$this->bdd->proteger($masque_fmt).' OR '.