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