1121 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Service fournissant une carte dynamique des obsertions publiques du CEL.
|
|
|
5 |
* Encodage en entrée : utf8
|
|
|
6 |
* Encodage en sortie : utf8
|
|
|
7 |
*
|
|
|
8 |
* Cas d'utilisation :
|
|
|
9 |
* /CelWidgetMap/Carte/Utilisateur : carte des observations publiques d'un utilisateur.
|
|
|
10 |
* /CelWidgetMap/Carte/Utilisateur/Projet : carte des observations publiques d'un utilisateur pour un projet.
|
|
|
11 |
* /CelWidgetMap/Carte/Utilisateur/Projet/dept : carte des observations publiques d'un utilisateur pour un projet sur un département.
|
|
|
12 |
* /CelWidgetMap/Carte/Utilisateur/Projet/dept/num_taxon : carte des observations publiques d'un utilisateur pour un projet sur un département pour un taxon.
|
|
|
13 |
*
|
|
|
14 |
* Carte = Type de carte. Valeurs possible : defaut,
|
|
|
15 |
* Utilisateur = identifiant (= courriel) de l'utilisateur ou * pour tous les utilisateurs.
|
|
|
16 |
* Projet = mot-clé du projet
|
|
|
17 |
*
|
|
|
18 |
* @author Jean-Pascal MILCENT <jpm@clapas.org>
|
|
|
19 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
20 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
21 |
* @version $Id$
|
|
|
22 |
* @copyright © 2010, Jean-Pascal MILCENT
|
|
|
23 |
*/
|
|
|
24 |
// TODO : supprimer le TRIM quand les obs seront reliées correctements aux localisations (sur le code INSEE par exemple)
|
|
|
25 |
class CelWidgetMapPoint extends Cel {
|
|
|
26 |
const MARQUEUR_GROUPE = 'GROUPE';
|
|
|
27 |
const MARQUEUR_COMMUNE = 'COMMUNE';
|
|
|
28 |
const MARQUEUR_STATION = 'STATION';
|
|
|
29 |
/**
|
|
|
30 |
* Méthode appelée avec une requête de type GET.
|
|
|
31 |
*/
|
|
|
32 |
public function getElement($ressources) {
|
|
|
33 |
$retour = null;
|
1131 |
aurelien |
34 |
if($this->parametres == null) {
|
|
|
35 |
$this->parametres = array();
|
|
|
36 |
}
|
1121 |
aurelien |
37 |
extract($this->parametres);
|
|
|
38 |
//Chronometre::chrono("Avant groupage");
|
|
|
39 |
|
|
|
40 |
$action = array_shift($ressources);
|
|
|
41 |
if (isset($action)) {
|
|
|
42 |
$methode = $this->traiterNomMethodeGet($action);
|
|
|
43 |
if (method_exists($this, $methode)) {
|
|
|
44 |
$retour = $this->$methode($ressources);
|
|
|
45 |
} else {
|
|
|
46 |
$this->messages[] = "Ce type de ressource '$methode' n'est pas disponible.";
|
|
|
47 |
}
|
|
|
48 |
} else {
|
|
|
49 |
$this->messages[] = "Vous devez indiquer le type de ressource.";
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
//Chronometre::chrono("Apres traitement");
|
|
|
53 |
//echo Chronometre::afficherChrono();
|
|
|
54 |
if (is_null($retour)) {
|
|
|
55 |
$info = 'Un problème est survenu : '.print_r($this->messages, true);
|
|
|
56 |
$this->envoyer($info);
|
|
|
57 |
} else if (isset($retour['type']) && $retour['type'] == 'jsonVar') {
|
|
|
58 |
$this->envoyerJsonVar($retour['variable_js'], $retour['donnees']);
|
|
|
59 |
} else if (isset($retour['type']) && $retour['type'] == 'jsonP') {
|
|
|
60 |
$this->envoyerJsonp($retour['donnees']);
|
|
|
61 |
} else if (isset($retour['type']) && $retour['type'] == 'png') {
|
|
|
62 |
header("Content-type: image/png");
|
|
|
63 |
imagepng($retour['img']);
|
|
|
64 |
imagedestroy($retour['img']);
|
|
|
65 |
} else {
|
|
|
66 |
$this->envoyerJson($retour);
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Les icones des groupes de stations
|
|
|
72 |
*/
|
|
|
73 |
public function getIconeGroupe($params) {
|
|
|
74 |
extract($this->parametres);
|
|
|
75 |
|
|
|
76 |
$chemin_marqueur = sprintf($this->config['settings']['cheminCelMarkerObsTpl'], $type);
|
|
|
77 |
$img = imagecreatefrompng($chemin_marqueur);
|
|
|
78 |
|
|
|
79 |
$noir = imagecolorallocate($img, 0, 0, 0);
|
|
|
80 |
$texte = (String) $nbre;
|
|
|
81 |
$x = (imagesx($img) - 6.0 * strlen($texte)) / 2;
|
|
|
82 |
$y = (imagesy($img) - 16) / 2;
|
|
|
83 |
|
|
|
84 |
imagestring($img, 3, $x, $y, $texte, $noir);
|
|
|
85 |
|
|
|
86 |
imagealphablending($img, false);
|
|
|
87 |
imagesavealpha($img, true);
|
|
|
88 |
|
|
|
89 |
return array('type' => 'png', 'img' => $img);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
* Les stations de la carte par défaut
|
|
|
94 |
*/
|
|
|
95 |
public function getStations($params) {
|
|
|
96 |
$stations = null;
|
|
|
97 |
$requete = 'SELECT wgs84_latitude AS lat, wgs84_longitude AS lng, location AS nom '.
|
|
|
98 |
'FROM cel_inventory AS i '.
|
|
|
99 |
' LEFT JOIN locations AS l '.
|
|
|
100 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
101 |
"WHERE transmission = '1' ".
|
|
|
102 |
" AND (( ".
|
|
|
103 |
" (coord_x = '' OR coord_x IS NULL OR coord_x = '000null') ".
|
|
|
104 |
" AND (coord_y = '' OR coord_y IS NULL OR coord_y = '000null') ".
|
|
|
105 |
" ) OR mots_cles_texte LIKE '%sensible%') ".
|
|
|
106 |
$this->construireWhereRectangleCommune().
|
|
|
107 |
$this->construireWhereDept().
|
|
|
108 |
$this->construireWhereCommune().
|
|
|
109 |
$this->construireWhereUtilisateur().
|
|
|
110 |
$this->construireWhereNumTaxon().
|
|
|
111 |
$this->construireWhereNomTaxon().
|
|
|
112 |
$this->construireWhereDate().
|
|
|
113 |
$this->construireWhereCommentaire().
|
|
|
114 |
$this->construireWhereProjet().
|
|
|
115 |
$this->construireWhereTag();
|
|
|
116 |
|
|
|
117 |
$resultats_communes = $this->requeter($requete);
|
|
|
118 |
|
|
|
119 |
$requete = 'SELECT coord_x AS lat, coord_y AS lng, location AS nom '.
|
|
|
120 |
'FROM cel_inventory AS i '.
|
|
|
121 |
' LEFT JOIN locations AS l '.
|
|
|
122 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
123 |
"WHERE transmission = '1' ".
|
|
|
124 |
" AND coord_x != '' AND coord_x IS NOT NULL AND coord_x != '000null' ".
|
|
|
125 |
" AND coord_y != '' AND coord_y IS NOT NULL AND coord_y != '000null' ".
|
|
|
126 |
" AND (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE '%sensible%') ".
|
|
|
127 |
$this->construireWhereRectangleStation().
|
|
|
128 |
$this->construireWhereDept().
|
|
|
129 |
$this->construireWhereCommune().
|
|
|
130 |
$this->construireWhereUtilisateur().
|
|
|
131 |
$this->construireWhereNumTaxon().
|
|
|
132 |
$this->construireWhereNomTaxon().
|
|
|
133 |
$this->construireWhereDate().
|
|
|
134 |
$this->construireWhereCommentaire().
|
|
|
135 |
$this->construireWhereProjet().
|
|
|
136 |
$this->construireWhereTag();
|
|
|
137 |
|
|
|
138 |
$resultats_stations = $this->requeter($requete);
|
|
|
139 |
$stations = $this->traiterStations($resultats_communes, $resultats_stations);
|
|
|
140 |
|
|
|
141 |
return $stations;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
public function getTout($params) {
|
|
|
145 |
|
1138 |
aurelien |
146 |
$emplacements = null;
|
|
|
147 |
$concatenation_id = 'CONCAT(coord_x,coord_y, wgs84_latitude,wgs84_longitude) ';
|
1122 |
aurelien |
148 |
|
|
|
149 |
$requete = 'SELECT DISTINCT *, location AS nom, '.
|
1138 |
aurelien |
150 |
"mots_cles_texte, ".
|
1121 |
aurelien |
151 |
"coord_x, ".
|
1138 |
aurelien |
152 |
"wgs84_latitude, ".
|
1121 |
aurelien |
153 |
"coord_y, ".
|
1138 |
aurelien |
154 |
"wgs84_longitude, ".
|
|
|
155 |
$concatenation_id." as id_coord ".
|
1121 |
aurelien |
156 |
'FROM cel_inventory AS i '.
|
|
|
157 |
' LEFT JOIN locations AS l '.
|
|
|
158 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
159 |
"WHERE transmission = '1' ".
|
|
|
160 |
" AND (".
|
1138 |
aurelien |
161 |
$this->construireWhereRectangleStationOR()." OR ".
|
|
|
162 |
$this->construireWhereRectangleCommuneOR().") ".
|
1121 |
aurelien |
163 |
$this->construireWhereDept().
|
|
|
164 |
$this->construireWhereCommune().
|
|
|
165 |
$this->construireWhereUtilisateur().
|
|
|
166 |
$this->construireWhereNumTaxon().
|
|
|
167 |
$this->construireWhereNomTaxon().
|
|
|
168 |
$this->construireWhereDate().
|
|
|
169 |
$this->construireWhereCommentaire().
|
|
|
170 |
$this->construireWhereProjet().
|
1138 |
aurelien |
171 |
$this->construireWhereTag().' GROUP BY id_coord';
|
1121 |
aurelien |
172 |
$resultats_emplacements = $this->executerRequete($requete);
|
|
|
173 |
$emplacements = $this->traiterEmplacements($resultats_emplacements, $this->compterObservations($params));
|
|
|
174 |
return $emplacements;
|
|
|
175 |
}
|
1122 |
aurelien |
176 |
|
|
|
177 |
private function afficherRequeteFormatee($requete) {
|
|
|
178 |
$requete = str_replace(')',')<br />',$requete);
|
|
|
179 |
$requete = str_replace('(',' <br /> (',$requete);
|
|
|
180 |
echo '<pre>'.$requete.'</pre>';
|
|
|
181 |
exit;
|
|
|
182 |
}
|
1121 |
aurelien |
183 |
|
|
|
184 |
private $nb_obs = 0;
|
|
|
185 |
|
|
|
186 |
private function compterObservations($params) {
|
|
|
187 |
$requete = 'SELECT COUNT(*) AS nb '.
|
|
|
188 |
'FROM cel_inventory AS i '.
|
|
|
189 |
' LEFT JOIN locations AS l '.
|
|
|
190 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
191 |
"WHERE transmission = '1' ".
|
1138 |
aurelien |
192 |
" AND ".
|
|
|
193 |
"(".$this->construireWhereRectangleStationOR()." OR ".
|
|
|
194 |
$this->construireWhereRectangleCommuneOR().
|
1121 |
aurelien |
195 |
$this->construireWhereDept().
|
|
|
196 |
$this->construireWhereCommune().
|
|
|
197 |
$this->construireWhereUtilisateur().
|
|
|
198 |
$this->construireWhereNumTaxon().
|
|
|
199 |
$this->construireWhereNomTaxon().
|
|
|
200 |
$this->construireWhereDate().
|
|
|
201 |
$this->construireWhereCommentaire().
|
|
|
202 |
$this->construireWhereProjet().
|
|
|
203 |
$this->construireWhereTag();
|
|
|
204 |
|
|
|
205 |
$resultats_nb_obs = $this->executerRequete($requete);
|
|
|
206 |
return $resultats_nb_obs[0]['nb'];
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
private function traiterEmplacements(&$emplacements, $nb_total_observation) {
|
|
|
210 |
$zoom = (int) array_key_exists('zoom', $this->parametres) ? $this->parametres['zoom'] : 11;
|
|
|
211 |
$distance = (int) array_key_exists('distance', $this->parametres) ? $this->parametres['distance'] : 20;
|
|
|
212 |
|
|
|
213 |
$marqueurs = array(
|
|
|
214 |
'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
|
|
|
215 |
'points' => null
|
|
|
216 |
);
|
|
|
217 |
|
1131 |
aurelien |
218 |
if (isset($this->parametres['ne']) && $this->parametres['sw'] && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
1121 |
aurelien |
219 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
220 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
|
|
221 |
$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree($emplacements, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
|
|
|
222 |
|
|
|
223 |
// laisser la classe cartoGroupage compter les élements simplifie le comptage
|
|
|
224 |
// et permet de ne pas reparser le tableau pour compter les différents éléments
|
|
|
225 |
$nb_elements = CartoGroupage::getNbElements();
|
1138 |
aurelien |
226 |
// les bornes servent à centrer la carte dans le cas ou l'on demande des paramètres précis
|
1122 |
aurelien |
227 |
$marqueurs['stats']['coordmax'] = CartoGroupage::getBornes();
|
1121 |
aurelien |
228 |
$marqueurs['stats']['stations'] = $nb_elements['stations'];
|
|
|
229 |
$marqueurs['stats']['communes'] = $nb_elements['communes'];
|
|
|
230 |
$marqueurs['stats']['observations'] = (int)$nb_total_observation;
|
|
|
231 |
} else {
|
|
|
232 |
$marqueurs['points'] = $emplacements;
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
return $marqueurs;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
private function traiterStations($communes, $stations) {
|
|
|
239 |
$zoom = (int) array_key_exists('zoom', $this->parametres) ? $this->parametres['zoom'] : 11;
|
|
|
240 |
$distance = (int) array_key_exists('distance', $this->parametres) ? $this->parametres['distance'] : 20;
|
|
|
241 |
|
|
|
242 |
$marqueurs = array(
|
|
|
243 |
'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
|
|
|
244 |
'points' => null
|
|
|
245 |
);
|
|
|
246 |
$marqueurs['stats']['observations'] = $this->traiterNbreObs($communes) + $this->traiterNbreObs($stations);
|
|
|
247 |
|
|
|
248 |
$points = array();
|
|
|
249 |
if ($communes !== false) {
|
|
|
250 |
foreach ($communes as $commune) {
|
|
|
251 |
if (is_numeric($commune['lat']) && is_numeric($commune['lng'])) {
|
|
|
252 |
extract($commune);
|
|
|
253 |
$id = self::MARQUEUR_COMMUNE.':'.$lat.'|'.$lng;
|
|
|
254 |
$lata = round($lat, 5);
|
|
|
255 |
$lnga = round($lng, 5);
|
|
|
256 |
|
|
|
257 |
if (!isset($points[$id])) {
|
|
|
258 |
$points[$id]['id'] = $id;
|
|
|
259 |
$points[$id]['nom'] = $nom;
|
|
|
260 |
$points[$id]['lat'] = $lata;
|
|
|
261 |
$points[$id]['lng'] = $lnga;
|
|
|
262 |
$points[$id]['nbre'] = 1;
|
|
|
263 |
$marqueurs['stats']['communes']++;
|
|
|
264 |
} else {
|
|
|
265 |
$points[$id]['nbre']++;
|
|
|
266 |
}
|
|
|
267 |
}
|
|
|
268 |
}
|
|
|
269 |
}
|
|
|
270 |
if ($stations !== false) {
|
|
|
271 |
foreach ($stations as $station) {
|
|
|
272 |
if (is_numeric($station['lat']) && is_numeric($station['lng'])) {
|
|
|
273 |
extract($station);
|
|
|
274 |
$id = self::MARQUEUR_STATION.':'.$lat.'|'.$lng;
|
|
|
275 |
//$this->definirLatLngMaxMin($marqueurs, $lat, $lng);
|
|
|
276 |
$lata = round($lat, 5);
|
|
|
277 |
$lnga = round($lng, 5);
|
|
|
278 |
$nom = $this->etreNull($nom) ? $lata.','.$lnga : $nom;
|
|
|
279 |
|
|
|
280 |
if (!isset($points[$id])) {
|
|
|
281 |
$points[$id]['id'] = $id;
|
|
|
282 |
$points[$id]['nom'] = $nom;
|
|
|
283 |
$points[$id]['lat'] = $lata;
|
|
|
284 |
$points[$id]['lng'] = $lnga;
|
|
|
285 |
$points[$id]['nbre'] = 1;
|
|
|
286 |
$marqueurs['stats']['stations']++;
|
|
|
287 |
} else {
|
|
|
288 |
$points[$id]['nbre']++;
|
|
|
289 |
}
|
|
|
290 |
}
|
|
|
291 |
}
|
|
|
292 |
}
|
|
|
293 |
|
1131 |
aurelien |
294 |
if (isset($this->parametres['ne']) && $this->parametres['sw'] && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
1121 |
aurelien |
295 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
296 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
|
|
297 |
$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree(&$points, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
|
|
|
298 |
} else {
|
|
|
299 |
$marqueurs['points'] = $points;
|
|
|
300 |
}
|
|
|
301 |
//$marqueurs['stats']['latDiff'] = abs($marqueurs['stats']['latMin'] - $marqueurs['stats']['latMax']);
|
|
|
302 |
//$marqueurs['stats']['lngDiff'] = abs($marqueurs['stats']['lngMin'] - $marqueurs['stats']['lngMax']);
|
|
|
303 |
|
|
|
304 |
return $marqueurs;
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
private function definirLatLngMaxMin(&$marqueurs, $lat, $lng) {
|
|
|
308 |
if ($lat != null && $lng != null) {
|
|
|
309 |
$marqueurs['stats']['latMin'] = $marqueurs['stats']['latMin'] > $lat ? $lat : $marqueurs['stats']['latMin'];
|
|
|
310 |
$marqueurs['stats']['lngMin'] = $marqueurs['stats']['lngMin'] > $lng ? $lng : $marqueurs['stats']['lngMin'];
|
|
|
311 |
$marqueurs['stats']['latMax'] = $marqueurs['stats']['latMax'] < $lat ? $lat : $marqueurs['stats']['latMax'];
|
|
|
312 |
$marqueurs['stats']['lngMax'] = $marqueurs['stats']['lngMax'] < $lng ? $lng : $marqueurs['stats']['lngMax'];
|
|
|
313 |
}
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
private function traiterNbreObs($resultats) {
|
|
|
317 |
$obs_nbre = 0;
|
|
|
318 |
if ($resultats !== false) {
|
|
|
319 |
$obs_nbre = count($resultats);
|
|
|
320 |
}
|
|
|
321 |
return $obs_nbre;
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
private function verifierLatLng($lat, $lng) {
|
|
|
325 |
$ok_lat = $this->etreLatitude($lat) ? true : false;
|
|
|
326 |
$ok_lng = $this->etreLongitude($lng) ? true : false;
|
|
|
327 |
$ok = $ok_lat && $ok_lng;
|
|
|
328 |
return $ok;
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
private function etreLatitude($lat) {
|
|
|
332 |
$ok = false;
|
|
|
333 |
//$format = preg_match('/^[-]?[0-9]+(?:[.][0-9]+|)$/', $lat) ? true : false;
|
|
|
334 |
$ok = ($lat >= -90 && $lat <= 90) ? true : false;
|
|
|
335 |
return $ok;
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
private function etreLongitude($lng) {
|
|
|
339 |
$ok = false;
|
|
|
340 |
//$format = preg_match('/^[-]?[0-9]+(?:[.][0-9]+|)$/', $lng) ? true : false;
|
|
|
341 |
$ok = ($lng >= -180 && $lng <= 180) ? true : false;
|
|
|
342 |
return $ok;
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
private function etreObsSensible($tags) {
|
|
|
346 |
$sensible = true;
|
|
|
347 |
if (stristr($tags, 'sensible') === FALSE) {
|
|
|
348 |
$sensible = false;
|
|
|
349 |
}
|
|
|
350 |
return $sensible;
|
|
|
351 |
}
|
|
|
352 |
|
1168 |
aurelien |
353 |
private function communeEstDemandee() {
|
|
|
354 |
$station_infos = $this->decomposerParametreStation();
|
|
|
355 |
$commune_demandee = true;
|
|
|
356 |
if($station_infos['type'] == self::MARQUEUR_STATION) {
|
|
|
357 |
$commune_demandee = false;
|
|
|
358 |
}
|
|
|
359 |
return $commune_demandee;
|
|
|
360 |
}
|
|
|
361 |
|
1121 |
aurelien |
362 |
/**
|
|
|
363 |
* Données pour l'affichage des obs d'une station
|
|
|
364 |
*/
|
|
|
365 |
public function getObservations($params) {
|
|
|
366 |
$resultats = array();
|
|
|
367 |
$total = 0;
|
1131 |
aurelien |
368 |
if (isset($this->parametres['station']) && !$this->etreNull($this->parametres['station'])) {
|
1121 |
aurelien |
369 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS id, identifiant, nom_sel, nom_ret, num_nom_sel, num_nom_ret, num_taxon, famille, '.
|
|
|
370 |
' lieudit, location, date_observation, milieu, commentaire, '.
|
|
|
371 |
' sector, x_utm, y_utm, insee_code, date_transmission '.
|
|
|
372 |
'FROM cel_inventory AS i '.
|
|
|
373 |
' LEFT JOIN locations AS l '.
|
|
|
374 |
" ON (l.name = i.location AND l.code = i.id_location) ".
|
|
|
375 |
"WHERE transmission = '1' ".
|
1168 |
aurelien |
376 |
(($this->communeEstDemandee()) ? $this->construireWhereCommuneSansCoordonneesAvecSensibles() : $this->construireWhereCoordonneesSansSensibles()).
|
1138 |
aurelien |
377 |
$this->construireWhereDept().
|
1121 |
aurelien |
378 |
$this->construireWhereUtilisateur().
|
|
|
379 |
$this->construireWhereNumTaxon().
|
|
|
380 |
$this->construireWhereNomTaxon().
|
|
|
381 |
$this->construireWhereDate().
|
|
|
382 |
$this->construireWhereCommentaire().
|
|
|
383 |
$this->construireWhereProjet().
|
|
|
384 |
$this->construireWhereTag().
|
|
|
385 |
'ORDER BY nom_sel ASC '.
|
|
|
386 |
"LIMIT {$this->start},{$this->limit} ";
|
1168 |
aurelien |
387 |
|
1121 |
aurelien |
388 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
|
|
389 |
$requete = 'SELECT FOUND_ROWS()';
|
|
|
390 |
$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
|
|
|
391 |
}
|
|
|
392 |
|
|
|
393 |
// Post-traitement
|
|
|
394 |
$observations = $this->traiterObservations($resultats, $total);
|
|
|
395 |
$observations = $this->ajouterImagesAuxObs($observations);
|
|
|
396 |
$observations = $this->ajouterAuteursAuxObs($observations);
|
|
|
397 |
$observations = $this->supprimerIdDesObs($observations);
|
|
|
398 |
|
|
|
399 |
return $observations;
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
private function traiterObservations($donnees, $total) {
|
|
|
403 |
$observations = array('commune' => '', 'observations' => array(), 'observateurs' => array());
|
|
|
404 |
$observations['total'] = (isset($total)) ? $total : 0;
|
|
|
405 |
if (is_array($donnees) && count($donnees) > 0) {
|
|
|
406 |
foreach ($donnees as $donnee) {
|
|
|
407 |
$observation = array();
|
|
|
408 |
$observation['idObs'] = $donnee->id;
|
|
|
409 |
$observation['nn'] = $this->etreNull($donnee->num_nom_sel) ? null : $donnee->num_nom_sel;
|
|
|
410 |
$observation['nomSci'] = $this->nettoyerTexte($donnee->nom_sel);
|
|
|
411 |
$observation['date'] = $this->formaterDate($donnee->date_observation, '%d/%m/%Y');
|
|
|
412 |
$observation['datePubli'] = $this->formaterDate($donnee->date_transmission);
|
|
|
413 |
$observation['lieu'] = $this->traiterLieu($donnee);
|
|
|
414 |
$observation['observateur'] = $donnee->identifiant;
|
|
|
415 |
$observation['urlEflore'] = $this->getUrlEflore($donnee->num_nom_sel);
|
|
|
416 |
|
|
|
417 |
if (isset($donnee->location)) {
|
|
|
418 |
$observations['commune'] = $this->nettoyerTexte($donnee->location);
|
|
|
419 |
}
|
|
|
420 |
$observations['observations'][$donnee->id] = $observation;
|
|
|
421 |
|
|
|
422 |
if (! array_key_exists($donnee->identifiant, $observations['observateurs'])) {
|
|
|
423 |
$observations['observateurs'][$donnee->identifiant] = $donnee->identifiant;
|
|
|
424 |
}
|
|
|
425 |
}
|
|
|
426 |
}
|
|
|
427 |
return $observations;
|
|
|
428 |
}
|
|
|
429 |
|
|
|
430 |
private function getUrlEflore($nn) {
|
|
|
431 |
$urlEflore = null;
|
|
|
432 |
if (! $this->etreNull($nn)) {
|
|
|
433 |
$urlEflore = sprintf($this->config['settings']['efloreUrlTpl'], $nn, 'illustration');
|
|
|
434 |
}
|
|
|
435 |
return $urlEflore;
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
private function traiterLieu($donnee) {
|
|
|
439 |
$lieu = array();
|
|
|
440 |
if (!$this->etreNull($donnee->lieudit)) {
|
|
|
441 |
$lieu[] = $donnee->lieudit;
|
|
|
442 |
}
|
|
|
443 |
if (!$this->etreNull($donnee->milieu)) {
|
|
|
444 |
$lieu[] = $donnee->milieu;
|
|
|
445 |
}
|
|
|
446 |
return implode(', ', $lieu);
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
private function chargerImages(Array $obs_ids) {
|
|
|
450 |
// Récupération des données au format Json
|
|
|
451 |
$service = 'CelImage/liste-ids?obsId='.implode(',', $obs_ids);
|
|
|
452 |
$url = sprintf($this->config['settings']['baseURLServicesCelTpl'], $service);
|
|
|
453 |
$json = $this->getRestClient()->consulter($url);
|
|
|
454 |
$donnees = json_decode($json);
|
|
|
455 |
|
|
|
456 |
// Post-traitement des données
|
|
|
457 |
$images = $this->traiterImages($donnees);
|
|
|
458 |
|
|
|
459 |
return $images;
|
|
|
460 |
}
|
|
|
461 |
|
|
|
462 |
private function traiterImages($donnees) {
|
|
|
463 |
$images = array();
|
|
|
464 |
if (count($donnees) > 0) {
|
|
|
465 |
foreach ($donnees as $id_obs => $id_images) {
|
|
|
466 |
foreach ($id_images as $id_img) {
|
|
|
467 |
$urls['idImg'] = $id_img;
|
|
|
468 |
$urls['guid'] = sprintf($this->config['settings']['guidImgTpl'], $id_img);
|
|
|
469 |
$urls['miniature'] = $this->getUrlImage($id_img, 'CXS');
|
|
|
470 |
$urls['normale'] = $this->getUrlImage($id_img, 'XL');
|
|
|
471 |
$images[$id_obs][] = $urls;
|
|
|
472 |
}
|
|
|
473 |
}
|
|
|
474 |
}
|
|
|
475 |
return $images;
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
private function ajouterImagesAuxObs($observations) {
|
|
|
479 |
$images = $this->chargerImages(array_keys($observations['observations']));
|
|
|
480 |
foreach ($observations['observations'] as $id => $infos) {
|
1122 |
aurelien |
481 |
if(isset($images[$id])) {
|
|
|
482 |
$infos['images'] = $images[$id];
|
|
|
483 |
$observations['observations'][$id] = $infos;
|
|
|
484 |
}
|
1121 |
aurelien |
485 |
}
|
|
|
486 |
return $observations;
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
private function ajouterAuteursAuxObs($observations) {
|
|
|
490 |
$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
|
|
|
491 |
unset($observations['observateurs']);
|
|
|
492 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
493 |
$courriel = $infos['observateur'];
|
|
|
494 |
$infos['observateur'] = $observateurs[$courriel]['intitule'];
|
|
|
495 |
$infos['observateurId'] = $observateurs[$courriel]['id'];
|
|
|
496 |
$observations['observations'][$id] = $infos;
|
|
|
497 |
}
|
|
|
498 |
return $observations;
|
|
|
499 |
}
|
|
|
500 |
|
|
|
501 |
private function supprimerIdDesObs($observations) {
|
|
|
502 |
// Le tableau de sortie ne doit pas avoir les id des obs en clé car sinon Jquery Template ne fonctionne pas
|
|
|
503 |
$observationSansId = $observations;
|
|
|
504 |
unset($observationSansId['observations']);
|
|
|
505 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
506 |
$observationSansId['observations'][] = $infos;
|
|
|
507 |
}
|
|
|
508 |
return $observationSansId;
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
/**
|
|
|
512 |
* Liste des taxons présents sur la carte
|
|
|
513 |
*/
|
|
|
514 |
public function getTaxons($params) {
|
|
|
515 |
$json = null;
|
|
|
516 |
|
|
|
517 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, num_nom_ret, num_taxon, famille '.
|
|
|
518 |
'FROM cel_inventory AS i '.
|
|
|
519 |
' LEFT JOIN locations AS l '.
|
|
|
520 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
521 |
"WHERE transmission = '1' ".
|
|
|
522 |
" AND nom_ret != '' ".
|
|
|
523 |
$this->construireWhereDept().
|
|
|
524 |
$this->construireWhereCommune().
|
|
|
525 |
$this->construireWhereUtilisateur().
|
|
|
526 |
$this->construireWhereNumTaxon().
|
|
|
527 |
$this->construireWhereNomTaxon().
|
|
|
528 |
$this->construireWhereDate().
|
|
|
529 |
$this->construireWhereCommentaire().
|
|
|
530 |
$this->construireWhereProjet().
|
|
|
531 |
$this->construireWhereTag().
|
|
|
532 |
'ORDER BY nom_ret ASC '.
|
|
|
533 |
"LIMIT {$this->start},{$this->limit} ";
|
|
|
534 |
//$this->debug[] = $requete;
|
|
|
535 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
|
|
536 |
|
|
|
537 |
$requete = 'SELECT FOUND_ROWS()';
|
|
|
538 |
$taxons['total'] = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
|
|
|
539 |
|
|
|
540 |
// Post-traitement
|
|
|
541 |
$taxons['taxons'] = $this->traiterTaxons($resultats);
|
|
|
542 |
|
|
|
543 |
return $taxons;
|
|
|
544 |
}
|
|
|
545 |
|
|
|
546 |
private function traiterTaxons($donnees) {
|
|
|
547 |
$taxons = array();
|
|
|
548 |
if (is_array($donnees) && count($donnees) > 0) {
|
|
|
549 |
foreach ($donnees as $donnee) {
|
|
|
550 |
if (!isset($taxons[$donnee->num_taxon]) && ! $this->etreNull($donnee->nom_ret)) {
|
|
|
551 |
$taxon = array();
|
|
|
552 |
$taxon['nn'] = $donnee->num_nom_ret;
|
|
|
553 |
$taxon['nt'] = $donnee->num_taxon;
|
|
|
554 |
$taxon['nom'] = $this->nettoyerTexte($donnee->nom_ret);
|
|
|
555 |
$taxon['famille'] = $this->nettoyerTexte($donnee->famille);
|
|
|
556 |
$taxons[$donnee->num_taxon] = $taxon;
|
|
|
557 |
}
|
|
|
558 |
}
|
|
|
559 |
}
|
|
|
560 |
$taxons = array_values($taxons);
|
|
|
561 |
return $taxons;
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
private function construireWhereCoordonnees() {
|
|
|
565 |
$sql = '';
|
|
|
566 |
// Récupération des coordonnées depuis l'id station
|
|
|
567 |
extract($this->decomposerParametreStation());
|
|
|
568 |
if (isset($type)) {
|
|
|
569 |
if ($type == self::MARQUEUR_COMMUNE) {
|
|
|
570 |
$lat = $this->proteger($lat);
|
|
|
571 |
$lng = $this->proteger($lng);
|
|
|
572 |
$sql = " AND (ROUND(wgs84_latitude,5) = ROUND($lat,5) AND ROUND(wgs84_longitude,5) = ROUND($lng,5)) ";
|
|
|
573 |
} else if ($type == self::MARQUEUR_STATION) {
|
|
|
574 |
$lat = $this->proteger($lat);
|
|
|
575 |
$lng = $this->proteger($lng);
|
|
|
576 |
$sql = " AND (coord_x = $lat AND coord_y = $lng) ";
|
|
|
577 |
}
|
|
|
578 |
}
|
|
|
579 |
return $sql;
|
|
|
580 |
}
|
1122 |
aurelien |
581 |
|
|
|
582 |
private function construireWhereCoordonneesSansSensibles() {
|
|
|
583 |
$sql = '(';
|
|
|
584 |
// Récupération des coordonnées depuis l'id station
|
|
|
585 |
extract($this->decomposerParametreStation());
|
|
|
586 |
if (isset($type)) {
|
|
|
587 |
if ($type == self::MARQUEUR_COMMUNE) {
|
|
|
588 |
$lat = $this->proteger($lat);
|
|
|
589 |
$lng = $this->proteger($lng);
|
|
|
590 |
$sql = " AND (ROUND(wgs84_latitude,5) = ROUND($lat,5) AND ROUND(wgs84_longitude,5) = ROUND($lng,5)) ";
|
|
|
591 |
} else if ($type == self::MARQUEUR_STATION) {
|
|
|
592 |
$lat = $this->proteger($lat);
|
|
|
593 |
$lng = $this->proteger($lng);
|
|
|
594 |
$sql = " AND (coord_x = $lat AND coord_y = $lng) ";
|
|
|
595 |
}
|
|
|
596 |
}
|
1168 |
aurelien |
597 |
$sql .= ' AND (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE "%sensible%" ) ';
|
1122 |
aurelien |
598 |
return $sql;
|
|
|
599 |
}
|
1121 |
aurelien |
600 |
|
|
|
601 |
private function construireWhereCommentaire() {
|
|
|
602 |
$sql = '';
|
|
|
603 |
list($type, $commentaire) = $this->decomposerParametreCommentaire();
|
|
|
604 |
if (!$this->etreNull($commentaire)) {
|
|
|
605 |
$commentaire = $this->proteger('%'.$commentaire.'%');
|
|
|
606 |
switch ($type) {
|
|
|
607 |
case '*' :
|
|
|
608 |
$sql = $this->obtenirConditionPourCommentaires($commentaire);
|
|
|
609 |
$sql = " AND (commentaire LIKE $commentaire OR ($sql)) ";
|
|
|
610 |
break;
|
|
|
611 |
case 'observation' :
|
|
|
612 |
$sql = " AND commentaire LIKE $commentaire ";
|
|
|
613 |
break;
|
|
|
614 |
case 'photo' :
|
|
|
615 |
$sql = ' AND '.$this->obtenirConditionPourCommentaires($commentaire).' ';
|
|
|
616 |
break;
|
|
|
617 |
case 'photo.meta' :
|
|
|
618 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireMeta($commentaire).' ';
|
|
|
619 |
break;
|
|
|
620 |
case 'photo.utilisateur' :
|
|
|
621 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireUtilisateur($commentaire).' ';
|
|
|
622 |
break;
|
|
|
623 |
default:
|
|
|
624 |
$sql = " AND commentaire LIKE $commentaire ";
|
|
|
625 |
}
|
|
|
626 |
}
|
|
|
627 |
return $sql;
|
|
|
628 |
}
|
|
|
629 |
|
|
|
630 |
|
|
|
631 |
private function construireWhereNomTaxon() {
|
|
|
632 |
$sql = '';
|
|
|
633 |
list($type, $nom) = $this->decomposerParametreTaxon();
|
|
|
634 |
if (!$this->etreNull($nom)) {
|
|
|
635 |
$nom = $this->proteger($nom.'%');
|
|
|
636 |
switch ($type) {
|
|
|
637 |
case '*' :
|
|
|
638 |
$sql = " AND (nom_ret LIKE $nom OR nom_sel LIKE $nom OR famille LIKE $nom) ";
|
|
|
639 |
break;
|
|
|
640 |
case 'retenu' :
|
|
|
641 |
$sql = " AND nom_ret LIKE $nom ";
|
|
|
642 |
break;
|
|
|
643 |
case 'selectionne' :
|
|
|
644 |
$sql = " AND nom_sel LIKE $nom ";
|
|
|
645 |
break;
|
|
|
646 |
case 'famille' :
|
|
|
647 |
$sql = " AND famille LIKE $nom ";
|
|
|
648 |
break;
|
|
|
649 |
default:
|
|
|
650 |
$sql = " AND nom_ret LIKE $nom ";
|
|
|
651 |
}
|
|
|
652 |
}
|
|
|
653 |
return $sql;
|
|
|
654 |
}
|
|
|
655 |
|
|
|
656 |
private function construireWhereDate() {
|
|
|
657 |
$sql = '';
|
|
|
658 |
// Récupération des coordonnées depuis l'id station
|
|
|
659 |
list($type, $date) = $this->decomposerParametreDate();
|
|
|
660 |
|
|
|
661 |
if (!$this->etreNull($date)) {
|
|
|
662 |
$date = $this->proteger($date.'%');
|
|
|
663 |
switch ($type) {
|
|
|
664 |
case '*' :
|
|
|
665 |
$sql = " AND (
|
|
|
666 |
date_observation LIKE $date
|
|
|
667 |
OR date_creation LIKE $date
|
|
|
668 |
OR date_modification LIKE $date
|
|
|
669 |
OR date_transmission LIKE $date) ";
|
|
|
670 |
break;
|
|
|
671 |
case 'observation' :
|
|
|
672 |
$sql = " AND date_observation LIKE $date ";
|
|
|
673 |
break;
|
|
|
674 |
case 'creation' :
|
|
|
675 |
$sql = " AND date_creation LIKE $date ";
|
|
|
676 |
break;
|
|
|
677 |
case 'modification' :
|
|
|
678 |
$sql = " AND date_modification LIKE $date ";
|
|
|
679 |
break;
|
|
|
680 |
case 'transmission' :
|
|
|
681 |
$sql = " AND date_transmission LIKE $date ";
|
|
|
682 |
break;
|
|
|
683 |
case 'photo' :
|
|
|
684 |
$sql = $this->obtenirConditionPourDatePhoto($date);
|
|
|
685 |
break;
|
|
|
686 |
case 'ajout' :
|
|
|
687 |
$sql = $this->obtenirConditionPourDateAjout($date);
|
|
|
688 |
break;
|
|
|
689 |
case 'liaison' :
|
|
|
690 |
$sql = $this->obtenirConditionPourDateLiaison($date);
|
|
|
691 |
break;
|
|
|
692 |
default:
|
|
|
693 |
$sql = " AND date_observation LIKE $date ";
|
|
|
694 |
}
|
|
|
695 |
}
|
|
|
696 |
return $sql;
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
private function obtenirConditionPourDatePhoto($date) {
|
|
|
700 |
$observations = $this->obtenirObsLieesImg('date.photo', $date);
|
|
|
701 |
if (is_null($observations)) {
|
|
|
702 |
$this->debug[] = "Aucune observation n'est liée à une photo prise à la date : $date";
|
|
|
703 |
}
|
|
|
704 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
705 |
return $sql;
|
|
|
706 |
}
|
|
|
707 |
|
|
|
708 |
private function obtenirConditionPourDateLiaison($date) {
|
|
|
709 |
$observations = $this->obtenirObsLieesImg('date.liaison', $date);
|
|
|
710 |
if (is_null($observations)) {
|
|
|
711 |
$this->debug[] = "Aucune observation n'a été liée à une image à à la date : $date";
|
|
|
712 |
}
|
|
|
713 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
714 |
return $sql;
|
|
|
715 |
}
|
|
|
716 |
|
|
|
717 |
private function obtenirConditionPourDateAjout($date) {
|
|
|
718 |
$observations = $this->obtenirObsLieesImg('date.ajout', $date);
|
|
|
719 |
if (is_null($observations)) {
|
|
|
720 |
$this->debug[] = "Aucune observation n'est liée à une image ajoutée à la date : $date";
|
|
|
721 |
}
|
|
|
722 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
723 |
return $sql;
|
|
|
724 |
}
|
|
|
725 |
|
|
|
726 |
private function obtenirConditionPourCommentaireMeta($commentaire) {
|
|
|
727 |
$observations = $this->obtenirObsLieesImg('commentaire.meta', $commentaire);
|
|
|
728 |
if (is_null($observations)) {
|
|
|
729 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des méta-données correspond à : $commmentaire";
|
|
|
730 |
}
|
|
|
731 |
$operateur = '';
|
|
|
732 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
733 |
return $sql;
|
|
|
734 |
}
|
|
|
735 |
|
|
|
736 |
private function obtenirConditionPourCommentaireUtilisateur($commentaire) {
|
|
|
737 |
$observations = $this->obtenirObsLieesImg('commentaire.utilisateur', $commentaire);
|
|
|
738 |
if (is_null($observations)) {
|
|
|
739 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des utilisateur correspond à : $commmentaire";
|
|
|
740 |
}
|
|
|
741 |
$operateur = '';
|
|
|
742 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
743 |
return $sql;
|
|
|
744 |
}
|
|
|
745 |
|
|
|
746 |
private function obtenirConditionPourCommentaires($commentaire) {
|
|
|
747 |
$observations = $this->obtenirObsLieesImg('commentaire.*', $commentaire);
|
|
|
748 |
if (is_null($observations)) {
|
|
|
749 |
$this->debug[] = "Aucune observation n'est liée à une image dont un des commentaires correspond à : $commmentaire";
|
|
|
750 |
}
|
|
|
751 |
$operateur = '';
|
|
|
752 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
753 |
return $sql;
|
|
|
754 |
}
|
|
|
755 |
|
|
|
756 |
/**
|
|
|
757 |
* Récupération des identifiant d'utilisateur et des ordres des observations correspondant à une date.
|
|
|
758 |
* Retour sous forme de tableau : array[identifiant] = array(ordre, ordre...);
|
|
|
759 |
*/
|
|
|
760 |
private function obtenirObsLieesImg($type, $param) {
|
|
|
761 |
// Construction de la requête
|
|
|
762 |
$requete = 'SELECT DISTINCT coi_ce_observation AS ordre, coi_ce_utilisateur AS utilisateur '.
|
|
|
763 |
'FROM cel_images '.
|
|
|
764 |
' LEFT JOIN cel_obs_images '.
|
|
|
765 |
' ON (ci_id_image = coi_ce_image) '.
|
|
|
766 |
' LEFT JOIN cel_inventory AS i '.
|
|
|
767 |
' ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
|
|
|
768 |
' LEFT JOIN locations AS l '.
|
|
|
769 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
770 |
"WHERE transmission = '1' ".
|
|
|
771 |
($type == 'date.photo' ? " AND (ci_meta_date_time LIKE ".str_replace('-', ':', $param)." OR ci_meta_date LIKE $param) " : '').
|
|
|
772 |
($type == 'date.ajout' ? " AND ci_meta_date_ajout LIKE $param " : '').
|
|
|
773 |
($type == 'date.liaison' ? " AND coi_date_liaison LIKE $param " : '').
|
|
|
774 |
($type == 'commentaire.meta' ? " AND ci_meta_comment LIKE $param " : '').
|
|
|
775 |
($type == 'commentaire.utilisateur' ? " AND ci_meta_user_comment LIKE $param " : '').
|
|
|
776 |
($type == 'commentaire.*' ? " AND (ci_meta_comment LIKE $param OR ci_meta_user_comment LIKE $param) " : '').
|
|
|
777 |
$this->construireWhereCoordonnees().
|
|
|
778 |
$this->construireWhereDept().
|
|
|
779 |
$this->construireWhereCommune().
|
|
|
780 |
$this->construireWhereUtilisateur().
|
|
|
781 |
$this->construireWhereNumTaxon().
|
|
|
782 |
$this->construireWhereNomTaxon().
|
|
|
783 |
$this->construireWhereProjet().
|
|
|
784 |
$this->construireWhereTag().
|
|
|
785 |
'ORDER BY utilisateur ASC, ordre ASC';
|
|
|
786 |
//$this->debug[] = $requete;
|
|
|
787 |
//die($requete);
|
|
|
788 |
$resultats = $this->executerRequete($requete);
|
|
|
789 |
|
|
|
790 |
$observations = null;
|
|
|
791 |
if ($resultats != false) {
|
|
|
792 |
$observations = array();
|
|
|
793 |
foreach ($resultats as $occurence) {
|
|
|
794 |
$utilisateur = $occurence['utilisateur'];
|
|
|
795 |
$ordre = $occurence['ordre'];
|
|
|
796 |
if (!array_key_exists($utilisateur, $observations)) {
|
|
|
797 |
$observations[$utilisateur] = array();
|
|
|
798 |
}
|
|
|
799 |
if (!array_key_exists($ordre, $observations[$utilisateur])) {
|
|
|
800 |
$observations[$utilisateur][$ordre] = $ordre;
|
|
|
801 |
}
|
|
|
802 |
}
|
|
|
803 |
}
|
|
|
804 |
return $observations;
|
|
|
805 |
}
|
|
|
806 |
|
|
|
807 |
private function assemblerObsEnConditionSql($observations, $operateur = 'AND') {
|
|
|
808 |
$sql = '';
|
|
|
809 |
if ($observations != null) {
|
|
|
810 |
// Pré-construction du where de la requête
|
|
|
811 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
|
|
812 |
foreach ($observations as $utilisateur => $ordres) {
|
|
|
813 |
$morceaux_requete[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
|
|
814 |
}
|
|
|
815 |
if (count($morceaux_requete) > 0) {
|
|
|
816 |
$sql = implode(" \nOR ", $morceaux_requete);
|
|
|
817 |
}
|
|
|
818 |
} else {
|
|
|
819 |
// Nous voulons que la requête ne retourne rien
|
|
|
820 |
$sql = "identifiant = '' AND ordre = ''";
|
|
|
821 |
}
|
|
|
822 |
$sql = " $operateur ($sql) ";
|
|
|
823 |
return $sql;
|
|
|
824 |
}
|
|
|
825 |
|
|
|
826 |
private function construireWhereRectangleStation() {
|
|
|
827 |
$sql = '';
|
1131 |
aurelien |
828 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
1121 |
aurelien |
829 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
830 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
|
|
831 |
|
|
|
832 |
$latMin = $sw['lat'];
|
|
|
833 |
$lngMin = $sw['lng'];
|
|
|
834 |
|
|
|
835 |
$latMax = $ne['lat'];
|
|
|
836 |
$lngMax = $ne['lng'];
|
|
|
837 |
|
|
|
838 |
// ATTENTION : coord_x correspond bien à la LATITUDE!
|
|
|
839 |
$sql = " AND (coord_x != 0 AND coord_y != 0) ".
|
|
|
840 |
" AND coord_x > $latMin ".
|
|
|
841 |
" AND coord_x < $latMax ".
|
|
|
842 |
" AND coord_y > $lngMin ".
|
|
|
843 |
" AND coord_y < $lngMax ";
|
|
|
844 |
}
|
|
|
845 |
return $sql;
|
|
|
846 |
}
|
|
|
847 |
|
|
|
848 |
private function construireWhereRectangleStationOR() {
|
|
|
849 |
$sql = '';
|
1131 |
aurelien |
850 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
1121 |
aurelien |
851 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
852 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
|
|
853 |
|
|
|
854 |
$latMin = $sw['lat'];
|
|
|
855 |
$lngMin = $sw['lng'];
|
|
|
856 |
|
|
|
857 |
$latMax = $ne['lat'];
|
|
|
858 |
$lngMax = $ne['lng'];
|
|
|
859 |
|
|
|
860 |
// ATTENTION : coord_x correspond bien à la LATITUDE!
|
|
|
861 |
$sql = "( (coord_x != 0 AND coord_y != 0) ".
|
|
|
862 |
" AND coord_x > $latMin ".
|
|
|
863 |
" AND coord_x < $latMax ".
|
|
|
864 |
" AND coord_y > $lngMin ".
|
|
|
865 |
" AND coord_y < $lngMax )";
|
|
|
866 |
}
|
|
|
867 |
return $sql;
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
private function construireWhereRectangleCommune() {
|
|
|
871 |
$sql = '';
|
1131 |
aurelien |
872 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
1121 |
aurelien |
873 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
874 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
|
|
875 |
|
|
|
876 |
$latMin = $sw['lat'];
|
|
|
877 |
$lngMin = $sw['lng'];
|
|
|
878 |
|
|
|
879 |
$latMax = $ne['lat'];
|
|
|
880 |
$lngMax = $ne['lng'];
|
|
|
881 |
|
|
|
882 |
$sql = "AND wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
|
|
883 |
" AND wgs84_latitude > $latMin ".
|
|
|
884 |
" AND wgs84_latitude < $latMax ".
|
|
|
885 |
" AND wgs84_longitude > $lngMin ".
|
|
|
886 |
" AND wgs84_longitude < $lngMax ";
|
|
|
887 |
}
|
|
|
888 |
return $sql;
|
|
|
889 |
}
|
|
|
890 |
|
|
|
891 |
private function construireWhereRectangleCommuneOR() {
|
|
|
892 |
$sql = '';
|
1131 |
aurelien |
893 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
1121 |
aurelien |
894 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
895 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
|
|
896 |
|
|
|
897 |
$latMin = $sw['lat'];
|
|
|
898 |
$lngMin = $sw['lng'];
|
|
|
899 |
|
|
|
900 |
$latMax = $ne['lat'];
|
|
|
901 |
$lngMax = $ne['lng'];
|
|
|
902 |
|
|
|
903 |
$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
|
|
904 |
" AND wgs84_latitude > $latMin ".
|
|
|
905 |
" AND wgs84_latitude < $latMax ".
|
|
|
906 |
" AND wgs84_longitude > $lngMin ".
|
|
|
907 |
" AND wgs84_longitude < $lngMax )";
|
|
|
908 |
}
|
|
|
909 |
return $sql;
|
|
|
910 |
}
|
|
|
911 |
|
|
|
912 |
private function construireWhereDept() {
|
|
|
913 |
$sql = '';
|
|
|
914 |
// Récupération des coordonnées depuis l'id station
|
|
|
915 |
extract($this->parametres);
|
1131 |
aurelien |
916 |
if (isset($this->parametres['dept']) && !$this->etreNull($dept)) {
|
1121 |
aurelien |
917 |
$dept = $this->traiterValeursMultiples($dept);
|
|
|
918 |
$sql = " AND code IN ($dept) ";
|
|
|
919 |
}
|
|
|
920 |
return $sql;
|
|
|
921 |
}
|
|
|
922 |
|
|
|
923 |
private function construireWhereCommune() {
|
|
|
924 |
$sql = '';
|
|
|
925 |
// Récupération des coordonnées depuis l'id station
|
|
|
926 |
extract($this->parametres);
|
1131 |
aurelien |
927 |
if (isset($this->parametres['commune']) && !$this->etreNull($commune)) {
|
1121 |
aurelien |
928 |
$commune = $this->proteger($commune);
|
|
|
929 |
$sql = " AND location LIKE $commune ";
|
|
|
930 |
}
|
|
|
931 |
return $sql;
|
|
|
932 |
}
|
|
|
933 |
|
1122 |
aurelien |
934 |
private function construireWhereCommuneSansCoordonneesAvecSensibles() {
|
|
|
935 |
$sql = '';
|
|
|
936 |
// Récupération des coordonnées depuis l'id station
|
|
|
937 |
extract($this->parametres);
|
1131 |
aurelien |
938 |
if (isset($this->parametres['commune']) && !$this->etreNull($commune)) {
|
1122 |
aurelien |
939 |
$commune = $this->proteger($commune);
|
|
|
940 |
$sql = " AND location LIKE $commune ";
|
|
|
941 |
$sql .= " AND (
|
|
|
942 |
(
|
|
|
943 |
(coord_x = '000null' OR coord_x = '') ".
|
|
|
944 |
" AND (coord_y = '000null' OR coord_y = '')".
|
|
|
945 |
')'.
|
|
|
946 |
' OR mots_cles_texte LIKE "%sensible%"'.
|
|
|
947 |
') ';
|
|
|
948 |
|
|
|
949 |
}
|
|
|
950 |
return $sql;
|
|
|
951 |
}
|
1121 |
aurelien |
952 |
|
|
|
953 |
private function construireWhereUtilisateur() {
|
|
|
954 |
$sql = '';
|
|
|
955 |
// Récupération des coordonnées depuis l'id station
|
|
|
956 |
extract($this->parametres);
|
1131 |
aurelien |
957 |
if (isset($this->parametres['utilisateur']) && !$this->etreNull($utilisateur)) {
|
1121 |
aurelien |
958 |
$utilisateur = $this->proteger($utilisateur);
|
|
|
959 |
$sql = " AND identifiant = $utilisateur ";
|
|
|
960 |
}
|
|
|
961 |
return $sql;
|
|
|
962 |
}
|
|
|
963 |
|
|
|
964 |
private function construireWhereNumTaxon() {
|
|
|
965 |
$sql = '';
|
|
|
966 |
// Récupération des coordonnées depuis l'id station
|
|
|
967 |
extract($this->parametres);
|
1131 |
aurelien |
968 |
if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
|
1121 |
aurelien |
969 |
$num_taxon = $this->proteger($num_taxon);
|
|
|
970 |
$sql = " AND num_taxon = $num_taxon ";
|
|
|
971 |
}
|
|
|
972 |
return $sql;
|
|
|
973 |
}
|
|
|
974 |
|
|
|
975 |
private function construireWhereProjet() {
|
|
|
976 |
$sql = '';
|
|
|
977 |
// Récupération des coordonnées depuis l'id station
|
|
|
978 |
extract($this->parametres);
|
1131 |
aurelien |
979 |
if(isset($this->parametres['projet']) ) {
|
|
|
980 |
$projet_sql = $this->getSqlWhereProjet($projet);
|
|
|
981 |
if (!$this->etreNull($projet_sql)) {
|
|
|
982 |
$sql = " AND ($projet_sql) ";
|
|
|
983 |
}
|
1121 |
aurelien |
984 |
}
|
|
|
985 |
return $sql;
|
|
|
986 |
}
|
|
|
987 |
|
|
|
988 |
/**
|
|
|
989 |
* Traitement de $projet pour construction du filtre dans la requête
|
|
|
990 |
*/
|
|
|
991 |
private function getSqlWhereProjet($projet) {
|
|
|
992 |
$sql = null;
|
|
|
993 |
if (! $this->etreNull($projet)) {
|
|
|
994 |
$mot_cle_encode = $this->bdd->quote($this->encoderMotCle($projet));
|
|
|
995 |
|
|
|
996 |
// Construction de la requête
|
|
|
997 |
$requete = 'SELECT * '.
|
|
|
998 |
'FROM cel_mots_cles_obs '.
|
|
|
999 |
"WHERE cmc_id_mot_cle_general = $mot_cle_encode ";
|
|
|
1000 |
$elements_projet = $this->executerRequete($requete);
|
|
|
1001 |
|
|
|
1002 |
$requete_projet = array();
|
|
|
1003 |
if ($elements_projet != false && count($elements_projet) > 0) {
|
|
|
1004 |
// Pré-construction du where de la requête
|
|
|
1005 |
$tpl_where = '(mots_cles LIKE "%%%s%%" AND identifiant = %s )';
|
|
|
1006 |
|
|
|
1007 |
foreach ($elements_projet as $occurence) {
|
|
|
1008 |
$requete_projet[] = sprintf($tpl_where, $occurence['cmc_id_mot_cle_utilisateur'], $this->bdd->quote($occurence['cmc_id_proprietaire']));
|
|
|
1009 |
}
|
|
|
1010 |
} else {
|
|
|
1011 |
$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
|
|
|
1012 |
}
|
|
|
1013 |
if (count($requete_projet) > 0) {
|
|
|
1014 |
$sql = implode(" \nOR ", $requete_projet);
|
|
|
1015 |
}
|
|
|
1016 |
}
|
|
|
1017 |
return $sql;
|
|
|
1018 |
}
|
|
|
1019 |
|
|
|
1020 |
private function construireWhereTag() {
|
|
|
1021 |
$sql = '';
|
|
|
1022 |
// Récupération des coordonnées depuis l'id station
|
|
|
1023 |
extract($this->parametres);
|
1131 |
aurelien |
1024 |
if(isset($this->parametres['tag']) ) {
|
|
|
1025 |
$tag_sql = $this->getSqlWhereObsAvecImagesTaguees($tag);
|
|
|
1026 |
if (!$this->etreNull($tag_sql)) {
|
|
|
1027 |
$sql = " AND ($tag_sql) ";
|
|
|
1028 |
}
|
1121 |
aurelien |
1029 |
}
|
|
|
1030 |
return $sql;
|
|
|
1031 |
}
|
|
|
1032 |
|
|
|
1033 |
/**
|
|
|
1034 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1035 |
*/
|
|
|
1036 |
private function getSqlWhereObsAvecImagesTaguees($tag) {
|
|
|
1037 |
$sql = null;
|
|
|
1038 |
if (! $this->etreNull($tag)) {
|
|
|
1039 |
$tag_sql = $this->getSqlWhereMotsCles($tag);
|
|
|
1040 |
// Construction de la requête
|
|
|
1041 |
$requete = 'SELECT DISTINCT coi_ce_observation AS ordre, coi_ce_utilisateur AS utilisateur '.
|
|
|
1042 |
'FROM cel_images '.
|
|
|
1043 |
' LEFT JOIN cel_obs_images '.
|
|
|
1044 |
' ON (ci_id_image = coi_ce_image) '.
|
|
|
1045 |
' LEFT JOIN cel_inventory AS i '.
|
|
|
1046 |
' ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
|
|
|
1047 |
' LEFT JOIN locations AS l '.
|
|
|
1048 |
" ON (l.name = i.location AND l.code = i.id_location) ".
|
|
|
1049 |
"WHERE transmission = '1' ".
|
|
|
1050 |
$this->construireWhereCoordonnees().
|
|
|
1051 |
$this->construireWhereUtilisateur().
|
|
|
1052 |
$this->construireWhereNumTaxon().
|
|
|
1053 |
$this->construireWhereNomTaxon().
|
|
|
1054 |
$this->construireWhereProjet().
|
|
|
1055 |
(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
|
|
|
1056 |
'ORDER BY utilisateur ASC, ordre ASC';
|
|
|
1057 |
//$this->debug[] = $requete;
|
|
|
1058 |
//die($requete);
|
|
|
1059 |
$elements_tag = $this->executerRequete($requete);
|
|
|
1060 |
|
|
|
1061 |
$requete_tag = array();
|
|
|
1062 |
if ($elements_tag != false && count($elements_tag) > 0) {
|
|
|
1063 |
|
|
|
1064 |
$filtres = array();
|
|
|
1065 |
foreach ($elements_tag as $occurence) {
|
|
|
1066 |
$utilisateur = $occurence['utilisateur'];
|
|
|
1067 |
$ordre = $occurence['ordre'];
|
|
|
1068 |
if (!array_key_exists($utilisateur, $filtres)) {
|
|
|
1069 |
$filtres[$utilisateur] = array();
|
|
|
1070 |
}
|
|
|
1071 |
if (!array_key_exists($ordre, $filtres[$utilisateur])) {
|
|
|
1072 |
$filtres[$utilisateur][$ordre] = $ordre;
|
|
|
1073 |
}
|
|
|
1074 |
}
|
|
|
1075 |
|
|
|
1076 |
// Pré-construction du where de la requête
|
|
|
1077 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
|
|
1078 |
foreach ($filtres as $utilisateur => $ordres) {
|
|
|
1079 |
$requete_tag[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
|
|
1080 |
}
|
|
|
1081 |
|
|
|
1082 |
} else {
|
|
|
1083 |
$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
|
|
|
1084 |
}
|
|
|
1085 |
if (count($requete_tag) > 0) {
|
|
|
1086 |
$sql = implode(" \nOR ", $requete_tag);
|
|
|
1087 |
}
|
|
|
1088 |
}
|
|
|
1089 |
return $sql;
|
|
|
1090 |
}
|
|
|
1091 |
|
|
|
1092 |
/**
|
|
|
1093 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1094 |
*/
|
|
|
1095 |
private function getSqlWhereMotsCles($tag) {
|
|
|
1096 |
$sql = null;
|
|
|
1097 |
$mots_cles = $this->decomposerParametreTag($tag);
|
|
|
1098 |
|
|
|
1099 |
// Construction de la requête
|
|
|
1100 |
$requete = 'SELECT cmc_id_proprietaire AS utilisateur, cmc_id_mot_cle_general AS mot_cle_general, '.
|
|
|
1101 |
' cmc_id_mot_cle_utilisateur AS mot_cle_utilisateur '.
|
|
|
1102 |
'FROM cel_mots_cles_images '.
|
|
|
1103 |
'WHERE '.$this->getSqlWhereMotsClesImages($mots_cles['motsClesEncodesProteges']);
|
|
|
1104 |
$elements_projet = $this->executerRequete($requete);
|
|
|
1105 |
//$this->debug[] = $requete;
|
|
|
1106 |
|
|
|
1107 |
$requete_projet = array();
|
|
|
1108 |
if ($elements_projet != false && count($elements_projet) > 0) {
|
|
|
1109 |
// Pré-construction du where de la requête
|
|
|
1110 |
if ($mots_cles['type'] == 'OR') {
|
|
|
1111 |
$tpl_where = '(ci_meta_mots_cles LIKE "%%%s,%%" AND ci_ce_utilisateur = %s )';
|
|
|
1112 |
foreach ($elements_projet as $occurence) {
|
|
|
1113 |
$requete_projet[] = sprintf($tpl_where, $occurence['mot_cle_utilisateur'], $this->bdd->quote($occurence['utilisateur']));
|
|
|
1114 |
}
|
|
|
1115 |
} else {
|
|
|
1116 |
$tpl_where_mc = "ci_meta_mots_cles LIKE '%%%s,%%'";
|
|
|
1117 |
$tpl_where = '((%s) AND ci_ce_utilisateur = %s)';
|
|
|
1118 |
$utilisateur_mc = array();
|
|
|
1119 |
foreach ($elements_projet as $occurence) {
|
|
|
1120 |
if (!isset($utilisateur_mc[$occurence['utilisateur']][$occurence['mot_cle_general']])) {
|
|
|
1121 |
$utilisateur_mc[$occurence['utilisateur']][$occurence['mot_cle_general']] = $occurence['mot_cle_utilisateur'];
|
|
|
1122 |
}
|
|
|
1123 |
}
|
|
|
1124 |
|
|
|
1125 |
foreach ($utilisateur_mc as $utilisateur => $mots_cles_utilisateur) {
|
|
|
1126 |
if (count($mots_cles_utilisateur) == count($mots_cles['motsCles'])) {
|
|
|
1127 |
$where_mots_cles_utilisateur = array();
|
|
|
1128 |
foreach ($mots_cles_utilisateur as $mot_cle) {
|
|
|
1129 |
$where_mots_cles_utilisateur[] = sprintf($tpl_where_mc, $mot_cle);
|
|
|
1130 |
}
|
|
|
1131 |
$where_mots_cles_utilisateur = implode(' AND ', $where_mots_cles_utilisateur);
|
|
|
1132 |
$utilisateur = $this->bdd->quote($utilisateur);
|
|
|
1133 |
$requete_projet[] = sprintf($tpl_where, $where_mots_cles_utilisateur, $utilisateur);
|
|
|
1134 |
}
|
|
|
1135 |
}
|
|
|
1136 |
}
|
|
|
1137 |
} else {
|
|
|
1138 |
$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
|
|
|
1139 |
}
|
|
|
1140 |
|
|
|
1141 |
$sql = implode(" \nOR ", $requete_projet);
|
|
|
1142 |
//$this->debug[] = $sql;
|
|
|
1143 |
return $sql;
|
|
|
1144 |
}
|
|
|
1145 |
|
|
|
1146 |
/**
|
|
|
1147 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1148 |
*/
|
|
|
1149 |
private function getSqlWhereMotsClesImages($mots_cles_encodes) {
|
|
|
1150 |
$where_mots_cles_images = array();
|
|
|
1151 |
foreach ($mots_cles_encodes as $mot_cle_encode) {
|
|
|
1152 |
$where_mots_cles_images[] = "cmc_id_mot_cle_general = $mot_cle_encode";
|
|
|
1153 |
}
|
|
|
1154 |
$where_mots_cles_images = implode(' OR ', $where_mots_cles_images);
|
|
|
1155 |
return $where_mots_cles_images;
|
|
|
1156 |
}
|
|
|
1157 |
|
|
|
1158 |
private function decomposerParametreTag($tags) {
|
|
|
1159 |
$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
|
|
|
1160 |
if (preg_match('/.+OU.+/', $tags)) {
|
|
|
1161 |
$mots_cles['type'] = 'OR';
|
|
|
1162 |
$mots_cles['motsCles'] = explode('OU', $tags);
|
|
|
1163 |
} else if (preg_match('/.+ET.+/', $tags)) {
|
|
|
1164 |
$mots_cles['type'] = 'AND';
|
|
|
1165 |
$mots_cles['motsCles'] = explode('ET', $tags);
|
|
|
1166 |
} else {
|
|
|
1167 |
$mots_cles['motsCles'][] = $tags;
|
|
|
1168 |
}
|
|
|
1169 |
|
|
|
1170 |
foreach ($mots_cles['motsCles'] as $mot) {
|
|
|
1171 |
$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote($this->encoderMotCle($mot));
|
|
|
1172 |
}
|
|
|
1173 |
$this->debug[] = $mots_cles;
|
|
|
1174 |
return $mots_cles;
|
|
|
1175 |
}
|
|
|
1176 |
|
|
|
1177 |
private function decomposerLatLng($coord) {
|
|
|
1178 |
$lat_lng = array();
|
|
|
1179 |
if (isset($coord)) {
|
|
|
1180 |
list($lat, $lng) = explode('|', $coord);
|
|
|
1181 |
$lat_lng = array('lat' => $lat, 'lng' => $lng);
|
|
|
1182 |
}
|
|
|
1183 |
return $lat_lng;
|
|
|
1184 |
}
|
|
|
1185 |
|
|
|
1186 |
private function decomposerParametreStation() {
|
|
|
1187 |
$station_infos = array();
|
|
|
1188 |
if (isset($this->parametres['station'])) {
|
|
|
1189 |
$station = $this->parametres['station'];
|
|
|
1190 |
$this->debug[] = $station;
|
|
|
1191 |
@list($type, $coord) = explode(':', $station);
|
|
|
1192 |
@list($lat, $lng) = explode('|', $coord);
|
|
|
1193 |
|
|
|
1194 |
$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
|
|
|
1195 |
}
|
|
|
1196 |
return $station_infos;
|
|
|
1197 |
}
|
|
|
1198 |
|
|
|
1199 |
private function decomposerParametreDate() {
|
1131 |
aurelien |
1200 |
$date_infos = array(null,null);
|
1121 |
aurelien |
1201 |
if (isset($this->parametres['date'])) {
|
|
|
1202 |
$date = $this->parametres['date'];
|
|
|
1203 |
if (strpos($date, ':')) {
|
|
|
1204 |
list($type, $date) = explode(':', $date);
|
|
|
1205 |
} else {
|
|
|
1206 |
$type = 'observation';
|
|
|
1207 |
}
|
|
|
1208 |
|
|
|
1209 |
$date = str_replace('/', '-', $date);
|
|
|
1210 |
if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $date, $matches)) {
|
|
|
1211 |
$date = $matches[3].'-'.$matches[2].'-'.$matches[1];
|
|
|
1212 |
}
|
|
|
1213 |
|
|
|
1214 |
$date_infos = array($type, $date);
|
|
|
1215 |
}
|
|
|
1216 |
return $date_infos;
|
|
|
1217 |
}
|
|
|
1218 |
|
|
|
1219 |
private function decomposerParametreTaxon() {
|
1131 |
aurelien |
1220 |
$nom_infos = array(null,null);
|
1121 |
aurelien |
1221 |
if (isset($this->parametres['taxon'])) {
|
|
|
1222 |
$taxon = $this->parametres['taxon'];
|
|
|
1223 |
if (strpos($taxon, ':')) {
|
|
|
1224 |
$nom_infos = explode(':', $taxon);
|
|
|
1225 |
} else {
|
|
|
1226 |
$nom_infos = array('retenu', $taxon);
|
|
|
1227 |
}
|
|
|
1228 |
}
|
|
|
1229 |
return $nom_infos;
|
|
|
1230 |
}
|
|
|
1231 |
|
|
|
1232 |
private function decomposerParametreCommentaire() {
|
1131 |
aurelien |
1233 |
$commentaire_infos = array(null,null);
|
1121 |
aurelien |
1234 |
if (isset($this->parametres['commentaire'])) {
|
|
|
1235 |
$commentaire = $this->parametres['commentaire'];
|
|
|
1236 |
if (strpos($commentaire, ':')) {
|
|
|
1237 |
$commentaire_infos = explode(':', $commentaire);
|
|
|
1238 |
} else {
|
|
|
1239 |
$commentaire_infos = array('observation', $commentaire);
|
|
|
1240 |
}
|
|
|
1241 |
}
|
|
|
1242 |
return $commentaire_infos;
|
|
|
1243 |
}
|
|
|
1244 |
}
|