Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1149 | Rev 1152 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1149 Rev 1151
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
		
Line 190... Line 193...
190
				'IF(ISNULL(nom), 0, 1) as nom_present ';
193
				'IF(ISNULL(nom), 0, 1) as nom_present ';
Line 191... Line 194...
191
		
194
		
192
		$ordre = 'nom_present DESC, nom_fr_present DESC, nom_fr_present DESC, '.
195
		$ordre = 'nom_present DESC, nom_fr_present DESC, nom_fr_present DESC, '.
Line 193... Line 196...
193
				 'nom_es_present DESC, intitule_present DESC, niveau DESC';
196
				 'nom_es_present DESC, intitule_present DESC, niveau DESC';
-
 
197
		
194
		
198
		$niveau_str = array();
195
		$niveau_str = array();
199
		if($niveaux != null) {
-
 
200
			foreach ($niveaux as $niveau) {
-
 
201
				$niveau_str[] = $this->bdd->proteger($niveau);
-
 
202
			}
-
 
203
		}
-
 
204
		
-
 
205
		$pays_str = '';
-
 
206
		if($pays != null) {
196
		foreach ($niveaux as $niveau) {
207
			$pays_str = '(code_iso_3166_1 = '.$this->bdd->proteger($pays).' OR  '.
Line 197... Line 208...
197
			$niveau_str[] = $this->bdd->proteger($niveau);
208
			'code_iso_3166_2 LIKE '.$this->bdd->proteger($pays."%").')';
198
		}
209
		}
199
		
210
		
-
 
211
		$requete = "SELECT $champs, $champs_tri FROM osm_zones_admin ".
200
		$requete = "SELECT $champs, $champs_tri FROM osm_zones_admin ".
212
					"WHERE ".
201
					"WHERE ".
213
						(!empty($niveau_str) ? ("niveau IN (".implode(',', $niveau_str).") AND ") : "").
202
						(!empty($niveau_str) ? ("niveau IN (".implode(',', $niveau_str).") AND ") : "").
214
						(!empty($pays_str) ? $pays_str.' AND ' : ""). 
203
						"(nom LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
215
						"(nom LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
204
						"intitule LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
216
						"intitule LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
205
						"nom_fr LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
217
						"nom_fr LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
Line 206... Line 218...
206
						"nom_en LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
218
						"nom_en LIKE ".$this->bdd->proteger($masque_fmt).' OR '.
207
						"nom_es LIKE ".$this->bdd->proteger($masque_fmt).') '.
219
						"nom_es LIKE ".$this->bdd->proteger($masque_fmt).') AND '.	
208
				"ORDER BY ".$ordre." LIMIT ".$limite;
220
			"ORDER BY ".$ordre." LIMIT ".$limite;
209
 
221