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