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