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' ".
|
1043 |
aurelien |
387 |
((!$this->etreNull($this->parametres['commune'])) ? $this->construireWhereCommuneSansCoordonnees() : $this->construireWhereCoordonnees()).
|
938 |
jpm |
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) {
|
1043 |
aurelien |
491 |
if(isset($images[$id])) {
|
|
|
492 |
$infos['images'] = $images[$id];
|
|
|
493 |
$observations['observations'][$id] = $infos;
|
|
|
494 |
}
|
938 |
jpm |
495 |
}
|
|
|
496 |
return $observations;
|
|
|
497 |
}
|
1003 |
jpm |
498 |
|
938 |
jpm |
499 |
private function ajouterAuteursAuxObs($observations) {
|
944 |
jpm |
500 |
$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
|
938 |
jpm |
501 |
unset($observations['observateurs']);
|
|
|
502 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
503 |
$courriel = $infos['observateur'];
|
944 |
jpm |
504 |
$infos['observateur'] = $observateurs[$courriel]['intitule'];
|
|
|
505 |
$infos['observateurId'] = $observateurs[$courriel]['id'];
|
938 |
jpm |
506 |
$observations['observations'][$id] = $infos;
|
|
|
507 |
}
|
|
|
508 |
return $observations;
|
|
|
509 |
}
|
1003 |
jpm |
510 |
|
938 |
jpm |
511 |
private function supprimerIdDesObs($observations) {
|
|
|
512 |
// Le tableau de sortie ne doit pas avoir les id des obs en clé car sinon Jquery Template ne fonctionne pas
|
|
|
513 |
$observationSansId = $observations;
|
|
|
514 |
unset($observationSansId['observations']);
|
|
|
515 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
516 |
$observationSansId['observations'][] = $infos;
|
|
|
517 |
}
|
|
|
518 |
return $observationSansId;
|
|
|
519 |
}
|
1003 |
jpm |
520 |
|
478 |
jpm |
521 |
/**
|
938 |
jpm |
522 |
* Liste des taxons présents sur la carte
|
840 |
jpm |
523 |
*/
|
938 |
jpm |
524 |
public function getTaxons($params) {
|
840 |
jpm |
525 |
$json = null;
|
1003 |
jpm |
526 |
|
938 |
jpm |
527 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, num_nom_ret, num_taxon, famille '.
|
840 |
jpm |
528 |
'FROM cel_inventory AS i '.
|
|
|
529 |
' LEFT JOIN locations AS l '.
|
|
|
530 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
531 |
"WHERE transmission = '1' ".
|
938 |
jpm |
532 |
" AND nom_ret != '' ".
|
|
|
533 |
$this->construireWhereDept().
|
|
|
534 |
$this->construireWhereCommune().
|
|
|
535 |
$this->construireWhereUtilisateur().
|
|
|
536 |
$this->construireWhereNumTaxon().
|
|
|
537 |
$this->construireWhereNomTaxon().
|
|
|
538 |
$this->construireWhereDate().
|
940 |
jpm |
539 |
$this->construireWhereCommentaire().
|
938 |
jpm |
540 |
$this->construireWhereProjet().
|
981 |
jpm |
541 |
$this->construireWhereTag().
|
938 |
jpm |
542 |
'ORDER BY nom_ret ASC '.
|
|
|
543 |
"LIMIT {$this->start},{$this->limit} ";
|
|
|
544 |
//$this->debug[] = $requete;
|
|
|
545 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
1003 |
jpm |
546 |
|
938 |
jpm |
547 |
$requete = 'SELECT FOUND_ROWS()';
|
|
|
548 |
$taxons['total'] = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
|
1003 |
jpm |
549 |
|
938 |
jpm |
550 |
// Post-traitement
|
|
|
551 |
$taxons['taxons'] = $this->traiterTaxons($resultats);
|
1003 |
jpm |
552 |
|
938 |
jpm |
553 |
return $taxons;
|
840 |
jpm |
554 |
}
|
1003 |
jpm |
555 |
|
938 |
jpm |
556 |
private function traiterTaxons($donnees) {
|
|
|
557 |
$taxons = array();
|
|
|
558 |
if (is_array($donnees) && count($donnees) > 0) {
|
|
|
559 |
foreach ($donnees as $donnee) {
|
|
|
560 |
if (!isset($taxons[$donnee->num_taxon]) && ! $this->etreNull($donnee->nom_ret)) {
|
|
|
561 |
$taxon = array();
|
|
|
562 |
$taxon['nn'] = $donnee->num_nom_ret;
|
|
|
563 |
$taxon['nt'] = $donnee->num_taxon;
|
|
|
564 |
$taxon['nom'] = $this->nettoyerTexte($donnee->nom_ret);
|
|
|
565 |
$taxon['famille'] = $this->nettoyerTexte($donnee->famille);
|
|
|
566 |
$taxons[$donnee->num_taxon] = $taxon;
|
|
|
567 |
}
|
|
|
568 |
}
|
|
|
569 |
}
|
|
|
570 |
$taxons = array_values($taxons);
|
|
|
571 |
return $taxons;
|
|
|
572 |
}
|
1003 |
jpm |
573 |
|
938 |
jpm |
574 |
private function construireWhereCoordonnees() {
|
|
|
575 |
$sql = '';
|
|
|
576 |
// Récupération des coordonnées depuis l'id station
|
940 |
jpm |
577 |
extract($this->decomposerParametreStation());
|
938 |
jpm |
578 |
if (isset($type)) {
|
981 |
jpm |
579 |
if ($type == self::MARQUEUR_COMMUNE) {
|
954 |
jpm |
580 |
$lat = $this->proteger($lat);
|
|
|
581 |
$lng = $this->proteger($lng);
|
1033 |
aurelien |
582 |
$sql = " AND (ROUND(wgs84_latitude,5) = ROUND($lat,5) AND ROUND(wgs84_longitude,5) = ROUND($lng,5)) ";
|
981 |
jpm |
583 |
} else if ($type == self::MARQUEUR_STATION) {
|
954 |
jpm |
584 |
$lat = $this->proteger($lat);
|
|
|
585 |
$lng = $this->proteger($lng);
|
|
|
586 |
$sql = " AND (coord_x = $lat AND coord_y = $lng) ";
|
938 |
jpm |
587 |
}
|
1003 |
jpm |
588 |
}
|
938 |
jpm |
589 |
return $sql;
|
|
|
590 |
}
|
1003 |
jpm |
591 |
|
940 |
jpm |
592 |
private function construireWhereCommentaire() {
|
|
|
593 |
$sql = '';
|
|
|
594 |
list($type, $commentaire) = $this->decomposerParametreCommentaire();
|
|
|
595 |
if (!$this->etreNull($commentaire)) {
|
|
|
596 |
$commentaire = $this->proteger('%'.$commentaire.'%');
|
|
|
597 |
switch ($type) {
|
|
|
598 |
case '*' :
|
|
|
599 |
$sql = $this->obtenirConditionPourCommentaires($commentaire);
|
|
|
600 |
$sql = " AND (commentaire LIKE $commentaire OR ($sql)) ";
|
|
|
601 |
break;
|
|
|
602 |
case 'observation' :
|
|
|
603 |
$sql = " AND commentaire LIKE $commentaire ";
|
|
|
604 |
break;
|
|
|
605 |
case 'photo' :
|
|
|
606 |
$sql = ' AND '.$this->obtenirConditionPourCommentaires($commentaire).' ';
|
|
|
607 |
break;
|
|
|
608 |
case 'photo.meta' :
|
|
|
609 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireMeta($commentaire).' ';
|
|
|
610 |
break;
|
|
|
611 |
case 'photo.utilisateur' :
|
|
|
612 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireUtilisateur($commentaire).' ';
|
|
|
613 |
break;
|
|
|
614 |
default:
|
|
|
615 |
$sql = " AND commentaire LIKE $commentaire ";
|
1003 |
jpm |
616 |
}
|
940 |
jpm |
617 |
}
|
|
|
618 |
return $sql;
|
|
|
619 |
}
|
1003 |
jpm |
620 |
|
|
|
621 |
|
938 |
jpm |
622 |
private function construireWhereNomTaxon() {
|
|
|
623 |
$sql = '';
|
940 |
jpm |
624 |
list($type, $nom) = $this->decomposerParametreTaxon();
|
|
|
625 |
if (!$this->etreNull($nom)) {
|
938 |
jpm |
626 |
$nom = $this->proteger($nom.'%');
|
|
|
627 |
switch ($type) {
|
|
|
628 |
case '*' :
|
|
|
629 |
$sql = " AND (nom_ret LIKE $nom OR nom_sel LIKE $nom OR famille LIKE $nom) ";
|
|
|
630 |
break;
|
940 |
jpm |
631 |
case 'retenu' :
|
938 |
jpm |
632 |
$sql = " AND nom_ret LIKE $nom ";
|
|
|
633 |
break;
|
940 |
jpm |
634 |
case 'selectionne' :
|
938 |
jpm |
635 |
$sql = " AND nom_sel LIKE $nom ";
|
|
|
636 |
break;
|
940 |
jpm |
637 |
case 'famille' :
|
938 |
jpm |
638 |
$sql = " AND famille LIKE $nom ";
|
|
|
639 |
break;
|
|
|
640 |
default:
|
|
|
641 |
$sql = " AND nom_ret LIKE $nom ";
|
1003 |
jpm |
642 |
}
|
938 |
jpm |
643 |
}
|
|
|
644 |
return $sql;
|
|
|
645 |
}
|
1003 |
jpm |
646 |
|
938 |
jpm |
647 |
private function construireWhereDate() {
|
|
|
648 |
$sql = '';
|
|
|
649 |
// Récupération des coordonnées depuis l'id station
|
940 |
jpm |
650 |
list($type, $date) = $this->decomposerParametreDate();
|
1003 |
jpm |
651 |
|
938 |
jpm |
652 |
if (!$this->etreNull($date)) {
|
|
|
653 |
$date = $this->proteger($date.'%');
|
|
|
654 |
switch ($type) {
|
|
|
655 |
case '*' :
|
|
|
656 |
$sql = " AND (
|
1003 |
jpm |
657 |
date_observation LIKE $date
|
|
|
658 |
OR date_creation LIKE $date
|
|
|
659 |
OR date_modification LIKE $date
|
938 |
jpm |
660 |
OR date_transmission LIKE $date) ";
|
|
|
661 |
break;
|
|
|
662 |
case 'observation' :
|
|
|
663 |
$sql = " AND date_observation LIKE $date ";
|
|
|
664 |
break;
|
|
|
665 |
case 'creation' :
|
|
|
666 |
$sql = " AND date_creation LIKE $date ";
|
|
|
667 |
break;
|
|
|
668 |
case 'modification' :
|
|
|
669 |
$sql = " AND date_modification LIKE $date ";
|
|
|
670 |
break;
|
|
|
671 |
case 'transmission' :
|
|
|
672 |
$sql = " AND date_transmission LIKE $date ";
|
|
|
673 |
break;
|
940 |
jpm |
674 |
case 'photo' :
|
|
|
675 |
$sql = $this->obtenirConditionPourDatePhoto($date);
|
|
|
676 |
break;
|
|
|
677 |
case 'ajout' :
|
|
|
678 |
$sql = $this->obtenirConditionPourDateAjout($date);
|
|
|
679 |
break;
|
938 |
jpm |
680 |
case 'liaison' :
|
940 |
jpm |
681 |
$sql = $this->obtenirConditionPourDateLiaison($date);
|
938 |
jpm |
682 |
break;
|
|
|
683 |
default:
|
|
|
684 |
$sql = " AND date_observation LIKE $date ";
|
|
|
685 |
}
|
|
|
686 |
}
|
|
|
687 |
return $sql;
|
|
|
688 |
}
|
1003 |
jpm |
689 |
|
940 |
jpm |
690 |
private function obtenirConditionPourDatePhoto($date) {
|
|
|
691 |
$observations = $this->obtenirObsLieesImg('date.photo', $date);
|
|
|
692 |
if (is_null($observations)) {
|
|
|
693 |
$this->debug[] = "Aucune observation n'est liée à une photo prise à la date : $date";
|
|
|
694 |
}
|
|
|
695 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
696 |
return $sql;
|
|
|
697 |
}
|
1003 |
jpm |
698 |
|
940 |
jpm |
699 |
private function obtenirConditionPourDateLiaison($date) {
|
|
|
700 |
$observations = $this->obtenirObsLieesImg('date.liaison', $date);
|
|
|
701 |
if (is_null($observations)) {
|
|
|
702 |
$this->debug[] = "Aucune observation n'a été liée à une image à à la date : $date";
|
|
|
703 |
}
|
|
|
704 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
705 |
return $sql;
|
|
|
706 |
}
|
|
|
707 |
|
|
|
708 |
private function obtenirConditionPourDateAjout($date) {
|
|
|
709 |
$observations = $this->obtenirObsLieesImg('date.ajout', $date);
|
|
|
710 |
if (is_null($observations)) {
|
|
|
711 |
$this->debug[] = "Aucune observation n'est liée à une image ajoutée à la date : $date";
|
|
|
712 |
}
|
|
|
713 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
714 |
return $sql;
|
|
|
715 |
}
|
1003 |
jpm |
716 |
|
940 |
jpm |
717 |
private function obtenirConditionPourCommentaireMeta($commentaire) {
|
|
|
718 |
$observations = $this->obtenirObsLieesImg('commentaire.meta', $commentaire);
|
|
|
719 |
if (is_null($observations)) {
|
|
|
720 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des méta-données correspond à : $commmentaire";
|
|
|
721 |
}
|
|
|
722 |
$operateur = '';
|
|
|
723 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
724 |
return $sql;
|
|
|
725 |
}
|
1003 |
jpm |
726 |
|
940 |
jpm |
727 |
private function obtenirConditionPourCommentaireUtilisateur($commentaire) {
|
|
|
728 |
$observations = $this->obtenirObsLieesImg('commentaire.utilisateur', $commentaire);
|
|
|
729 |
if (is_null($observations)) {
|
|
|
730 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des utilisateur correspond à : $commmentaire";
|
|
|
731 |
}
|
|
|
732 |
$operateur = '';
|
|
|
733 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
734 |
return $sql;
|
|
|
735 |
}
|
1003 |
jpm |
736 |
|
940 |
jpm |
737 |
private function obtenirConditionPourCommentaires($commentaire) {
|
|
|
738 |
$observations = $this->obtenirObsLieesImg('commentaire.*', $commentaire);
|
|
|
739 |
if (is_null($observations)) {
|
|
|
740 |
$this->debug[] = "Aucune observation n'est liée à une image dont un des commentaires correspond à : $commmentaire";
|
|
|
741 |
}
|
|
|
742 |
$operateur = '';
|
|
|
743 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
744 |
return $sql;
|
|
|
745 |
}
|
1003 |
jpm |
746 |
|
940 |
jpm |
747 |
/**
|
|
|
748 |
* Récupération des identifiant d'utilisateur et des ordres des observations correspondant à une date.
|
|
|
749 |
* Retour sous forme de tableau : array[identifiant] = array(ordre, ordre...);
|
|
|
750 |
*/
|
|
|
751 |
private function obtenirObsLieesImg($type, $param) {
|
|
|
752 |
// Construction de la requête
|
|
|
753 |
$requete = 'SELECT DISTINCT coi_ce_observation AS ordre, coi_ce_utilisateur AS utilisateur '.
|
|
|
754 |
'FROM cel_images '.
|
|
|
755 |
' LEFT JOIN cel_obs_images '.
|
|
|
756 |
' ON (ci_id_image = coi_ce_image) '.
|
|
|
757 |
' LEFT JOIN cel_inventory AS i '.
|
|
|
758 |
' ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
|
|
|
759 |
' LEFT JOIN locations AS l '.
|
|
|
760 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
761 |
"WHERE transmission = '1' ".
|
|
|
762 |
($type == 'date.photo' ? " AND (ci_meta_date_time LIKE ".str_replace('-', ':', $param)." OR ci_meta_date LIKE $param) " : '').
|
|
|
763 |
($type == 'date.ajout' ? " AND ci_meta_date_ajout LIKE $param " : '').
|
|
|
764 |
($type == 'date.liaison' ? " AND coi_date_liaison LIKE $param " : '').
|
|
|
765 |
($type == 'commentaire.meta' ? " AND ci_meta_comment LIKE $param " : '').
|
|
|
766 |
($type == 'commentaire.utilisateur' ? " AND ci_meta_user_comment LIKE $param " : '').
|
|
|
767 |
($type == 'commentaire.*' ? " AND (ci_meta_comment LIKE $param OR ci_meta_user_comment LIKE $param) " : '').
|
1003 |
jpm |
768 |
$this->construireWhereCoordonnees().
|
940 |
jpm |
769 |
$this->construireWhereDept().
|
|
|
770 |
$this->construireWhereCommune().
|
|
|
771 |
$this->construireWhereUtilisateur().
|
|
|
772 |
$this->construireWhereNumTaxon().
|
|
|
773 |
$this->construireWhereNomTaxon().
|
|
|
774 |
$this->construireWhereProjet().
|
|
|
775 |
$this->construireWhereTag().
|
|
|
776 |
'ORDER BY utilisateur ASC, ordre ASC';
|
|
|
777 |
//$this->debug[] = $requete;
|
|
|
778 |
//die($requete);
|
|
|
779 |
$resultats = $this->executerRequete($requete);
|
1003 |
jpm |
780 |
|
940 |
jpm |
781 |
$observations = null;
|
|
|
782 |
if ($resultats != false) {
|
|
|
783 |
$observations = array();
|
|
|
784 |
foreach ($resultats as $occurence) {
|
|
|
785 |
$utilisateur = $occurence['utilisateur'];
|
|
|
786 |
$ordre = $occurence['ordre'];
|
|
|
787 |
if (!array_key_exists($utilisateur, $observations)) {
|
|
|
788 |
$observations[$utilisateur] = array();
|
|
|
789 |
}
|
|
|
790 |
if (!array_key_exists($ordre, $observations[$utilisateur])) {
|
|
|
791 |
$observations[$utilisateur][$ordre] = $ordre;
|
|
|
792 |
}
|
|
|
793 |
}
|
|
|
794 |
}
|
|
|
795 |
return $observations;
|
|
|
796 |
}
|
1003 |
jpm |
797 |
|
940 |
jpm |
798 |
private function assemblerObsEnConditionSql($observations, $operateur = 'AND') {
|
|
|
799 |
$sql = '';
|
|
|
800 |
if ($observations != null) {
|
|
|
801 |
// Pré-construction du where de la requête
|
|
|
802 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
|
|
803 |
foreach ($observations as $utilisateur => $ordres) {
|
|
|
804 |
$morceaux_requete[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
|
|
805 |
}
|
|
|
806 |
if (count($morceaux_requete) > 0) {
|
|
|
807 |
$sql = implode(" \nOR ", $morceaux_requete);
|
|
|
808 |
}
|
|
|
809 |
} else {
|
|
|
810 |
// Nous voulons que la requête ne retourne rien
|
|
|
811 |
$sql = "identifiant = '' AND ordre = ''";
|
|
|
812 |
}
|
|
|
813 |
$sql = " $operateur ($sql) ";
|
|
|
814 |
return $sql;
|
|
|
815 |
}
|
1003 |
jpm |
816 |
|
981 |
jpm |
817 |
private function construireWhereRectangleStation() {
|
|
|
818 |
$sql = '';
|
|
|
819 |
if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
|
|
820 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
821 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
822 |
|
981 |
jpm |
823 |
$latMin = $sw['lat'];
|
|
|
824 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
825 |
|
981 |
jpm |
826 |
$latMax = $ne['lat'];
|
|
|
827 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
828 |
|
981 |
jpm |
829 |
// ATTENTION : coord_x correspond bien à la LATITUDE!
|
1003 |
jpm |
830 |
$sql = " AND (coord_x != 0 AND coord_y != 0) ".
|
981 |
jpm |
831 |
" AND coord_x > $latMin ".
|
|
|
832 |
" AND coord_x < $latMax ".
|
|
|
833 |
" AND coord_y > $lngMin ".
|
|
|
834 |
" AND coord_y < $lngMax ";
|
|
|
835 |
}
|
|
|
836 |
return $sql;
|
|
|
837 |
}
|
1003 |
jpm |
838 |
|
981 |
jpm |
839 |
private function construireWhereRectangleStationOR() {
|
|
|
840 |
$sql = '';
|
|
|
841 |
if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
|
|
842 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
843 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
844 |
|
981 |
jpm |
845 |
$latMin = $sw['lat'];
|
|
|
846 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
847 |
|
981 |
jpm |
848 |
$latMax = $ne['lat'];
|
|
|
849 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
850 |
|
981 |
jpm |
851 |
// ATTENTION : coord_x correspond bien à la LATITUDE!
|
1003 |
jpm |
852 |
$sql = "( (coord_x != 0 AND coord_y != 0) ".
|
981 |
jpm |
853 |
" AND coord_x > $latMin ".
|
|
|
854 |
" AND coord_x < $latMax ".
|
|
|
855 |
" AND coord_y > $lngMin ".
|
|
|
856 |
" AND coord_y < $lngMax )";
|
|
|
857 |
}
|
|
|
858 |
return $sql;
|
|
|
859 |
}
|
1003 |
jpm |
860 |
|
981 |
jpm |
861 |
private function construireWhereRectangleCommune() {
|
|
|
862 |
$sql = '';
|
|
|
863 |
if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
|
|
864 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
865 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
866 |
|
981 |
jpm |
867 |
$latMin = $sw['lat'];
|
|
|
868 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
869 |
|
981 |
jpm |
870 |
$latMax = $ne['lat'];
|
|
|
871 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
872 |
|
|
|
873 |
$sql = "AND wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
981 |
jpm |
874 |
" AND wgs84_latitude > $latMin ".
|
|
|
875 |
" AND wgs84_latitude < $latMax ".
|
|
|
876 |
" AND wgs84_longitude > $lngMin ".
|
|
|
877 |
" AND wgs84_longitude < $lngMax ";
|
|
|
878 |
}
|
|
|
879 |
return $sql;
|
|
|
880 |
}
|
1003 |
jpm |
881 |
|
981 |
jpm |
882 |
private function construireWhereRectangleCommuneOR() {
|
|
|
883 |
$sql = '';
|
|
|
884 |
if (! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
|
|
885 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
886 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
887 |
|
981 |
jpm |
888 |
$latMin = $sw['lat'];
|
|
|
889 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
890 |
|
981 |
jpm |
891 |
$latMax = $ne['lat'];
|
|
|
892 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
893 |
|
|
|
894 |
$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
981 |
jpm |
895 |
" AND wgs84_latitude > $latMin ".
|
|
|
896 |
" AND wgs84_latitude < $latMax ".
|
|
|
897 |
" AND wgs84_longitude > $lngMin ".
|
|
|
898 |
" AND wgs84_longitude < $lngMax )";
|
|
|
899 |
}
|
|
|
900 |
return $sql;
|
|
|
901 |
}
|
1003 |
jpm |
902 |
|
938 |
jpm |
903 |
private function construireWhereDept() {
|
|
|
904 |
$sql = '';
|
|
|
905 |
// Récupération des coordonnées depuis l'id station
|
|
|
906 |
extract($this->parametres);
|
|
|
907 |
if (!$this->etreNull($dept)) {
|
|
|
908 |
$dept = $this->traiterValeursMultiples($dept);
|
|
|
909 |
$sql = " AND code IN ($dept) ";
|
|
|
910 |
}
|
|
|
911 |
return $sql;
|
|
|
912 |
}
|
1003 |
jpm |
913 |
|
938 |
jpm |
914 |
private function construireWhereCommune() {
|
|
|
915 |
$sql = '';
|
|
|
916 |
// Récupération des coordonnées depuis l'id station
|
|
|
917 |
extract($this->parametres);
|
|
|
918 |
if (!$this->etreNull($commune)) {
|
|
|
919 |
$commune = $this->proteger($commune);
|
|
|
920 |
$sql = " AND location LIKE $commune ";
|
|
|
921 |
}
|
|
|
922 |
return $sql;
|
|
|
923 |
}
|
1003 |
jpm |
924 |
|
1043 |
aurelien |
925 |
private function construireWhereCommuneSansCoordonnees() {
|
|
|
926 |
$sql = '';
|
|
|
927 |
// Récupération des coordonnées depuis l'id station
|
|
|
928 |
extract($this->parametres);
|
|
|
929 |
if (!$this->etreNull($commune)) {
|
|
|
930 |
$commune = $this->proteger($commune);
|
|
|
931 |
$sql = " AND location LIKE $commune ";
|
|
|
932 |
$sql .= " AND ((coord_x = '000null' OR coord_x = '') ".
|
|
|
933 |
" AND (coord_y = '000null' OR coord_y = '')) ";
|
|
|
934 |
}
|
|
|
935 |
return $sql;
|
|
|
936 |
}
|
1003 |
jpm |
937 |
|
938 |
jpm |
938 |
private function construireWhereUtilisateur() {
|
|
|
939 |
$sql = '';
|
|
|
940 |
// Récupération des coordonnées depuis l'id station
|
|
|
941 |
extract($this->parametres);
|
|
|
942 |
if (!$this->etreNull($utilisateur)) {
|
|
|
943 |
$utilisateur = $this->proteger($utilisateur);
|
|
|
944 |
$sql = " AND identifiant = $utilisateur ";
|
|
|
945 |
}
|
|
|
946 |
return $sql;
|
|
|
947 |
}
|
1003 |
jpm |
948 |
|
938 |
jpm |
949 |
private function construireWhereNumTaxon() {
|
|
|
950 |
$sql = '';
|
|
|
951 |
// Récupération des coordonnées depuis l'id station
|
|
|
952 |
extract($this->parametres);
|
|
|
953 |
if (!$this->etreNull($num_taxon)) {
|
|
|
954 |
$num_taxon = $this->proteger($num_taxon);
|
|
|
955 |
$sql = " AND num_taxon = $num_taxon ";
|
|
|
956 |
}
|
|
|
957 |
return $sql;
|
|
|
958 |
}
|
1003 |
jpm |
959 |
|
938 |
jpm |
960 |
private function construireWhereProjet() {
|
|
|
961 |
$sql = '';
|
|
|
962 |
// Récupération des coordonnées depuis l'id station
|
|
|
963 |
extract($this->parametres);
|
|
|
964 |
$projet_sql = $this->getSqlWhereProjet($projet);
|
|
|
965 |
if (!$this->etreNull($projet_sql)) {
|
|
|
966 |
$sql = " AND ($projet_sql) ";
|
|
|
967 |
}
|
|
|
968 |
return $sql;
|
|
|
969 |
}
|
1003 |
jpm |
970 |
|
840 |
jpm |
971 |
/**
|
938 |
jpm |
972 |
* Traitement de $projet pour construction du filtre dans la requête
|
478 |
jpm |
973 |
*/
|
938 |
jpm |
974 |
private function getSqlWhereProjet($projet) {
|
|
|
975 |
$sql = null;
|
|
|
976 |
if (! $this->etreNull($projet)) {
|
|
|
977 |
$mot_cle_encode = $this->bdd->quote($this->encoderMotCle($projet));
|
1003 |
jpm |
978 |
|
938 |
jpm |
979 |
// Construction de la requête
|
|
|
980 |
$requete = 'SELECT * '.
|
|
|
981 |
'FROM cel_mots_cles_obs '.
|
|
|
982 |
"WHERE cmc_id_mot_cle_general = $mot_cle_encode ";
|
|
|
983 |
$elements_projet = $this->executerRequete($requete);
|
1003 |
jpm |
984 |
|
938 |
jpm |
985 |
$requete_projet = array();
|
|
|
986 |
if ($elements_projet != false && count($elements_projet) > 0) {
|
|
|
987 |
// Pré-construction du where de la requête
|
|
|
988 |
$tpl_where = '(mots_cles LIKE "%%%s%%" AND identifiant = %s )';
|
1003 |
jpm |
989 |
|
938 |
jpm |
990 |
foreach ($elements_projet as $occurence) {
|
|
|
991 |
$requete_projet[] = sprintf($tpl_where, $occurence['cmc_id_mot_cle_utilisateur'], $this->bdd->quote($occurence['cmc_id_proprietaire']));
|
|
|
992 |
}
|
|
|
993 |
} else {
|
|
|
994 |
$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
|
|
|
995 |
}
|
|
|
996 |
if (count($requete_projet) > 0) {
|
|
|
997 |
$sql = implode(" \nOR ", $requete_projet);
|
|
|
998 |
}
|
|
|
999 |
}
|
|
|
1000 |
return $sql;
|
|
|
1001 |
}
|
1003 |
jpm |
1002 |
|
938 |
jpm |
1003 |
private function construireWhereTag() {
|
|
|
1004 |
$sql = '';
|
|
|
1005 |
// Récupération des coordonnées depuis l'id station
|
840 |
jpm |
1006 |
extract($this->parametres);
|
938 |
jpm |
1007 |
$tag_sql = $this->getSqlWhereObsAvecImagesTaguees($tag);
|
|
|
1008 |
if (!$this->etreNull($tag_sql)) {
|
|
|
1009 |
$sql = " AND ($tag_sql) ";
|
489 |
jpm |
1010 |
}
|
938 |
jpm |
1011 |
return $sql;
|
|
|
1012 |
}
|
1003 |
jpm |
1013 |
|
938 |
jpm |
1014 |
/**
|
|
|
1015 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1016 |
*/
|
|
|
1017 |
private function getSqlWhereObsAvecImagesTaguees($tag) {
|
|
|
1018 |
$sql = null;
|
|
|
1019 |
if (! $this->etreNull($tag)) {
|
|
|
1020 |
$tag_sql = $this->getSqlWhereMotsCles($tag);
|
|
|
1021 |
// Construction de la requête
|
|
|
1022 |
$requete = 'SELECT DISTINCT coi_ce_observation AS ordre, coi_ce_utilisateur AS utilisateur '.
|
|
|
1023 |
'FROM cel_images '.
|
|
|
1024 |
' LEFT JOIN cel_obs_images '.
|
|
|
1025 |
' ON (ci_id_image = coi_ce_image) '.
|
|
|
1026 |
' LEFT JOIN cel_inventory AS i '.
|
|
|
1027 |
' ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
|
|
|
1028 |
' LEFT JOIN locations AS l '.
|
|
|
1029 |
" ON (l.name = i.location AND l.code = i.id_location) ".
|
|
|
1030 |
"WHERE transmission = '1' ".
|
|
|
1031 |
$this->construireWhereCoordonnees().
|
|
|
1032 |
$this->construireWhereUtilisateur().
|
|
|
1033 |
$this->construireWhereNumTaxon().
|
|
|
1034 |
$this->construireWhereNomTaxon().
|
|
|
1035 |
$this->construireWhereProjet().
|
|
|
1036 |
(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
|
|
|
1037 |
'ORDER BY utilisateur ASC, ordre ASC';
|
|
|
1038 |
//$this->debug[] = $requete;
|
|
|
1039 |
//die($requete);
|
|
|
1040 |
$elements_tag = $this->executerRequete($requete);
|
1003 |
jpm |
1041 |
|
938 |
jpm |
1042 |
$requete_tag = array();
|
|
|
1043 |
if ($elements_tag != false && count($elements_tag) > 0) {
|
1003 |
jpm |
1044 |
|
938 |
jpm |
1045 |
$filtres = array();
|
|
|
1046 |
foreach ($elements_tag as $occurence) {
|
|
|
1047 |
$utilisateur = $occurence['utilisateur'];
|
|
|
1048 |
$ordre = $occurence['ordre'];
|
|
|
1049 |
if (!array_key_exists($utilisateur, $filtres)) {
|
|
|
1050 |
$filtres[$utilisateur] = array();
|
|
|
1051 |
}
|
|
|
1052 |
if (!array_key_exists($ordre, $filtres[$utilisateur])) {
|
|
|
1053 |
$filtres[$utilisateur][$ordre] = $ordre;
|
|
|
1054 |
}
|
|
|
1055 |
}
|
1003 |
jpm |
1056 |
|
938 |
jpm |
1057 |
// Pré-construction du where de la requête
|
|
|
1058 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
|
|
1059 |
foreach ($filtres as $utilisateur => $ordres) {
|
|
|
1060 |
$requete_tag[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
|
|
1061 |
}
|
1003 |
jpm |
1062 |
|
938 |
jpm |
1063 |
} else {
|
|
|
1064 |
$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
|
|
|
1065 |
}
|
|
|
1066 |
if (count($requete_tag) > 0) {
|
|
|
1067 |
$sql = implode(" \nOR ", $requete_tag);
|
|
|
1068 |
}
|
489 |
jpm |
1069 |
}
|
938 |
jpm |
1070 |
return $sql;
|
478 |
jpm |
1071 |
}
|
1003 |
jpm |
1072 |
|
487 |
jpm |
1073 |
/**
|
938 |
jpm |
1074 |
* Traitement de $tag pour construction du filtre dans la requête
|
487 |
jpm |
1075 |
*/
|
938 |
jpm |
1076 |
private function getSqlWhereMotsCles($tag) {
|
|
|
1077 |
$sql = null;
|
940 |
jpm |
1078 |
$mots_cles = $this->decomposerParametreTag($tag);
|
1003 |
jpm |
1079 |
|
487 |
jpm |
1080 |
// Construction de la requête
|
938 |
jpm |
1081 |
$requete = 'SELECT cmc_id_proprietaire AS utilisateur, cmc_id_mot_cle_general AS mot_cle_general, '.
|
|
|
1082 |
' cmc_id_mot_cle_utilisateur AS mot_cle_utilisateur '.
|
|
|
1083 |
'FROM cel_mots_cles_images '.
|
|
|
1084 |
'WHERE '.$this->getSqlWhereMotsClesImages($mots_cles['motsClesEncodesProteges']);
|
487 |
jpm |
1085 |
$elements_projet = $this->executerRequete($requete);
|
938 |
jpm |
1086 |
//$this->debug[] = $requete;
|
1003 |
jpm |
1087 |
|
487 |
jpm |
1088 |
$requete_projet = array();
|
|
|
1089 |
if ($elements_projet != false && count($elements_projet) > 0) {
|
|
|
1090 |
// Pré-construction du where de la requête
|
938 |
jpm |
1091 |
if ($mots_cles['type'] == 'OR') {
|
|
|
1092 |
$tpl_where = '(ci_meta_mots_cles LIKE "%%%s,%%" AND ci_ce_utilisateur = %s )';
|
|
|
1093 |
foreach ($elements_projet as $occurence) {
|
|
|
1094 |
$requete_projet[] = sprintf($tpl_where, $occurence['mot_cle_utilisateur'], $this->bdd->quote($occurence['utilisateur']));
|
|
|
1095 |
}
|
|
|
1096 |
} else {
|
|
|
1097 |
$tpl_where_mc = "ci_meta_mots_cles LIKE '%%%s,%%'";
|
|
|
1098 |
$tpl_where = '((%s) AND ci_ce_utilisateur = %s)';
|
|
|
1099 |
$utilisateur_mc = array();
|
|
|
1100 |
foreach ($elements_projet as $occurence) {
|
|
|
1101 |
if (!isset($utilisateur_mc[$occurence['utilisateur']][$occurence['mot_cle_general']])) {
|
|
|
1102 |
$utilisateur_mc[$occurence['utilisateur']][$occurence['mot_cle_general']] = $occurence['mot_cle_utilisateur'];
|
1003 |
jpm |
1103 |
}
|
938 |
jpm |
1104 |
}
|
1003 |
jpm |
1105 |
|
938 |
jpm |
1106 |
foreach ($utilisateur_mc as $utilisateur => $mots_cles_utilisateur) {
|
|
|
1107 |
if (count($mots_cles_utilisateur) == count($mots_cles['motsCles'])) {
|
|
|
1108 |
$where_mots_cles_utilisateur = array();
|
|
|
1109 |
foreach ($mots_cles_utilisateur as $mot_cle) {
|
|
|
1110 |
$where_mots_cles_utilisateur[] = sprintf($tpl_where_mc, $mot_cle);
|
|
|
1111 |
}
|
|
|
1112 |
$where_mots_cles_utilisateur = implode(' AND ', $where_mots_cles_utilisateur);
|
|
|
1113 |
$utilisateur = $this->bdd->quote($utilisateur);
|
|
|
1114 |
$requete_projet[] = sprintf($tpl_where, $where_mots_cles_utilisateur, $utilisateur);
|
|
|
1115 |
}
|
|
|
1116 |
}
|
487 |
jpm |
1117 |
}
|
|
|
1118 |
} else {
|
|
|
1119 |
$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
|
|
|
1120 |
}
|
1003 |
jpm |
1121 |
|
487 |
jpm |
1122 |
$sql = implode(" \nOR ", $requete_projet);
|
938 |
jpm |
1123 |
//$this->debug[] = $sql;
|
487 |
jpm |
1124 |
return $sql;
|
840 |
jpm |
1125 |
}
|
1003 |
jpm |
1126 |
|
938 |
jpm |
1127 |
/**
|
|
|
1128 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1129 |
*/
|
|
|
1130 |
private function getSqlWhereMotsClesImages($mots_cles_encodes) {
|
|
|
1131 |
$where_mots_cles_images = array();
|
|
|
1132 |
foreach ($mots_cles_encodes as $mot_cle_encode) {
|
|
|
1133 |
$where_mots_cles_images[] = "cmc_id_mot_cle_general = $mot_cle_encode";
|
|
|
1134 |
}
|
|
|
1135 |
$where_mots_cles_images = implode(' OR ', $where_mots_cles_images);
|
|
|
1136 |
return $where_mots_cles_images;
|
|
|
1137 |
}
|
1003 |
jpm |
1138 |
|
940 |
jpm |
1139 |
private function decomposerParametreTag($tags) {
|
938 |
jpm |
1140 |
$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
|
|
|
1141 |
if (preg_match('/.+OU.+/', $tags)) {
|
|
|
1142 |
$mots_cles['type'] = 'OR';
|
|
|
1143 |
$mots_cles['motsCles'] = explode('OU', $tags);
|
|
|
1144 |
} else if (preg_match('/.+ET.+/', $tags)) {
|
|
|
1145 |
$mots_cles['type'] = 'AND';
|
|
|
1146 |
$mots_cles['motsCles'] = explode('ET', $tags);
|
|
|
1147 |
} else {
|
|
|
1148 |
$mots_cles['motsCles'][] = $tags;
|
|
|
1149 |
}
|
1003 |
jpm |
1150 |
|
938 |
jpm |
1151 |
foreach ($mots_cles['motsCles'] as $mot) {
|
|
|
1152 |
$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote($this->encoderMotCle($mot));
|
|
|
1153 |
}
|
|
|
1154 |
$this->debug[] = $mots_cles;
|
|
|
1155 |
return $mots_cles;
|
|
|
1156 |
}
|
1003 |
jpm |
1157 |
|
981 |
jpm |
1158 |
private function decomposerLatLng($coord) {
|
|
|
1159 |
$lat_lng = array();
|
|
|
1160 |
if (isset($coord)) {
|
|
|
1161 |
list($lat, $lng) = explode('|', $coord);
|
|
|
1162 |
$lat_lng = array('lat' => $lat, 'lng' => $lng);
|
|
|
1163 |
}
|
|
|
1164 |
return $lat_lng;
|
|
|
1165 |
}
|
1003 |
jpm |
1166 |
|
940 |
jpm |
1167 |
private function decomposerParametreStation() {
|
938 |
jpm |
1168 |
$station_infos = array();
|
|
|
1169 |
if (isset($this->parametres['station'])) {
|
|
|
1170 |
$station = $this->parametres['station'];
|
|
|
1171 |
$this->debug[] = $station;
|
1033 |
aurelien |
1172 |
@list($type, $coord) = explode(':', $station);
|
|
|
1173 |
@list($lat, $lng) = explode('|', $coord);
|
1003 |
jpm |
1174 |
|
954 |
jpm |
1175 |
$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
|
938 |
jpm |
1176 |
}
|
|
|
1177 |
return $station_infos;
|
|
|
1178 |
}
|
1003 |
jpm |
1179 |
|
940 |
jpm |
1180 |
private function decomposerParametreDate() {
|
|
|
1181 |
$date_infos = array();
|
|
|
1182 |
if (isset($this->parametres['date'])) {
|
|
|
1183 |
$date = $this->parametres['date'];
|
|
|
1184 |
if (strpos($date, ':')) {
|
|
|
1185 |
list($type, $date) = explode(':', $date);
|
|
|
1186 |
} else {
|
|
|
1187 |
$type = 'observation';
|
|
|
1188 |
}
|
1003 |
jpm |
1189 |
|
940 |
jpm |
1190 |
$date = str_replace('/', '-', $date);
|
|
|
1191 |
if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $date, $matches)) {
|
|
|
1192 |
$date = $matches[3].'-'.$matches[2].'-'.$matches[1];
|
|
|
1193 |
}
|
1003 |
jpm |
1194 |
|
940 |
jpm |
1195 |
$date_infos = array($type, $date);
|
|
|
1196 |
}
|
|
|
1197 |
return $date_infos;
|
|
|
1198 |
}
|
1003 |
jpm |
1199 |
|
940 |
jpm |
1200 |
private function decomposerParametreTaxon() {
|
|
|
1201 |
$nom_infos = array();
|
|
|
1202 |
if (isset($this->parametres['taxon'])) {
|
|
|
1203 |
$taxon = $this->parametres['taxon'];
|
|
|
1204 |
if (strpos($taxon, ':')) {
|
|
|
1205 |
$nom_infos = explode(':', $taxon);
|
|
|
1206 |
} else {
|
|
|
1207 |
$nom_infos = array('retenu', $taxon);
|
|
|
1208 |
}
|
|
|
1209 |
}
|
|
|
1210 |
return $nom_infos;
|
|
|
1211 |
}
|
1003 |
jpm |
1212 |
|
940 |
jpm |
1213 |
private function decomposerParametreCommentaire() {
|
|
|
1214 |
$commentaire_infos = array();
|
|
|
1215 |
if (isset($this->parametres['commentaire'])) {
|
|
|
1216 |
$commentaire = $this->parametres['commentaire'];
|
|
|
1217 |
if (strpos($commentaire, ':')) {
|
|
|
1218 |
$commentaire_infos = explode(':', $commentaire);
|
|
|
1219 |
} else {
|
|
|
1220 |
$commentaire_infos = array('observation', $commentaire);
|
|
|
1221 |
}
|
|
|
1222 |
}
|
|
|
1223 |
return $commentaire_infos;
|
|
|
1224 |
}
|
416 |
aurelien |
1225 |
}
|