Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 970 Rev 981
Line 21... Line 21...
21
 * @version $Id$
21
 * @version $Id$
22
 * @copyright © 2010, Jean-Pascal MILCENT
22
 * @copyright © 2010, Jean-Pascal MILCENT
23
 */
23
 */
24
// TODO : supprimer le TRIM quand les obs seront reliées correctements aux localisations (sur le code INSEE par exemple)
24
// TODO : supprimer le TRIM quand les obs seront reliées correctements aux localisations (sur le code INSEE par exemple)
25
class CelWidgetMap extends Cel {
25
class CelWidgetMap extends Cel {
26
	
-
 
-
 
26
	const MARQUEUR_GROUPE = 'GROUPE';
-
 
27
	const MARQUEUR_COMMUNE = 'COMMUNE';
-
 
28
	const MARQUEUR_STATION = 'STATION';
27
	/**
29
	/**
28
	 * Méthode appelée avec une requête de type GET.
30
	 * Méthode appelée avec une requête de type GET.
29
	 */
31
	 */
30
	public function getElement($ressources) {
32
	public function getElement($ressources) {
31
		$retour = null;
33
		$retour = null;
32
		extract($this->parametres);
34
		extract($this->parametres);
-
 
35
		//Chronometre::chrono("Avant groupage");
Line 33... Line 36...
33
		
36
		
34
		$action = array_shift($ressources);
37
		$action = array_shift($ressources);
35
		if (isset($action)) {
38
		if (isset($action)) {
36
			$methode = $this->traiterNomMethodeGet($action);
39
			$methode = $this->traiterNomMethodeGet($action);
Line 40... Line 43...
40
				$this->messages[] = "Ce type de ressource '$methode' n'est pas disponible.";
43
				$this->messages[] = "Ce type de ressource '$methode' n'est pas disponible.";
41
			}
44
			}
42
		} else {
45
		} else {
43
			$this->messages[] = "Vous devez indiquer le type de ressource.";
46
			$this->messages[] = "Vous devez indiquer le type de ressource.";
44
		}
47
		}
45
 
48
		
-
 
49
		//Chronometre::chrono("Apres traitement");
-
 
50
		//echo Chronometre::afficherChrono();
46
		if (is_null($retour)) {
51
		if (is_null($retour)) {
47
			$info = 'Un problème est survenu : '.print_r($this->messages, true);
52
			$info = 'Un problème est survenu : '.print_r($this->messages, true);
48
			$this->envoyer($info);
53
			$this->envoyer($info);
49
		} else if ($retour['type'] == 'jsonVar') {
54
		} else if ($retour['type'] == 'jsonVar') {
Line 50... Line 55...
50
			
55
			
51
			$this->envoyerJsonVar($retour['variable_js'], $retour['donnees']);
56
			$this->envoyerJsonVar($retour['variable_js'], $retour['donnees']);
52
		}  else if ($retour['type'] == 'jsonP') {
57
		} else if ($retour['type'] == 'jsonP') {
-
 
58
			$this->envoyerJsonp($retour['donnees']);
-
 
59
		} else if ($retour['type'] == 'png') {
-
 
60
			header("Content-type: image/png");
-
 
61
			imagepng($retour['img']);
53
			$this->envoyerJsonp($retour['donnees']);
62
			imagedestroy($retour['img']);
54
		} else {
63
		} else {
55
			$this->envoyerJson($retour);
64
			$this->envoyerJson($retour);
56
		}
65
		}
57
	}
66
	}
-
 
67
	
-
 
68
	/**
-
 
69
	 * Les icones des groupes de stations
-
 
70
	 */
-
 
71
	public function getIconeGroupe($params) {
-
 
72
		extract($this->parametres);
-
 
73
		
-
 
74
		$img = imagecreatefrompng("/home/jpm/web/serveur/commun/icones/carto/groupe/g$type.png");
-
 
75
		
-
 
76
		$noir = imagecolorallocate($img, 0, 0, 0);
-
 
77
		$texte = (String) $nbre;
-
 
78
		$x = (imagesx($img) - 6.0 * strlen($texte)) / 2;
-
 
79
		$y = (imagesy($img) - 16) / 2;
-
 
80
		
-
 
81
		imagestring($img, 3, $x, $y, $texte, $noir);
-
 
82
		
-
 
83
		imagealphablending($img, false);
-
 
84
		imagesavealpha($img, true);
-
 
85
		
-
 
86
		return array('type' => 'png', 'img' => $img);
-
 
87
	}
58
 
88
	
59
	/**
89
	/**
60
	 * Les stations de la carte par défaut
90
	 * Les stations de la carte par défaut
61
	 */
91
	 */
62
	public function getStations($params) {
-
 
63
		
92
	public function getStations($params) {
64
		$json = null;
93
		$stations = null;
65
		$requete =  'SELECT sector, x_utm, y_utm, wgs84_latitude AS commune_latitude, wgs84_longitude AS commune_longitude, '.
-
 
66
					'	coord_x AS point_latitude, coord_y  AS point_longitude '.
94
		$requete =  'SELECT wgs84_latitude AS lat, wgs84_longitude AS lng, location AS nom '.
67
                    'FROM cel_inventory AS i '.
95
                    'FROM cel_inventory AS i '.
68
                    '   LEFT JOIN locations AS l '.
96
                    '   LEFT JOIN locations AS l '.
69
                    '       ON (l.name = i.location AND l.code = i.id_location) '.
97
                    '       ON (l.name = i.location AND l.code = i.id_location) '.
-
 
98
                    "WHERE transmission = '1' ".
-
 
99
					" AND (( ".
-
 
100
					"		(coord_x = '' OR coord_x IS NULL OR coord_x = '000null') ".
-
 
101
					" 		AND (coord_y = '' OR coord_y IS NULL OR coord_y = '000null') ".
-
 
102
					"	) OR mots_cles_texte LIKE '%sensible%') ".
70
                    "WHERE transmission = '1' ".
103
					$this->construireWhereRectangleCommune().
71
					$this->construireWhereDept().
104
					$this->construireWhereDept().
72
                    $this->construireWhereCommune().
105
                    $this->construireWhereCommune().
73
                    $this->construireWhereUtilisateur().
106
                    $this->construireWhereUtilisateur().
74
					$this->construireWhereNumTaxon().
107
					$this->construireWhereNumTaxon().
75
					$this->construireWhereNomTaxon().
108
					$this->construireWhereNomTaxon().
76
					$this->construireWhereDate().
109
					$this->construireWhereDate().
77
					$this->construireWhereCommentaire().
110
					$this->construireWhereCommentaire().
78
					$this->construireWhereProjet().
111
					$this->construireWhereProjet().
79
					$this->construireWhereTag();
-
 
80
		//die($requete);
-
 
Line 81... Line -...
81
		$resultats = $this->requeter($requete);
-
 
82
		
112
					$this->construireWhereTag();
Line -... Line 113...
-
 
113
		
83
		// Traitement des résultats
114
		$resultats_communes = $this->requeter($requete);
-
 
115
		
-
 
116
		$requete =  'SELECT coord_x AS lat, coord_y  AS lng, location AS nom '.
-
 
117
					'FROM cel_inventory AS i '.
-
 
118
                    '   LEFT JOIN locations AS l '.
-
 
119
                    '       ON (l.name = i.location AND l.code = i.id_location) '.
84
		$json['donnees'] = $this->traiterStations($resultats);
120
                    "WHERE transmission = '1' ".
85
		
121
					" AND coord_x != '' AND coord_x IS NOT NULL AND coord_x != '000null' ".
-
 
122
					" AND coord_y != '' AND coord_y IS NOT NULL AND coord_y != '000null' ".
-
 
123
					" AND (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE '%sensible%') ".
-
 
124
					$this->construireWhereRectangleStation().
-
 
125
					$this->construireWhereDept().
-
 
126
                    $this->construireWhereCommune().
-
 
127
                    $this->construireWhereUtilisateur().
-
 
128
					$this->construireWhereNumTaxon().
-
 
129
					$this->construireWhereNomTaxon().
-
 
130
					$this->construireWhereDate().
-
 
131
					$this->construireWhereCommentaire().
-
 
132
					$this->construireWhereProjet().
-
 
133
					$this->construireWhereTag();
Line 86... Line 134...
86
		// Création des infos du widget
134
					
87
		$json['type'] = (isset($this->formatRetour)) ? $this->formatRetour : 'jsonVar';
135
		$resultats_stations = $this->requeter($requete);
Line -... Line 136...
-
 
136
		$stations = $this->traiterStations($resultats_communes, $resultats_stations);
-
 
137
		
-
 
138
		return $stations;
-
 
139
	}
-
 
140
	
-
 
141
	public function getTout($params) {
-
 
142
		
-
 
143
		$emplacements = null;	
-
 
144
		$requete =  'SELECT DISTINCT location AS nom, '.
-
 
145
							"IF ((coord_x != '000null' AND coord_x != '' ".
-
 
146
								" AND coord_y != '000null' AND coord_y != ''), ".
-
 
147
								"'stations', ".
-
 
148
							"'communes' ".
-
 
149
							") as type_emplacement, ".
-
 
150
							"IF ((coord_x != '000null' AND coord_x != '' ".
-
 
151
								" AND coord_y != '000null' AND coord_y != ''), ".
-
 
152
								"ROUND(coord_x,5), ".
-
 
153
								"ROUND(wgs84_latitude,5) ".
-
 
154
							") as lat, ".
-
 
155
							"IF ((coord_x != '000null' AND coord_x != '' ".
-
 
156
								" AND coord_y != '000null' AND coord_y != ''), ".
-
 
157
								"ROUND(coord_y,5), ".
-
 
158
								"ROUND(wgs84_longitude,5) ".
-
 
159
							") as lng, ".
-
 
160
							"IF ((coord_x != '000null' AND coord_x != '' ".
-
 
161
								" AND coord_y != '000null' AND coord_y != ''), ".
-
 
162
								'CONCAT("'.self::MARQUEUR_STATION.':",ROUND(coord_x,5),"|",ROUND(coord_y,5)), '.
-
 
163
								'CONCAT("'.self::MARQUEUR_COMMUNE.':",ROUND(wgs84_latitude,5),"|",ROUND(wgs84_longitude,5)) '.
-
 
164
							") as id ".
-
 
165
					'FROM cel_inventory AS i '.
-
 
166
                    '   LEFT JOIN locations AS l '.
-
 
167
                    '       ON (l.name = i.location AND l.code = i.id_location) '.
-
 
168
                    "WHERE transmission = '1' ".
-
 
169
					" AND (".	
-
 
170
						"(".$this->construireWhereRectangleStationOR().
-
 
171
							" AND (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE '%sensible%') ".
-
 
172
						")".
-
 
173
						" OR ".
-
 
174
						" ( ".
-
 
175
							$this->construireWhereRectangleCommuneOR().
-
 
176
							" OR mots_cles_texte LIKE '%sensible%' ".
-
 
177
						" ) ".
-
 
178
					") ".		
-
 
179
					$this->construireWhereDept().
-
 
180
                    $this->construireWhereCommune().
-
 
181
                    $this->construireWhereUtilisateur().
-
 
182
					$this->construireWhereNumTaxon().
-
 
183
					$this->construireWhereNomTaxon().
-
 
184
					$this->construireWhereDate().
-
 
185
					$this->construireWhereCommentaire().
-
 
186
					$this->construireWhereProjet().
-
 
187
					$this->construireWhereTag();
-
 
188
						
-
 
189
		$resultats_emplacements = $this->executerRequete($requete);
-
 
190
		$emplacements = $this->traiterEmplacements($resultats_emplacements);
88
		$json['variable_js'] = 'stations';
191
		
-
 
192
		return $emplacements;
-
 
193
		
-
 
194
	}
89
		
195
	
-
 
196
	private function traiterEmplacements(&$emplacements) {
90
		return $json;
197
		$zoom = (int) array_key_exists('zoom', $this->parametres) ? $this->parametres['zoom'] : 11;
-
 
198
		$distance = (int) array_key_exists('distance', $this->parametres) ? $this->parametres['distance'] : 20;
-
 
199
		
-
 
200
		$marqueurs = array(
-
 
201
			'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
-
 
202
			'points' => null
-
 
203
		);
-
 
204
						
91
	}
205
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
206
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
207
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
208
			$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree($emplacements, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
-
 
209
			
-
 
210
			$nb_elements = CartoGroupage::getNbElements();
-
 
211
			
92
	
212
			$marqueurs['stats']['stations'] = $nb_elements['stations'];
-
 
213
			$marqueurs['stats']['communes'] = $nb_elements['communes'];
93
	private function traiterNbreObs($resultats) {
214
			$marqueurs['stats']['observations'] = $nb_elements['observations'];
94
		$obs_nbre = 0;
215
		} else {
Line 95... Line 216...
95
		if ($resultats !== false) {
216
			$marqueurs['points'] = $emplacements;
-
 
217
		}
-
 
218
 
-
 
219
		return $marqueurs;
96
			$obs_nbre = count($resultats);
220
	}
97
		}
221
	
98
		return $obs_nbre;
222
	private function traiterStations($communes, $stations) {
99
	}
223
		$zoom = (int) array_key_exists('zoom', $this->parametres) ? $this->parametres['zoom'] : 11;
100
	
224
		$distance = (int) array_key_exists('distance', $this->parametres) ? $this->parametres['distance'] : 20;
Line 101... Line 225...
101
	private function traiterStations($resultats) {
225
		
102
		$stations = array(
226
		$marqueurs = array(
103
			'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
227
			'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
104
			'points' => null
228
			'points' => null
105
		);
229
		);
-
 
230
		$marqueurs['stats']['observations'] = $this->traiterNbreObs($communes) + $this->traiterNbreObs($stations);
-
 
231
		
106
		$stations['stats']['observations'] = $this->traiterNbreObs($resultats);
232
		$points = array();
107
		
233
		if ($communes !== false) {
-
 
234
			foreach ($communes as $commune) {
108
		$points = array();
235
				if (is_numeric($commune['lat']) && is_numeric($commune['lng'])) {
109
		if ($resultats !== false) {
236
					extract($commune);
-
 
237
					$id = self::MARQUEUR_COMMUNE.':'.$lat.'|'.$lng;
110
			foreach ($resultats as $enrg) {
238
					$this->definirLatLngMaxMin($marqueurs, $lat, $lng);
111
				if (!$this->etreNull($enrg['point_latitude'])&& !$this->etreNull($enrg['point_longitude'])) {
239
					$lata = round($lat, 5);
112
					$lat = $enrg['point_latitude'];
240
					$lnga = round($lng, 5);
113
					$lng = $enrg['point_longitude'];
241
	
114
					$id = $lat.'-'.$lng;
242
					if (!isset($points[$id])) {
115
					if (!isset($points[$id])) {
243
						$points[$id]['id'] = $id;
116
						$points[$id]['id'] = "POINT:$lat-$lng";
244
						$points[$id]['nom'] = $nom;
-
 
245
						$points[$id]['lat'] = $lata;
-
 
246
						$points[$id]['lng'] = $lnga;
-
 
247
						$points[$id]['nbre'] = 1;
-
 
248
						$marqueurs['stats']['communes']++;
-
 
249
					} else {
117
						$points[$id]['lat'] = round($lat, 5);
250
						$points[$id]['nbre']++;
-
 
251
					}
-
 
252
				}
-
 
253
			}
118
						$points[$id]['lng'] = round($lng, 5);
254
		}
119
						$points[$id]['nbre'] = 1;
255
		if ($stations !== false) {
120
						$stations['stats']['stations']++;
256
			foreach ($stations as $station) {
-
 
257
				if (is_numeric($station['lat']) && is_numeric($station['lng'])) {
121
					} else {
258
					extract($station);
122
						$points[$id]['nbre']++;
259
					$id = self::MARQUEUR_STATION.':'.$lat.'|'.$lng;
-
 
260
					$this->definirLatLngMaxMin($marqueurs, $lat, $lng);
123
					}
261
					$lata = round($lat, 5);
124
				} else if (!$this->etreNull($enrg['commune_latitude'])&& !$this->etreNull($enrg['commune_longitude'])) {
262
					$lnga = round($lng, 5);
125
					$lat = $enrg['commune_latitude'];
263
					$nom = $this->etreNull($nom) ? $lata.','.$lnga : $nom;
126
					$lng = $enrg['commune_longitude'];
264
	
127
					$id = $lat.'-'.$lng;
265
					if (!isset($points[$id])) {
128
					if (!isset($points[$id])) {
266
						$points[$id]['id'] = $id;
129
						$points[$id]['id'] = "COMMUNE:$lat-$lng";
267
						$points[$id]['nom'] = $nom;
130
						$points[$id]['lat'] = round($lat, 5);
268
						$points[$id]['lat'] = $lata;
131
						$points[$id]['lng'] = round($lng, 5);
269
						$points[$id]['lng'] = $lnga;
132
						$points[$id]['nbre'] = 1;
-
 
133
						$stations['stats']['communes']++;
270
						$points[$id]['nbre'] = 1;
-
 
271
						$marqueurs['stats']['stations']++;
-
 
272
					} else {
-
 
273
						$points[$id]['nbre']++;
-
 
274
					}
-
 
275
				}
-
 
276
			}
-
 
277
		}
-
 
278
		
-
 
279
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
280
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
281
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
282
			$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree(&$points, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
-
 
283
		} else {
-
 
284
			$marqueurs['points'] = $points;
-
 
285
		}
-
 
286
		$marqueurs['stats']['latDiff'] = abs($marqueurs['stats']['latMin'] - $marqueurs['stats']['latMax']);
-
 
287
		$marqueurs['stats']['lngDiff'] = abs($marqueurs['stats']['lngMin'] - $marqueurs['stats']['lngMax']);
-
 
288
		
-
 
289
		return $marqueurs;
-
 
290
	}
-
 
291
	
-
 
292
	private function definirLatLngMaxMin(&$marqueurs, $lat, $lng) {
-
 
293
		if ($lat != null && $lng != null) {
-
 
294
			$marqueurs['stats']['latMin'] = $marqueurs['stats']['latMin'] > $lat ? $lat : $marqueurs['stats']['latMin'];
-
 
295
			$marqueurs['stats']['lngMin'] = $marqueurs['stats']['lngMin'] > $lng ? $lng : $marqueurs['stats']['lngMin'];
-
 
296
			$marqueurs['stats']['latMax'] = $marqueurs['stats']['latMax'] < $lat ? $lat : $marqueurs['stats']['latMax'];
-
 
297
			$marqueurs['stats']['lngMax'] = $marqueurs['stats']['lngMax'] < $lng ? $lng : $marqueurs['stats']['lngMax'];
-
 
298
		}
-
 
299
	}
-
 
300
	
-
 
301
	private function traiterNbreObs($resultats) {
-
 
302
		$obs_nbre = 0;
-
 
303
		if ($resultats !== false) {
-
 
304
			$obs_nbre = count($resultats);
-
 
305
		}
-
 
306
		return $obs_nbre;
-
 
307
	}
-
 
308
	
-
 
309
	private function verifierLatLng($lat, $lng) {
-
 
310
		$ok_lat = $this->etreLatitude($lat) ? true : false;
-
 
311
		$ok_lng = $this->etreLongitude($lng) ? true : false;
-
 
312
		$ok = $ok_lat && $ok_lng;
-
 
313
		return $ok; 
-
 
314
	}
-
 
315
	
-
 
316
	private function etreLatitude($lat) {
-
 
317
		$ok = false;
-
 
318
		//$format =  preg_match('/^[-]?[0-9]+(?:[.][0-9]+|)$/', $lat) ? true : false;
-
 
319
		$ok = ($lat >= -90 && $lat <= 90) ? true : false;
-
 
320
		return $ok;
-
 
321
	}
-
 
322
	
-
 
323
	private function etreLongitude($lng) {
-
 
324
		$ok = false;
-
 
325
		//$format =  preg_match('/^[-]?[0-9]+(?:[.][0-9]+|)$/', $lng) ? true : false;
-
 
326
		$ok = ($lng >= -180 && $lng <= 180) ? true : false;
-
 
327
		return $ok;
134
					} else {
328
	}
135
						$points[$id]['nbre']++;
329
	
Line 136... Line 330...
136
					}
330
	private function etreObsSensible($tags) {
137
				} 
331
		$sensible = true;
138
			}
332
		if (stristr($tags, 'sensible') === FALSE) {
Line 172... Line 366...
172
			$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
366
			$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
173
		}
367
		}
Line 174... Line 368...
174
		
368
		
175
		// Post-traitement
369
		// Post-traitement
176
		$observations = $this->traiterObservations($resultats, $total);
370
		$observations = $this->traiterObservations($resultats, $total);
177
		$observations = $this->ajouterImagesAuxObs($observations);
371
		//$observations = $this->ajouterImagesAuxObs($observations);
178
		$observations = $this->ajouterAuteursAuxObs($observations);
372
		//$observations = $this->ajouterAuteursAuxObs($observations);
-
 
373
		$observations = $this->supprimerIdDesObs($observations);
179
		$observations = $this->supprimerIdDesObs($observations);
374
		
180
		return $observations;
375
		return $observations;
Line 181... Line 376...
181
	}
376
	}
182
	
377
	
Line 305... Line 500...
305
					$this->construireWhereNumTaxon().
500
					$this->construireWhereNumTaxon().
306
					$this->construireWhereNomTaxon().
501
					$this->construireWhereNomTaxon().
307
					$this->construireWhereDate().
502
					$this->construireWhereDate().
308
					$this->construireWhereCommentaire().
503
					$this->construireWhereCommentaire().
309
					$this->construireWhereProjet().
504
					$this->construireWhereProjet().
310
					$this->construireWhereTag();
505
					$this->construireWhereTag().
311
					'ORDER BY nom_ret ASC '.
506
					'ORDER BY nom_ret ASC '.
312
                    "LIMIT {$this->start},{$this->limit} ";
507
                    "LIMIT {$this->start},{$this->limit} ";
313
		//$this->debug[] = $requete;
508
		//$this->debug[] = $requete;
314
		$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
509
		$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
Line 343... Line 538...
343
	private function construireWhereCoordonnees() {
538
	private function construireWhereCoordonnees() {
344
		$sql = '';
539
		$sql = '';
345
		// Récupération des coordonnées depuis l'id station
540
		// Récupération des coordonnées depuis l'id station
346
		extract($this->decomposerParametreStation());
541
		extract($this->decomposerParametreStation());
347
		if (isset($type)) {
542
		if (isset($type)) {
348
			if ($type == 'COMMUNE') {
543
			if ($type == self::MARQUEUR_COMMUNE) {
349
				$lat = $this->proteger($lat);
544
				$lat = $this->proteger($lat);
350
				$lng = $this->proteger($lng);
545
				$lng = $this->proteger($lng);
351
				$sql = " AND (wgs84_latitude = $lat AND wgs84_longitude = $lng) ";
546
				$sql = " AND (wgs84_latitude = $lat AND wgs84_longitude = $lng) ";
352
			}  else if ($type == 'POINT') {
547
			}  else if ($type == self::MARQUEUR_STATION) {
353
				$lat = $this->proteger($lat);
548
				$lat = $this->proteger($lat);
354
				$lng = $this->proteger($lng);
549
				$lng = $this->proteger($lng);
355
				$sql = " AND (coord_x = $lat AND coord_y = $lng) ";
550
				$sql = " AND (coord_x = $lat AND coord_y = $lng) ";
356
			}
551
			}
357
		}		
552
		}		
Line 581... Line 776...
581
		}
776
		}
582
		$sql = " $operateur ($sql) ";
777
		$sql = " $operateur ($sql) ";
583
		return $sql;
778
		return $sql;
584
	}
779
	}
Line -... Line 780...
-
 
780
	
-
 
781
	private function construireWhereRectangleStation() {
-
 
782
		$sql = '';
-
 
783
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
784
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
785
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
786
			
-
 
787
			$latMin = $sw['lat'];
-
 
788
			$lngMin = $sw['lng'];
-
 
789
			
-
 
790
			$latMax = $ne['lat'];
-
 
791
			$lngMax = $ne['lng'];
-
 
792
			
-
 
793
			// ATTENTION : coord_x correspond bien à la LATITUDE!
-
 
794
			$sql = " AND (coord_x != 0 AND coord_y != 0) ". 
-
 
795
				" AND coord_x > $latMin ".
-
 
796
				" AND coord_x < $latMax ".
-
 
797
				" AND coord_y > $lngMin ".
-
 
798
				" AND coord_y < $lngMax ";
-
 
799
		}
-
 
800
		return $sql;
-
 
801
	}
-
 
802
	
-
 
803
	private function construireWhereRectangleStationOR() {
-
 
804
		$sql = '';
-
 
805
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
806
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
807
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
808
			
-
 
809
			$latMin = $sw['lat'];
-
 
810
			$lngMin = $sw['lng'];
-
 
811
			
-
 
812
			$latMax = $ne['lat'];
-
 
813
			$lngMax = $ne['lng'];
-
 
814
			
-
 
815
			// ATTENTION : coord_x correspond bien à la LATITUDE!
-
 
816
			$sql = "( (coord_x != 0 AND coord_y != 0) ". 
-
 
817
				" AND coord_x > $latMin ".
-
 
818
				" AND coord_x < $latMax ".
-
 
819
				" AND coord_y > $lngMin ".
-
 
820
				" AND coord_y < $lngMax )";
-
 
821
		}
-
 
822
		return $sql;
-
 
823
	}
-
 
824
	
-
 
825
	private function construireWhereRectangleCommune() {
-
 
826
		$sql = '';
-
 
827
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
828
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
829
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
830
			
-
 
831
			$latMin = $sw['lat'];
-
 
832
			$lngMin = $sw['lng'];
-
 
833
			
-
 
834
			$latMax = $ne['lat'];
-
 
835
			$lngMax = $ne['lng'];
-
 
836
			
-
 
837
			$sql = "AND wgs84_longitude != 0 AND wgs84_latitude != 0 ". 
-
 
838
				" AND wgs84_latitude > $latMin ".
-
 
839
				" AND wgs84_latitude < $latMax ".
-
 
840
				" AND wgs84_longitude > $lngMin ".
-
 
841
				" AND wgs84_longitude < $lngMax ";
-
 
842
		}
-
 
843
		return $sql;
-
 
844
	}
-
 
845
	
-
 
846
	private function construireWhereRectangleCommuneOR() {
-
 
847
		$sql = '';
-
 
848
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
849
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
850
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
851
			
-
 
852
			$latMin = $sw['lat'];
-
 
853
			$lngMin = $sw['lng'];
-
 
854
			
-
 
855
			$latMax = $ne['lat'];
-
 
856
			$lngMax = $ne['lng'];
-
 
857
			
-
 
858
			$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ". 
-
 
859
				" AND wgs84_latitude > $latMin ".
-
 
860
				" AND wgs84_latitude < $latMax ".
-
 
861
				" AND wgs84_longitude > $lngMin ".
-
 
862
				" AND wgs84_longitude < $lngMax )";
-
 
863
		}
-
 
864
		return $sql;
-
 
865
	}
585
	
866
	
586
	private function construireWhereDept() {
867
	private function construireWhereDept() {
587
		$sql = '';
868
		$sql = '';
588
		// Récupération des coordonnées depuis l'id station
869
		// Récupération des coordonnées depuis l'id station
589
		extract($this->parametres);
870
		extract($this->parametres);
Line 824... Line 1105...
824
		}
1105
		}
825
		$this->debug[] = $mots_cles;
1106
		$this->debug[] = $mots_cles;
826
		return $mots_cles;
1107
		return $mots_cles;
827
	}
1108
	}
Line -... Line 1109...
-
 
1109
	
-
 
1110
	private function decomposerLatLng($coord) {
-
 
1111
		$lat_lng = array();
-
 
1112
		if (isset($coord)) {
-
 
1113
			list($lat, $lng) = explode('|', $coord);
-
 
1114
			$lat_lng = array('lat' => $lat, 'lng' => $lng);
-
 
1115
		}
-
 
1116
		return $lat_lng;
-
 
1117
	}
828
	
1118
	
829
	private function decomposerParametreStation() {
1119
	private function decomposerParametreStation() {
830
		$station_infos = array();
1120
		$station_infos = array();
831
		if (isset($this->parametres['station'])) {
1121
		if (isset($this->parametres['station'])) {
832
			$station = $this->parametres['station'];
1122
			$station = $this->parametres['station'];
833
			$this->debug[] = $station;
1123
			$this->debug[] = $station;
834
			list($type, $coord) = explode(':', $station);
1124
			list($type, $coord) = explode(':', $station);
Line 835... Line 1125...
835
			list($lat, $lng) = explode('-', $coord);
1125
			list($lat, $lng) = explode('|', $coord);
836
			
1126
			
837
			$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
1127
			$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
838
		}
1128
		}