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