Subversion Repositories eFlore/Applications.cel

Rev

Rev 1043 | Rev 1334 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1043 Rev 1095
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
	const MARQUEUR_GROUPE = 'GROUPE';
-
 
27
	const MARQUEUR_COMMUNE = 'COMMUNE';
-
 
28
	const MARQUEUR_STATION = 'STATION';
-
 
-
 
26
	
29
	/**
27
	/**
30
	 * Méthode appelée avec une requête de type GET.
28
	 * Méthode appelée avec une requête de type GET.
31
	 */
29
	 */
32
	public function getElement($ressources) {
30
	public function getElement($ressources) {
33
		$retour = null;
31
		$retour = null;
34
		extract($this->parametres);
32
		extract($this->parametres);
35
		//Chronometre::chrono("Avant groupage");
-
 
Line 36... Line 33...
36
 
33
		
37
		$action = array_shift($ressources);
34
		$action = array_shift($ressources);
38
		if (isset($action)) {
35
		if (isset($action)) {
39
			$methode = $this->traiterNomMethodeGet($action);
36
			$methode = $this->traiterNomMethodeGet($action);
Line 44... Line 41...
44
			}
41
			}
45
		} else {
42
		} else {
46
			$this->messages[] = "Vous devez indiquer le type de ressource.";
43
			$this->messages[] = "Vous devez indiquer le type de ressource.";
47
		}
44
		}
Line 48... Line -...
48
 
-
 
49
		//Chronometre::chrono("Apres traitement");
-
 
50
		//echo Chronometre::afficherChrono();
45
 
51
		if (is_null($retour)) {
46
		if (is_null($retour)) {
52
			$info = 'Un problème est survenu : '.print_r($this->messages, true);
47
			$info = 'Un problème est survenu : '.print_r($this->messages, true);
53
			$this->envoyer($info);
48
			$this->envoyer($info);
-
 
49
		} else if ($retour['type'] == 'jsonVar') {
54
		} else if (isset($retour['type']) && $retour['type'] == 'jsonVar') {
50
			
55
			$this->envoyerJsonVar($retour['variable_js'], $retour['donnees']);
51
			$this->envoyerJsonVar($retour['variable_js'], $retour['donnees']);
56
		} else if (isset($retour['type']) && $retour['type'] == 'jsonP') {
52
		}  else if ($retour['type'] == 'jsonP') {
57
			$this->envoyerJsonp($retour['donnees']);
-
 
58
		} else if (isset($retour['type']) && $retour['type'] == 'png') {
-
 
59
			header("Content-type: image/png");
-
 
60
			imagepng($retour['img']);
-
 
61
			imagedestroy($retour['img']);
53
			$this->envoyerJsonp($retour['donnees']);
62
		} else {
54
		} else {
63
			$this->envoyerJson($retour);
55
			$this->envoyerJson($retour);
64
		}
56
		}
Line 65... Line 57...
65
	}
57
	}
66
 
-
 
67
	/**
-
 
68
	 * Les icones des groupes de stations
-
 
69
	 */
-
 
70
	public function getIconeGroupe($params) {
-
 
71
		extract($this->parametres);
-
 
72
 
-
 
73
		$chemin_marqueur = sprintf($this->config['settings']['cheminCelMarkerObsTpl'], $type);
-
 
74
		$img = imagecreatefrompng($chemin_marqueur);
-
 
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
	}
-
 
88
 
58
 
89
	/**
59
	/**
90
	 * Les stations de la carte par défaut
60
	 * Les stations de la carte par défaut
91
	 */
61
	 */
92
	public function getStations($params) {
62
	public function getStations($params) {
93
		$stations = null;
-
 
94
		$requete =  'SELECT wgs84_latitude AS lat, wgs84_longitude AS lng, location AS nom '.
-
 
95
                    'FROM cel_inventory AS i '.
-
 
96
                    '   LEFT JOIN locations AS l '.
-
 
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%') ".
-
 
103
					$this->construireWhereRectangleCommune().
-
 
104
					$this->construireWhereDept().
-
 
105
                    $this->construireWhereCommune().
-
 
106
                    $this->construireWhereUtilisateur().
-
 
107
					$this->construireWhereNumTaxon().
-
 
108
					$this->construireWhereNomTaxon().
-
 
109
					$this->construireWhereDate().
-
 
110
					$this->construireWhereCommentaire().
-
 
111
					$this->construireWhereProjet().
-
 
112
					$this->construireWhereTag();
-
 
113
 
-
 
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) '.
-
 
120
                    "WHERE transmission = '1' ".
-
 
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();
-
 
134
 
-
 
135
		$resultats_stations = $this->requeter($requete);
-
 
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
								"coord_x, ".
-
 
153
								"wgs84_latitude ".
-
 
154
							") as lat, ".
-
 
155
							"IF ((coord_x != '000null' AND coord_x != '' ".
-
 
156
								" AND coord_y != '000null' AND coord_y != ''), ".
-
 
157
								"coord_y, ".
-
 
158
								"wgs84_longitude ".
-
 
159
							") as lng, ".
-
 
160
							"IF ((coord_x != '000null' AND coord_x != '' ".
-
 
161
								" AND coord_y != '000null' AND coord_y != ''), ".
-
 
162
								'CONCAT("'.self::MARQUEUR_STATION.':",coord_x,"|",coord_y), '.
-
 
163
								'CONCAT("'.self::MARQUEUR_COMMUNE.':",wgs84_latitude,"|",wgs84_longitude) '.
-
 
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() != null ? $this->construireWhereRectangleStationOR().' AND ' : '').
-
 
171
							" (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE '%sensible%') ".
-
 
172
						")".
-
 
173
						" OR ".
-
 
174
						" ( ".
-
 
175
							"(".($this->construireWhereRectangleCommuneOR() != null ? $this->construireWhereRectangleCommuneOR().' Or ' : '').
-
 
176
							" mots_cles_texte LIKE '%sensible%' ".
-
 
177
							")".
-
 
178
						" ) ".
-
 
179
					") ".
-
 
180
					$this->construireWhereDept().
-
 
181
                    $this->construireWhereCommune().
-
 
182
                    $this->construireWhereUtilisateur().
-
 
183
					$this->construireWhereNumTaxon().
-
 
184
					$this->construireWhereNomTaxon().
-
 
185
					$this->construireWhereDate().
-
 
186
					$this->construireWhereCommentaire().
-
 
187
					$this->construireWhereProjet().
-
 
188
					$this->construireWhereTag();
-
 
189
 
-
 
190
		$resultats_emplacements = $this->executerRequete($requete);
-
 
191
		$emplacements = $this->traiterEmplacements($resultats_emplacements, $this->compterObservations($params));
-
 
192
 
-
 
193
		return $emplacements;
-
 
194
	}
-
 
195
 
-
 
196
	private $nb_obs = 0;
-
 
197
 
-
 
198
	private function compterObservations($params) {
63
		$json = null;
199
		$requete =  'SELECT COUNT(*) AS nb '.
64
		$requete =  'SELECT sector, x_utm, y_utm, wgs84_latitude AS coord_x, wgs84_longitude AS coord_y '.
200
					'FROM cel_inventory AS i '.
65
                    'FROM cel_inventory AS i '.
201
                    '   LEFT JOIN locations AS l '.
66
                    '   LEFT JOIN locations AS l '.
202
                    '       ON (l.name = i.location AND l.code = i.id_location) '.
-
 
203
                    "WHERE transmission = '1' ".
-
 
204
					" AND (".
-
 
205
						"(".($this->construireWhereRectangleStationOR() != null ? $this->construireWhereRectangleStationOR().' AND ' : '').
-
 
206
							" (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE '%sensible%') ".
-
 
207
						")".
-
 
208
						" OR ".
-
 
209
						" ( ".
-
 
210
							"(".($this->construireWhereRectangleCommuneOR() != null ? $this->construireWhereRectangleCommuneOR().' Or ' : '').
-
 
211
							" mots_cles_texte LIKE '%sensible%' ".
-
 
212
							")".
-
 
213
						" ) ".
67
                    '       ON (l.name = i.location AND l.code = i.id_location) '.
214
					") ".
68
                    "WHERE transmission = '1' ".
215
					$this->construireWhereDept().
69
					$this->construireWhereDept().
216
                    $this->construireWhereCommune().
70
                    $this->construireWhereCommune().
217
                    $this->construireWhereUtilisateur().
71
                    $this->construireWhereUtilisateur().
218
					$this->construireWhereNumTaxon().
72
					$this->construireWhereNumTaxon().
219
					$this->construireWhereNomTaxon().
73
					$this->construireWhereNomTaxon().
220
					$this->construireWhereDate().
74
					$this->construireWhereDate().
221
					$this->construireWhereCommentaire().
75
					$this->construireWhereCommentaire().
-
 
76
					$this->construireWhereProjet().
-
 
77
					$this->construireWhereTag();
Line 222... Line -...
222
					$this->construireWhereProjet().
-
 
223
					$this->construireWhereTag();
-
 
224
 
-
 
225
		$resultats_nb_obs = $this->executerRequete($requete);
-
 
226
		return $resultats_nb_obs[0]['nb'];
-
 
227
	}
-
 
228
 
-
 
229
	private function traiterEmplacements(&$emplacements, $nb_total_observation) {
-
 
230
		$zoom = (int) array_key_exists('zoom', $this->parametres) ? $this->parametres['zoom'] : 11;
-
 
231
		$distance = (int) array_key_exists('distance', $this->parametres) ? $this->parametres['distance'] : 20;
-
 
232
 
78
		//die($requete);
233
		$marqueurs = array(
-
 
234
			'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
-
 
235
			'points' => null
-
 
236
		);
79
		$resultats = $this->requeter($requete);
237
 
80
		
238
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
239
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
240
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
241
			$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree($emplacements, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
-
 
242
 
-
 
243
			// laisser la classe cartoGroupage compter les élements simplifie le comptage
-
 
244
			// et permet de ne pas reparser le tableau pour compter les différents éléments
-
 
245
			$nb_elements = CartoGroupage::getNbElements();
-
 
246
 
-
 
247
			$marqueurs['stats']['stations'] = $nb_elements['stations'];
-
 
248
			$marqueurs['stats']['communes'] = $nb_elements['communes'];
-
 
249
			$marqueurs['stats']['observations'] = (int)$nb_total_observation;
-
 
250
		} else {
-
 
251
			$marqueurs['points'] = $emplacements;
-
 
252
		}
-
 
Line 253... Line -...
253
 
-
 
254
		return $marqueurs;
-
 
255
	}
-
 
256
 
-
 
257
	private function traiterStations($communes, $stations) {
-
 
258
		$zoom = (int) array_key_exists('zoom', $this->parametres) ? $this->parametres['zoom'] : 11;
-
 
259
		$distance = (int) array_key_exists('distance', $this->parametres) ? $this->parametres['distance'] : 20;
-
 
260
 
-
 
261
		$marqueurs = array(
-
 
262
			'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
-
 
263
			'points' => null
-
 
264
		);
-
 
265
		$marqueurs['stats']['observations'] = $this->traiterNbreObs($communes) + $this->traiterNbreObs($stations);
-
 
266
 
-
 
267
		$points = array();
-
 
268
		if ($communes !== false) {
-
 
269
			foreach ($communes as $commune) {
-
 
270
				if (is_numeric($commune['lat']) && is_numeric($commune['lng'])) {
-
 
271
					extract($commune);
-
 
272
					$id = self::MARQUEUR_COMMUNE.':'.$lat.'|'.$lng;
-
 
273
					//$this->definirLatLngMaxMin($marqueurs, $lat, $lng);
-
 
274
					$lata = round($lat, 5);
-
 
275
					$lnga = round($lng, 5);
-
 
276
 
-
 
277
					if (!isset($points[$id])) {
-
 
278
						$points[$id]['id'] = $id;
-
 
279
						$points[$id]['nom'] = $nom;
-
 
280
						$points[$id]['lat'] = $lata;
-
 
281
						$points[$id]['lng'] = $lnga;
-
 
282
						$points[$id]['nbre'] = 1;
-
 
283
						$marqueurs['stats']['communes']++;
-
 
284
					} else {
-
 
285
						$points[$id]['nbre']++;
-
 
286
					}
81
		// Traitement des résultats
287
				}
82
		$obs_nbre = $this->traiterNbreObs($resultats);
288
			}
83
		$stations = $this->traiterStations($resultats);
289
		}
-
 
290
		if ($stations !== false) {
-
 
291
			foreach ($stations as $station) {
-
 
292
				if (is_numeric($station['lat']) && is_numeric($station['lng'])) {
-
 
293
					extract($station);
-
 
294
					$id = self::MARQUEUR_STATION.':'.$lat.'|'.$lng;
-
 
295
					//$this->definirLatLngMaxMin($marqueurs, $lat, $lng);
-
 
296
					$lata = round($lat, 5);
-
 
297
					$lnga = round($lng, 5);
-
 
298
					$nom = $this->etreNull($nom) ? $lata.','.$lnga : $nom;
-
 
299
 
-
 
300
					if (!isset($points[$id])) {
-
 
301
						$points[$id]['id'] = $id;
-
 
302
						$points[$id]['nom'] = $nom;
84
		
303
						$points[$id]['lat'] = $lata;
-
 
304
						$points[$id]['lng'] = $lnga;
-
 
305
						$points[$id]['nbre'] = 1;
-
 
306
						$marqueurs['stats']['stations']++;
-
 
307
					} else {
-
 
308
						$points[$id]['nbre']++;
-
 
309
					}
-
 
310
				}
-
 
311
			}
-
 
312
		}
-
 
313
 
-
 
314
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
315
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
316
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
317
			$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree(&$points, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
-
 
318
		} else {
-
 
Line -... Line 85...
-
 
85
		// Création des infos du widget
319
			$marqueurs['points'] = $points;
86
		$json['donnees']['points'] = $stations;
320
		}
-
 
Line 321... Line -...
321
		//$marqueurs['stats']['latDiff'] = abs($marqueurs['stats']['latMin'] - $marqueurs['stats']['latMax']);
-
 
322
		//$marqueurs['stats']['lngDiff'] = abs($marqueurs['stats']['lngMin'] - $marqueurs['stats']['lngMax']);
87
		$json['donnees']['stats']['communes'] = count($stations);
323
 
-
 
324
		return $marqueurs;
-
 
325
	}
-
 
326
 
-
 
327
	private function definirLatLngMaxMin(&$marqueurs, $lat, $lng) {
-
 
328
		if ($lat != null && $lng != null) {
88
		$json['donnees']['stats']['observations'] = $obs_nbre;
Line 329... Line 89...
329
			$marqueurs['stats']['latMin'] = $marqueurs['stats']['latMin'] > $lat ? $lat : $marqueurs['stats']['latMin'];
89
		
330
			$marqueurs['stats']['lngMin'] = $marqueurs['stats']['lngMin'] > $lng ? $lng : $marqueurs['stats']['lngMin'];
90
		$json['type'] = (isset($this->formatRetour)) ? $this->formatRetour : 'jsonVar';
331
			$marqueurs['stats']['latMax'] = $marqueurs['stats']['latMax'] < $lat ? $lat : $marqueurs['stats']['latMax'];
91
		$json['variable_js'] = 'stations';
332
			$marqueurs['stats']['lngMax'] = $marqueurs['stats']['lngMax'] < $lng ? $lng : $marqueurs['stats']['lngMax'];
92
		
333
		}
93
		return $json;
334
	}
94
	}
335
 
95
	
Line 336... Line 96...
336
	private function traiterNbreObs($resultats) {
96
	private function traiterNbreObs($resultats) {
-
 
97
		$obs_nbre = 0;
-
 
98
		if ($resultats !== false) {
337
		$obs_nbre = 0;
99
			$obs_nbre = count($resultats);
-
 
100
		}
338
		if ($resultats !== false) {
101
		return $obs_nbre;
-
 
102
	}
-
 
103
	
-
 
104
	private function traiterStations($resultats) {
-
 
105
		$stations = array();
-
 
106
		if ($resultats !== false) {
339
			$obs_nbre = count($resultats);
107
			foreach ($resultats as $enrg) {
-
 
108
				if ($enrg['coord_x'] != null && $enrg['coord_y'] != null) {
340
		}
109
					$id = $enrg['coord_x'].'-'.$enrg['coord_y'];
-
 
110
					if (!isset($stations[$id])) {
341
		return $obs_nbre;
111
						$enrg['id'] = 'UTM:'.$enrg['x_utm'].'-'.$enrg['y_utm'].'-'.$enrg['sector'];
342
	}
-
 
343
 
-
 
344
	private function verifierLatLng($lat, $lng) {
-
 
345
		$ok_lat = $this->etreLatitude($lat) ? true : false;
-
 
346
		$ok_lng = $this->etreLongitude($lng) ? true : false;
-
 
347
		$ok = $ok_lat && $ok_lng;
-
 
348
		return $ok;
112
						unset($enrg['x_utm']);
349
	}
-
 
350
 
-
 
351
	private function etreLatitude($lat) {
-
 
352
		$ok = false;
-
 
353
		//$format =  preg_match('/^[-]?[0-9]+(?:[.][0-9]+|)$/', $lat) ? true : false;
-
 
354
		$ok = ($lat >= -90 && $lat <= 90) ? true : false;
-
 
355
		return $ok;
113
						unset($enrg['y_utm']);
356
	}
-
 
357
 
114
						unset($enrg['sector']);
358
	private function etreLongitude($lng) {
-
 
359
		$ok = false;
-
 
360
		//$format =  preg_match('/^[-]?[0-9]+(?:[.][0-9]+|)$/', $lng) ? true : false;
-
 
361
		$ok = ($lng >= -180 && $lng <= 180) ? true : false;
115
						$stations[$id] = $enrg;
362
		return $ok;
116
						$stations[$id]['nbre'] = 1;
363
	}
117
					} else {
Line 364... Line 118...
364
 
118
						$stations[$id]['nbre']++;
365
	private function etreObsSensible($tags) {
119
					}
366
		$sensible = true;
120
				}
Line 382... Line 136...
382
						'	sector, x_utm, y_utm, insee_code, date_transmission '.
136
						'	sector, x_utm, y_utm, insee_code, date_transmission '.
383
						'FROM cel_inventory AS i '.
137
						'FROM cel_inventory AS i '.
384
						'	LEFT JOIN locations AS l '.
138
						'	LEFT JOIN locations AS l '.
385
						"		ON (l.name = i.location AND l.code = i.id_location) ".
139
						"		ON (l.name = i.location AND l.code = i.id_location) ".
386
						"WHERE transmission = '1' ".
140
						"WHERE transmission = '1' ".
387
						((!$this->etreNull($this->parametres['commune'])) ? $this->construireWhereCommuneSansCoordonnees() : $this->construireWhereCoordonnees()).
141
						$this->construireWhereCoordonnees().
388
						$this->construireWhereUtilisateur().
142
						$this->construireWhereUtilisateur().
389
						$this->construireWhereNumTaxon().
143
						$this->construireWhereNumTaxon().
390
						$this->construireWhereNomTaxon().
144
						$this->construireWhereNomTaxon().
391
						$this->construireWhereDate().
145
						$this->construireWhereDate().
392
						$this->construireWhereCommentaire().
146
						$this->construireWhereCommentaire().
393
						$this->construireWhereProjet().
147
						$this->construireWhereProjet().
394
						$this->construireWhereTag().
148
						$this->construireWhereTag().
395
	                    'ORDER BY nom_sel ASC '.
149
	                    'ORDER BY nom_sel ASC '.
396
	                    "LIMIT {$this->start},{$this->limit} ";
150
	                    "LIMIT {$this->start},{$this->limit} ";
397
 
-
 
-
 
151
			//die($requete);
398
			$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
152
			$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
-
 
153
			
399
			$requete = 'SELECT FOUND_ROWS()';
154
			$requete = 'SELECT FOUND_ROWS()';
400
			$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
155
			$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
401
		}
156
		}
Line 402... Line 157...
402
 
157
		
403
		// Post-traitement
158
		// Post-traitement
404
		$observations = $this->traiterObservations($resultats, $total);
159
		$observations = $this->traiterObservations($resultats, $total);
405
		$observations = $this->ajouterImagesAuxObs($observations);
160
		$observations = $this->ajouterImagesAuxObs($observations);
406
		$observations = $this->ajouterAuteursAuxObs($observations);
161
		$observations = $this->ajouterAuteursAuxObs($observations);
407
		$observations = $this->supprimerIdDesObs($observations);
-
 
408
 
162
		$observations = $this->supprimerIdDesObs($observations);
409
		return $observations;
163
		return $observations;
Line 410... Line 164...
410
	}
164
	}
411
 
165
	
Line 486... Line 240...
486
	}
240
	}
Line 487... Line 241...
487
 
241
	
488
	private function ajouterImagesAuxObs($observations) {
242
	private function ajouterImagesAuxObs($observations) {
489
		$images = $this->chargerImages(array_keys($observations['observations']));
243
		$images = $this->chargerImages(array_keys($observations['observations']));
490
		foreach ($observations['observations'] as $id => $infos) {
-
 
491
			if(isset($images[$id])) {
244
		foreach ($observations['observations'] as $id => $infos) {
492
				$infos['images'] = $images[$id];
245
			$infos['images'] = $images[$id];
493
				$observations['observations'][$id] = $infos;
246
			$observations['observations'][$id] = $infos;
494
			}
-
 
495
		}
247
		}
496
		return $observations;
248
		return $observations;
Line 497... Line 249...
497
	}
249
	}
498
 
250
	
Line 536... Line 288...
536
					$this->construireWhereNumTaxon().
288
					$this->construireWhereNumTaxon().
537
					$this->construireWhereNomTaxon().
289
					$this->construireWhereNomTaxon().
538
					$this->construireWhereDate().
290
					$this->construireWhereDate().
539
					$this->construireWhereCommentaire().
291
					$this->construireWhereCommentaire().
540
					$this->construireWhereProjet().
292
					$this->construireWhereProjet().
541
					$this->construireWhereTag().
293
					$this->construireWhereTag();
542
					'ORDER BY nom_ret ASC '.
294
					'ORDER BY nom_ret ASC '.
543
                    "LIMIT {$this->start},{$this->limit} ";
295
                    "LIMIT {$this->start},{$this->limit} ";
544
		//$this->debug[] = $requete;
296
		//$this->debug[] = $requete;
545
		$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
297
		$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
Line 574... Line 326...
574
	private function construireWhereCoordonnees() {
326
	private function construireWhereCoordonnees() {
575
		$sql = '';
327
		$sql = '';
576
		// Récupération des coordonnées depuis l'id station
328
		// Récupération des coordonnées depuis l'id station
577
		extract($this->decomposerParametreStation());
329
		extract($this->decomposerParametreStation());
578
		if (isset($type)) {
330
		if (isset($type)) {
579
			if ($type == self::MARQUEUR_COMMUNE) {
331
			if ($type == 'UTM') {
-
 
332
				$secteur = $this->proteger($secteur);
580
				$lat = $this->proteger($lat);
333
				$x_utm = $this->proteger($x_utm);
581
				$lng = $this->proteger($lng);
334
				$y_utm = $this->proteger($y_utm);
-
 
335
				
582
				$sql = " AND (ROUND(wgs84_latitude,5) = ROUND($lat,5) AND ROUND(wgs84_longitude,5) = ROUND($lng,5)) ";
336
				$sql = " AND (sector = $secteur AND x_utm = $x_utm AND y_utm = $y_utm ) ";
583
			}  else if ($type == self::MARQUEUR_STATION) {
337
			}  else if ($type == 'LngLat') {
584
				$lat = $this->proteger($lat);
338
				$coord_x = $this->proteger($coord_x);
585
				$lng = $this->proteger($lng);
339
				$coord_y = $this->proteger($coord_y);
-
 
340
				
586
				$sql = " AND (coord_x = $lat AND coord_y = $lng) ";
341
				$sql = " AND (coord_x = $coord_x AND coord_y = $coord_y ) ";
587
			}
342
			}
588
		}
343
		}		
589
		return $sql;
344
		return $sql;
590
	}
345
	}
Line 812... Line 567...
812
		}
567
		}
813
		$sql = " $operateur ($sql) ";
568
		$sql = " $operateur ($sql) ";
814
		return $sql;
569
		return $sql;
815
	}
570
	}
Line 816... Line -...
816
 
-
 
817
	private function construireWhereRectangleStation() {
-
 
818
		$sql = '';
-
 
819
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
820
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
821
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
822
 
-
 
823
			$latMin = $sw['lat'];
-
 
824
			$lngMin = $sw['lng'];
-
 
825
 
-
 
826
			$latMax = $ne['lat'];
-
 
827
			$lngMax = $ne['lng'];
-
 
828
 
-
 
829
			// ATTENTION : coord_x correspond bien à la LATITUDE!
-
 
830
			$sql = " AND (coord_x != 0 AND coord_y != 0) ".
-
 
831
				" AND coord_x > $latMin ".
-
 
832
				" AND coord_x < $latMax ".
-
 
833
				" AND coord_y > $lngMin ".
-
 
834
				" AND coord_y < $lngMax ";
-
 
835
		}
-
 
836
		return $sql;
-
 
837
	}
-
 
838
 
-
 
839
	private function construireWhereRectangleStationOR() {
-
 
840
		$sql = '';
-
 
841
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
842
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
843
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
844
 
-
 
845
			$latMin = $sw['lat'];
-
 
846
			$lngMin = $sw['lng'];
-
 
847
 
-
 
848
			$latMax = $ne['lat'];
-
 
849
			$lngMax = $ne['lng'];
-
 
850
 
-
 
851
			// ATTENTION : coord_x correspond bien à la LATITUDE!
-
 
852
			$sql = "( (coord_x != 0 AND coord_y != 0) ".
-
 
853
				" AND coord_x > $latMin ".
-
 
854
				" AND coord_x < $latMax ".
-
 
855
				" AND coord_y > $lngMin ".
-
 
856
				" AND coord_y < $lngMax )";
-
 
857
		}
-
 
858
		return $sql;
-
 
859
	}
-
 
860
 
-
 
861
	private function construireWhereRectangleCommune() {
-
 
862
		$sql = '';
-
 
863
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
864
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
865
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
866
 
-
 
867
			$latMin = $sw['lat'];
-
 
868
			$lngMin = $sw['lng'];
-
 
869
 
-
 
870
			$latMax = $ne['lat'];
-
 
871
			$lngMax = $ne['lng'];
-
 
872
 
-
 
873
			$sql = "AND wgs84_longitude != 0 AND wgs84_latitude != 0 ".
-
 
874
				" AND wgs84_latitude > $latMin ".
-
 
875
				" AND wgs84_latitude < $latMax ".
-
 
876
				" AND wgs84_longitude > $lngMin ".
-
 
877
				" AND wgs84_longitude < $lngMax ";
-
 
878
		}
-
 
879
		return $sql;
-
 
880
	}
-
 
881
 
-
 
882
	private function construireWhereRectangleCommuneOR() {
-
 
883
		$sql = '';
-
 
884
		if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
-
 
885
			$ne = $this->decomposerLatLng($this->parametres['ne']);
-
 
886
			$sw = $this->decomposerLatLng($this->parametres['sw']);
-
 
887
 
-
 
888
			$latMin = $sw['lat'];
-
 
889
			$lngMin = $sw['lng'];
-
 
890
 
-
 
891
			$latMax = $ne['lat'];
-
 
892
			$lngMax = $ne['lng'];
-
 
893
 
-
 
894
			$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
-
 
895
				" AND wgs84_latitude > $latMin ".
-
 
896
				" AND wgs84_latitude < $latMax ".
-
 
897
				" AND wgs84_longitude > $lngMin ".
-
 
898
				" AND wgs84_longitude < $lngMax )";
-
 
899
		}
-
 
900
		return $sql;
-
 
901
	}
-
 
902
 
571
	
903
	private function construireWhereDept() {
572
	private function construireWhereDept() {
904
		$sql = '';
573
		$sql = '';
905
		// Récupération des coordonnées depuis l'id station
574
		// Récupération des coordonnées depuis l'id station
906
		extract($this->parametres);
575
		extract($this->parametres);
907
		if (!$this->etreNull($dept)) {
576
		if (isset($dept) && !$this->etreNull($dept)) {
908
			$dept = $this->traiterValeursMultiples($dept);
577
			$dept = $this->traiterValeursMultiples($dept);
909
			$sql = " AND code IN ($dept) ";
578
			$sql = " AND code IN ($dept) ";
910
		}
579
		}
911
		return $sql;
580
		return $sql;
Line 912... Line 581...
912
	}
581
	}
913
 
582
	
914
	private function construireWhereCommune() {
583
	private function construireWhereCommune() {
915
		$sql = '';
584
		$sql = '';
916
		// Récupération des coordonnées depuis l'id station
585
		// Récupération des coordonnées depuis l'id station
917
		extract($this->parametres);
586
		extract($this->parametres);
918
		if (!$this->etreNull($commune)) {
587
		if (isset($commune) && !$this->etreNull($commune)) {
919
			$commune = $this->proteger($commune);
588
			$commune = $this->proteger($commune);
920
			$sql = " AND location LIKE $commune ";
589
			$sql = " AND location LIKE $commune ";
921
		}
590
		}
Line 922... Line -...
922
		return $sql;
-
 
923
	}
-
 
924
 
-
 
925
	private function construireWhereCommuneSansCoordonnees() {
-
 
926
		$sql = '';
-
 
927
		// Récupération des coordonnées depuis l'id station
-
 
928
		extract($this->parametres);
-
 
929
		if (!$this->etreNull($commune)) {
-
 
930
			$commune = $this->proteger($commune);
-
 
931
			$sql = " AND location LIKE $commune ";
-
 
932
			$sql .= " AND ((coord_x = '000null' OR coord_x = '') ".
-
 
933
								" AND (coord_y = '000null' OR coord_y = '')) ";
-
 
Line 934... Line 591...
934
		}
591
		return $sql;
935
		return $sql;
592
	}
936
	}
593
	
937
 
594
	
938
	private function construireWhereUtilisateur() {
595
	private function construireWhereUtilisateur() {
939
		$sql = '';
596
		$sql = '';
940
		// Récupération des coordonnées depuis l'id station
597
		// Récupération des coordonnées depuis l'id station
941
		extract($this->parametres);
598
		extract($this->parametres);
942
		if (!$this->etreNull($utilisateur)) {
599
		if (isset($utilisateur) && !$this->etreNull($utilisateur)) {
943
			$utilisateur = $this->proteger($utilisateur);
600
			$utilisateur = $this->proteger($utilisateur);
Line 944... Line 601...
944
			$sql = " AND identifiant = $utilisateur ";
601
			$sql = " AND identifiant = $utilisateur ";
945
		}
602
		}
946
		return $sql;
603
		return $sql;
947
	}
604
	}
948
 
605
	
949
	private function construireWhereNumTaxon() {
606
	private function construireWhereNumTaxon() {
950
		$sql = '';
607
		$sql = '';
951
		// Récupération des coordonnées depuis l'id station
608
		// Récupération des coordonnées depuis l'id station
952
		extract($this->parametres);
609
		extract($this->parametres);
953
		if (!$this->etreNull($num_taxon)) {
610
		if (isset($num_taxon) && !$this->etreNull($num_taxon)) {
Line 954... Line 611...
954
			$num_taxon = $this->proteger($num_taxon);
611
			$num_taxon = $this->proteger($num_taxon);
955
			$sql = " AND num_taxon = $num_taxon ";
612
			$sql = " AND num_taxon = $num_taxon ";
956
		}
613
		}
957
		return $sql;
614
		return $sql;
958
	}
615
	}
959
 
616
	
960
	private function construireWhereProjet() {
617
	private function construireWhereProjet() {
961
		$sql = '';
618
		$sql = '';
962
		// Récupération des coordonnées depuis l'id station
619
		// Récupération des coordonnées depuis l'id station
963
		extract($this->parametres);
620
		extract($this->parametres);
Line 971... Line 628...
971
	/**
628
	/**
972
	 * Traitement de $projet pour construction du filtre dans la requête
629
	 * Traitement de $projet pour construction du filtre dans la requête
973
	 */
630
	 */
974
	private function getSqlWhereProjet($projet) {
631
	private function getSqlWhereProjet($projet) {
975
		$sql = null;
632
		$sql = null;
976
		if (! $this->etreNull($projet)) {
633
		if (isset($projet) && !$this->etreNull($projet)) {
977
			$mot_cle_encode = $this->bdd->quote($this->encoderMotCle($projet));
634
			$mot_cle_encode = $this->bdd->quote($this->encoderMotCle($projet));
Line 978... Line 635...
978
 
635
			
979
			// Construction de la requête
636
			// Construction de la requête
980
			$requete = 	'SELECT * '.
637
			$requete = 	'SELECT * '.
Line 1002... Line 659...
1002
 
659
	
1003
	private function construireWhereTag() {
660
	private function construireWhereTag() {
1004
		$sql = '';
661
		$sql = '';
1005
		// Récupération des coordonnées depuis l'id station
662
		// Récupération des coordonnées depuis l'id station
1006
		extract($this->parametres);
663
		extract($this->parametres);
1007
		$tag_sql = $this->getSqlWhereObsAvecImagesTaguees($tag);
664
		$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
1008
		if (!$this->etreNull($tag_sql)) {
665
		if (!$this->etreNull($tag_sql)) {
1009
			$sql = " AND ($tag_sql) ";
666
			$sql = " AND ($tag_sql) ";
1010
		}
667
		}
1011
		return $sql;
668
		return $sql;
Line 1014... Line 671...
1014
	/**
671
	/**
1015
	 * Traitement de $tag pour construction du filtre dans la requête
672
	 * Traitement de $tag pour construction du filtre dans la requête
1016
	 */
673
	 */
1017
	private function getSqlWhereObsAvecImagesTaguees($tag) {
674
	private function getSqlWhereObsAvecImagesTaguees($tag) {
1018
		$sql = null;
675
		$sql = null;
1019
		if (! $this->etreNull($tag)) {
676
		if (isset($tag) && !$this->etreNull($tag)) {
1020
			$tag_sql = $this->getSqlWhereMotsCles($tag);
677
			$tag_sql = $this->getSqlWhereMotsCles($tag);
1021
			// Construction de la requête
678
			// Construction de la requête
1022
			$requete = 	'SELECT DISTINCT coi_ce_observation AS ordre,  coi_ce_utilisateur AS utilisateur '.
679
			$requete = 	'SELECT DISTINCT coi_ce_observation AS ordre,  coi_ce_utilisateur AS utilisateur '.
1023
						'FROM cel_images '.
680
						'FROM cel_images '.
1024
						'	LEFT JOIN cel_obs_images '.
681
						'	LEFT JOIN cel_obs_images '.
Line 1153... Line 810...
1153
		}
810
		}
1154
		$this->debug[] = $mots_cles;
811
		$this->debug[] = $mots_cles;
1155
		return $mots_cles;
812
		return $mots_cles;
1156
	}
813
	}
Line 1157... Line -...
1157
 
-
 
1158
	private function decomposerLatLng($coord) {
-
 
1159
		$lat_lng = array();
-
 
1160
		if (isset($coord)) {
-
 
1161
			list($lat, $lng) = explode('|', $coord);
-
 
1162
			$lat_lng = array('lat' => $lat, 'lng' => $lng);
-
 
1163
		}
-
 
1164
		return $lat_lng;
-
 
1165
	}
-
 
1166
 
814
	
1167
	private function decomposerParametreStation() {
815
	private function decomposerParametreStation() {
1168
		$station_infos = array();
816
		$station_infos = array();
1169
		if (isset($this->parametres['station'])) {
817
		if (isset($this->parametres['station'])) {
1170
			$station = $this->parametres['station'];
818
			$station = $this->parametres['station'];
1171
			$this->debug[] = $station;
819
			$this->debug[] = $station;
1172
			@list($type, $coord) = explode(':', $station);
-
 
Line -... Line 820...
-
 
820
			list($type, $coord) = explode(':', $station);
-
 
821
			
1173
			@list($lat, $lng) = explode('|', $coord);
822
			if ($type == 'UTM') {
-
 
823
				list($x_utm, $y_utm, $secteur) = explode('-', $coord);
-
 
824
				$station_infos = array('x_utm' => $x_utm, 'y_utm' => $y_utm, 'secteur' => $secteur);
-
 
825
			} else if ($type == 'LngLat') {
-
 
826
				list($coord_y, $coord_x) = explode('-', $coord);
-
 
827
				$station_infos = array('coord_y' => $coord_y, 'coord_x' => $coord_x);
1174
 
828
			}
1175
			$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
829
			$station_infos['type'] = $type;
1176
		}
830
		}
Line 1177... Line 831...
1177
		return $station_infos;
831
		return $station_infos;
1178
	}
832
	}
1179
 
833
	
1180
	private function decomposerParametreDate() {
834
	private function decomposerParametreDate() {
1181
		$date_infos = array();
835
		$date_infos = array(null,null);
1182
		if (isset($this->parametres['date'])) {
836
		if (isset($this->parametres['date'])) {
1183
			$date = $this->parametres['date'];
837
			$date = $this->parametres['date'];
Line 1196... Line 850...
1196
		}
850
		}
1197
		return $date_infos;
851
		return $date_infos;
1198
	}
852
	}
Line 1199... Line 853...
1199
 
853
	
1200
	private function decomposerParametreTaxon() {
854
	private function decomposerParametreTaxon() {
1201
		$nom_infos = array();
855
		$nom_infos = array(null, null);
1202
		if (isset($this->parametres['taxon'])) {
856
		if (isset($this->parametres['taxon'])) {
1203
			$taxon = $this->parametres['taxon'];
857
			$taxon = $this->parametres['taxon'];
1204
			if (strpos($taxon, ':')) {
858
			if (strpos($taxon, ':')) {
1205
				$nom_infos = explode(':', $taxon);
859
				$nom_infos = explode(':', $taxon);
Line 1209... Line 863...
1209
		}
863
		}
1210
		return $nom_infos;
864
		return $nom_infos;
1211
	}
865
	}
Line 1212... Line 866...
1212
 
866
	
1213
	private function decomposerParametreCommentaire() {
867
	private function decomposerParametreCommentaire() {
1214
		$commentaire_infos = array();
868
		$commentaire_infos = array(null, null);
1215
		if (isset($this->parametres['commentaire'])) {
869
		if (isset($this->parametres['commentaire'])) {
1216
			$commentaire = $this->parametres['commentaire'];
870
			$commentaire = $this->parametres['commentaire'];
1217
			if (strpos($commentaire, ':')) {
871
			if (strpos($commentaire, ':')) {
1218
				$commentaire_infos = explode(':', $commentaire);
872
				$commentaire_infos = explode(':', $commentaire);