416 |
aurelien |
1 |
<?php
|
550 |
jpm |
2 |
// declare(encoding='UTF-8');
|
416 |
aurelien |
3 |
/**
|
|
|
4 |
* Service fournissant une carte dynamique des obsertions publiques du CEL.
|
|
|
5 |
* Encodage en entrée : utf8
|
|
|
6 |
* Encodage en sortie : utf8
|
|
|
7 |
*
|
|
|
8 |
* Cas d'utilisation :
|
|
|
9 |
* /CelWidgetMap/Carte/Utilisateur : carte des observations publiques d'un utilisateur.
|
|
|
10 |
* /CelWidgetMap/Carte/Utilisateur/Projet : carte des observations publiques d'un utilisateur pour un projet.
|
485 |
delphine |
11 |
* /CelWidgetMap/Carte/Utilisateur/Projet/dept : carte des observations publiques d'un utilisateur pour un projet sur un département.
|
|
|
12 |
* /CelWidgetMap/Carte/Utilisateur/Projet/dept/num_taxon : carte des observations publiques d'un utilisateur pour un projet sur un département pour un taxon.
|
416 |
aurelien |
13 |
*
|
|
|
14 |
* Carte = Type de carte. Valeurs possible : defaut,
|
|
|
15 |
* Utilisateur = identifiant (= courriel) de l'utilisateur ou * pour tous les utilisateurs.
|
|
|
16 |
* Projet = mot-clé du projet
|
|
|
17 |
*
|
|
|
18 |
* @author Jean-Pascal MILCENT <jpm@clapas.org>
|
|
|
19 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
20 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
21 |
* @version $Id$
|
|
|
22 |
* @copyright © 2010, Jean-Pascal MILCENT
|
|
|
23 |
*/
|
519 |
jpm |
24 |
// TODO : supprimer le TRIM quand les obs seront reliées correctements aux localisations (sur le code INSEE par exemple)
|
416 |
aurelien |
25 |
class CelWidgetMap extends Cel {
|
485 |
delphine |
26 |
|
416 |
aurelien |
27 |
/**
|
|
|
28 |
* Méthode appelée avec une requête de type GET.
|
|
|
29 |
*/
|
840 |
jpm |
30 |
public function getElement($ressources) {
|
416 |
aurelien |
31 |
$retour = null;
|
840 |
jpm |
32 |
extract($this->parametres);
|
485 |
delphine |
33 |
|
840 |
jpm |
34 |
$action = array_shift($ressources);
|
|
|
35 |
if (isset($action)) {
|
|
|
36 |
$methode = $this->traiterNomMethodeGet($action);
|
416 |
aurelien |
37 |
if (method_exists($this, $methode)) {
|
840 |
jpm |
38 |
$retour = $this->$methode($ressources);
|
416 |
aurelien |
39 |
} else {
|
840 |
jpm |
40 |
$this->messages[] = "Ce type de ressource '$methode' n'est pas disponible.";
|
416 |
aurelien |
41 |
}
|
|
|
42 |
} else {
|
840 |
jpm |
43 |
$this->messages[] = "Vous devez indiquer le type de ressource.";
|
416 |
aurelien |
44 |
}
|
|
|
45 |
|
|
|
46 |
if (is_null($retour)) {
|
|
|
47 |
$info = 'Un problème est survenu : '.print_r($this->messages, true);
|
|
|
48 |
$this->envoyer($info);
|
938 |
jpm |
49 |
} else if ($retour['type'] == 'jsonVar') {
|
|
|
50 |
|
694 |
jpm |
51 |
$this->envoyerJsonVar($retour['variable_js'], $retour['donnees']);
|
938 |
jpm |
52 |
} else if ($retour['type'] == 'jsonP') {
|
584 |
jpm |
53 |
$this->envoyerJsonp($retour['donnees']);
|
474 |
jpm |
54 |
} else {
|
938 |
jpm |
55 |
$this->envoyerJson($retour);
|
416 |
aurelien |
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
938 |
jpm |
60 |
* Les stations de la carte par défaut
|
416 |
aurelien |
61 |
*/
|
938 |
jpm |
62 |
public function getStations($params) {
|
416 |
aurelien |
63 |
$json = null;
|
954 |
jpm |
64 |
$requete = 'SELECT sector, x_utm, y_utm, wgs84_latitude AS commune_latitude, wgs84_longitude AS commune_longitude, '.
|
|
|
65 |
' coord_x AS point_latitude, coord_y AS point_longitude '.
|
938 |
jpm |
66 |
'FROM cel_inventory AS i '.
|
|
|
67 |
' LEFT JOIN locations AS l '.
|
|
|
68 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
69 |
"WHERE transmission = '1' ".
|
|
|
70 |
$this->construireWhereDept().
|
|
|
71 |
$this->construireWhereCommune().
|
|
|
72 |
$this->construireWhereUtilisateur().
|
|
|
73 |
$this->construireWhereNumTaxon().
|
|
|
74 |
$this->construireWhereNomTaxon().
|
|
|
75 |
$this->construireWhereDate().
|
940 |
jpm |
76 |
$this->construireWhereCommentaire().
|
938 |
jpm |
77 |
$this->construireWhereProjet().
|
|
|
78 |
$this->construireWhereTag();
|
940 |
jpm |
79 |
//die($requete);
|
840 |
jpm |
80 |
$resultats = $this->requeter($requete);
|
485 |
delphine |
81 |
|
416 |
aurelien |
82 |
// Traitement des résultats
|
954 |
jpm |
83 |
$json['donnees'] = $this->traiterStations($resultats);
|
938 |
jpm |
84 |
|
|
|
85 |
// Création des infos du widget
|
|
|
86 |
$json['type'] = (isset($this->formatRetour)) ? $this->formatRetour : 'jsonVar';
|
|
|
87 |
$json['variable_js'] = 'stations';
|
|
|
88 |
|
|
|
89 |
return $json;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
private function traiterNbreObs($resultats) {
|
|
|
93 |
$obs_nbre = 0;
|
|
|
94 |
if ($resultats !== false) {
|
|
|
95 |
$obs_nbre = count($resultats);
|
|
|
96 |
}
|
|
|
97 |
return $obs_nbre;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
private function traiterStations($resultats) {
|
954 |
jpm |
101 |
$stations = array(
|
|
|
102 |
'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
|
|
|
103 |
'points' => null
|
|
|
104 |
);
|
|
|
105 |
$stations['stats']['observations'] = $this->traiterNbreObs($resultats);
|
|
|
106 |
|
|
|
107 |
$points = array();
|
840 |
jpm |
108 |
if ($resultats !== false) {
|
|
|
109 |
foreach ($resultats as $enrg) {
|
954 |
jpm |
110 |
if (!$this->etreNull($enrg['point_latitude'])&& !$this->etreNull($enrg['point_longitude'])) {
|
|
|
111 |
$lat = $enrg['point_latitude'];
|
|
|
112 |
$lng = $enrg['point_longitude'];
|
|
|
113 |
$id = $lat.'-'.$lng;
|
|
|
114 |
if (!isset($points[$id])) {
|
|
|
115 |
$points[$id]['id'] = "POINT:$lat-$lng";
|
|
|
116 |
$points[$id]['lat'] = round($lat, 5);
|
|
|
117 |
$points[$id]['lng'] = round($lng, 5);
|
|
|
118 |
$points[$id]['nbre'] = 1;
|
|
|
119 |
$stations['stats']['stations']++;
|
840 |
jpm |
120 |
} else {
|
954 |
jpm |
121 |
$points[$id]['nbre']++;
|
840 |
jpm |
122 |
}
|
954 |
jpm |
123 |
} else if (!$this->etreNull($enrg['commune_latitude'])&& !$this->etreNull($enrg['commune_longitude'])) {
|
|
|
124 |
$lat = $enrg['commune_latitude'];
|
|
|
125 |
$lng = $enrg['commune_longitude'];
|
|
|
126 |
$id = $lat.'-'.$lng;
|
|
|
127 |
if (!isset($points[$id])) {
|
|
|
128 |
$points[$id]['id'] = "COMMUNE:$lat-$lng";
|
|
|
129 |
$points[$id]['lat'] = round($lat, 5);
|
|
|
130 |
$points[$id]['lng'] = round($lng, 5);
|
|
|
131 |
$points[$id]['nbre'] = 1;
|
|
|
132 |
$stations['stats']['communes']++;
|
|
|
133 |
} else {
|
|
|
134 |
$points[$id]['nbre']++;
|
|
|
135 |
}
|
|
|
136 |
}
|
416 |
aurelien |
137 |
}
|
954 |
jpm |
138 |
$stations['points'] = array_values($points);
|
416 |
aurelien |
139 |
}
|
938 |
jpm |
140 |
return $stations;
|
416 |
aurelien |
141 |
}
|
474 |
jpm |
142 |
|
|
|
143 |
/**
|
|
|
144 |
* Données pour l'affichage des obs d'une station
|
|
|
145 |
*/
|
|
|
146 |
public function getObservations($params) {
|
938 |
jpm |
147 |
$resultats = array();
|
|
|
148 |
$total = 0;
|
|
|
149 |
if (!$this->etreNull($this->parametres['station'])) {
|
|
|
150 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS id, identifiant, nom_sel, nom_ret, num_nom_sel, num_nom_ret, num_taxon, famille, '.
|
|
|
151 |
' lieudit, location, date_observation, milieu, commentaire, '.
|
|
|
152 |
' sector, x_utm, y_utm, insee_code, date_transmission '.
|
|
|
153 |
'FROM cel_inventory AS i '.
|
|
|
154 |
' LEFT JOIN locations AS l '.
|
|
|
155 |
" ON (l.name = i.location AND l.code = i.id_location) ".
|
|
|
156 |
"WHERE transmission = '1' ".
|
|
|
157 |
$this->construireWhereCoordonnees().
|
|
|
158 |
$this->construireWhereUtilisateur().
|
|
|
159 |
$this->construireWhereNumTaxon().
|
|
|
160 |
$this->construireWhereNomTaxon().
|
|
|
161 |
$this->construireWhereDate().
|
940 |
jpm |
162 |
$this->construireWhereCommentaire().
|
938 |
jpm |
163 |
$this->construireWhereProjet().
|
|
|
164 |
$this->construireWhereTag().
|
|
|
165 |
'ORDER BY nom_sel ASC '.
|
|
|
166 |
"LIMIT {$this->start},{$this->limit} ";
|
|
|
167 |
//die($requete);
|
|
|
168 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
|
|
169 |
|
|
|
170 |
$requete = 'SELECT FOUND_ROWS()';
|
|
|
171 |
$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
|
474 |
jpm |
172 |
}
|
487 |
jpm |
173 |
|
474 |
jpm |
174 |
// Post-traitement
|
938 |
jpm |
175 |
$observations = $this->traiterObservations($resultats, $total);
|
|
|
176 |
$observations = $this->ajouterImagesAuxObs($observations);
|
|
|
177 |
$observations = $this->ajouterAuteursAuxObs($observations);
|
|
|
178 |
$observations = $this->supprimerIdDesObs($observations);
|
|
|
179 |
return $observations;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
private function traiterObservations($donnees, $total) {
|
|
|
183 |
$observations = array('commune' => '', 'observations' => array(), 'observateurs' => array());
|
|
|
184 |
$observations['total'] = (isset($total)) ? $total : 0;
|
|
|
185 |
if (is_array($donnees) && count($donnees) > 0) {
|
|
|
186 |
foreach ($donnees as $donnee) {
|
|
|
187 |
$observation = array();
|
|
|
188 |
$observation['idObs'] = $donnee->id;
|
|
|
189 |
$observation['nn'] = $this->etreNull($donnee->num_nom_sel) ? null : $donnee->num_nom_sel;
|
|
|
190 |
$observation['nomSci'] = $this->nettoyerTexte($donnee->nom_sel);
|
|
|
191 |
$observation['date'] = $this->formaterDate($donnee->date_observation, '%d/%m/%Y');
|
|
|
192 |
$observation['datePubli'] = $this->formaterDate($donnee->date_transmission);
|
|
|
193 |
$observation['lieu'] = $this->traiterLieu($donnee);
|
|
|
194 |
$observation['observateur'] = $donnee->identifiant;
|
|
|
195 |
$observation['urlEflore'] = $this->getUrlEflore($donnee->num_nom_sel);
|
|
|
196 |
|
|
|
197 |
if (isset($donnee->location)) {
|
|
|
198 |
$observations['commune'] = $this->nettoyerTexte($donnee->location);
|
|
|
199 |
}
|
|
|
200 |
$observations['observations'][$donnee->id] = $observation;
|
|
|
201 |
|
|
|
202 |
if (! array_key_exists($donnee->identifiant, $observations['observateurs'])) {
|
|
|
203 |
$observations['observateurs'][$donnee->identifiant] = $donnee->identifiant;
|
|
|
204 |
}
|
|
|
205 |
}
|
487 |
jpm |
206 |
}
|
938 |
jpm |
207 |
return $observations;
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
private function getUrlEflore($nn) {
|
|
|
211 |
$urlEflore = null;
|
|
|
212 |
if (! $this->etreNull($nn)) {
|
|
|
213 |
$urlEflore = sprintf($this->config['settings']['efloreUrlTpl'], $nn, 'illustration');
|
|
|
214 |
}
|
|
|
215 |
return $urlEflore;
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
private function traiterLieu($donnee) {
|
|
|
219 |
$lieu = array();
|
|
|
220 |
if (!$this->etreNull($donnee->lieudit)) {
|
|
|
221 |
$lieu[] = $donnee->lieudit;
|
|
|
222 |
}
|
|
|
223 |
if (!$this->etreNull($donnee->milieu)) {
|
|
|
224 |
$lieu[] = $donnee->milieu;
|
|
|
225 |
}
|
|
|
226 |
return implode(', ', $lieu);
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
private function chargerImages(Array $obs_ids) {
|
|
|
230 |
// Récupération des données au format Json
|
|
|
231 |
$service = 'CelImage/liste-ids?obsId='.implode(',', $obs_ids);
|
|
|
232 |
$url = sprintf($this->config['settings']['baseURLServicesCelTpl'], $service);
|
|
|
233 |
$json = $this->getRestClient()->consulter($url);
|
|
|
234 |
$donnees = json_decode($json);
|
|
|
235 |
|
|
|
236 |
// Post-traitement des données
|
|
|
237 |
$images = $this->traiterImages($donnees);
|
474 |
jpm |
238 |
|
938 |
jpm |
239 |
return $images;
|
474 |
jpm |
240 |
}
|
478 |
jpm |
241 |
|
938 |
jpm |
242 |
private function traiterImages($donnees) {
|
|
|
243 |
$images = array();
|
|
|
244 |
if (count($donnees) > 0) {
|
|
|
245 |
foreach ($donnees as $id_obs => $id_images) {
|
|
|
246 |
foreach ($id_images as $id_img) {
|
|
|
247 |
$urls['idImg'] = $id_img;
|
|
|
248 |
$urls['guid'] = sprintf($this->config['settings']['guidImgTpl'], $id_img);
|
|
|
249 |
$urls['miniature'] = $this->getUrlImage($id_img, 'CXS');
|
|
|
250 |
$urls['normale'] = $this->getUrlImage($id_img, 'XL');
|
|
|
251 |
$images[$id_obs][] = $urls;
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
}
|
|
|
255 |
return $images;
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
private function ajouterImagesAuxObs($observations) {
|
|
|
259 |
$images = $this->chargerImages(array_keys($observations['observations']));
|
|
|
260 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
261 |
$infos['images'] = $images[$id];
|
|
|
262 |
$observations['observations'][$id] = $infos;
|
|
|
263 |
}
|
|
|
264 |
return $observations;
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
private function ajouterAuteursAuxObs($observations) {
|
944 |
jpm |
268 |
$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
|
938 |
jpm |
269 |
unset($observations['observateurs']);
|
|
|
270 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
271 |
$courriel = $infos['observateur'];
|
944 |
jpm |
272 |
$infos['observateur'] = $observateurs[$courriel]['intitule'];
|
|
|
273 |
$infos['observateurId'] = $observateurs[$courriel]['id'];
|
938 |
jpm |
274 |
$observations['observations'][$id] = $infos;
|
|
|
275 |
}
|
|
|
276 |
return $observations;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
private function supprimerIdDesObs($observations) {
|
|
|
280 |
// Le tableau de sortie ne doit pas avoir les id des obs en clé car sinon Jquery Template ne fonctionne pas
|
|
|
281 |
$observationSansId = $observations;
|
|
|
282 |
unset($observationSansId['observations']);
|
|
|
283 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
284 |
$observationSansId['observations'][] = $infos;
|
|
|
285 |
}
|
|
|
286 |
return $observationSansId;
|
|
|
287 |
}
|
|
|
288 |
|
478 |
jpm |
289 |
/**
|
938 |
jpm |
290 |
* Liste des taxons présents sur la carte
|
840 |
jpm |
291 |
*/
|
938 |
jpm |
292 |
public function getTaxons($params) {
|
840 |
jpm |
293 |
$json = null;
|
|
|
294 |
|
938 |
jpm |
295 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, num_nom_ret, num_taxon, famille '.
|
840 |
jpm |
296 |
'FROM cel_inventory AS i '.
|
|
|
297 |
' LEFT JOIN locations AS l '.
|
|
|
298 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
299 |
"WHERE transmission = '1' ".
|
938 |
jpm |
300 |
" AND nom_ret != '' ".
|
|
|
301 |
$this->construireWhereDept().
|
|
|
302 |
$this->construireWhereCommune().
|
|
|
303 |
$this->construireWhereUtilisateur().
|
|
|
304 |
$this->construireWhereNumTaxon().
|
|
|
305 |
$this->construireWhereNomTaxon().
|
|
|
306 |
$this->construireWhereDate().
|
940 |
jpm |
307 |
$this->construireWhereCommentaire().
|
938 |
jpm |
308 |
$this->construireWhereProjet().
|
|
|
309 |
$this->construireWhereTag();
|
|
|
310 |
'ORDER BY nom_ret ASC '.
|
|
|
311 |
"LIMIT {$this->start},{$this->limit} ";
|
|
|
312 |
//$this->debug[] = $requete;
|
|
|
313 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
840 |
jpm |
314 |
|
938 |
jpm |
315 |
$requete = 'SELECT FOUND_ROWS()';
|
|
|
316 |
$taxons['total'] = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
|
840 |
jpm |
317 |
|
938 |
jpm |
318 |
// Post-traitement
|
|
|
319 |
$taxons['taxons'] = $this->traiterTaxons($resultats);
|
|
|
320 |
|
|
|
321 |
return $taxons;
|
840 |
jpm |
322 |
}
|
|
|
323 |
|
938 |
jpm |
324 |
private function traiterTaxons($donnees) {
|
|
|
325 |
$taxons = array();
|
|
|
326 |
if (is_array($donnees) && count($donnees) > 0) {
|
|
|
327 |
foreach ($donnees as $donnee) {
|
|
|
328 |
if (!isset($taxons[$donnee->num_taxon]) && ! $this->etreNull($donnee->nom_ret)) {
|
|
|
329 |
$taxon = array();
|
|
|
330 |
$taxon['nn'] = $donnee->num_nom_ret;
|
|
|
331 |
$taxon['nt'] = $donnee->num_taxon;
|
|
|
332 |
$taxon['nom'] = $this->nettoyerTexte($donnee->nom_ret);
|
|
|
333 |
$taxon['famille'] = $this->nettoyerTexte($donnee->famille);
|
|
|
334 |
$taxons[$donnee->num_taxon] = $taxon;
|
|
|
335 |
}
|
|
|
336 |
}
|
|
|
337 |
}
|
|
|
338 |
$taxons = array_values($taxons);
|
|
|
339 |
return $taxons;
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
private function construireWhereCoordonnees() {
|
|
|
343 |
$sql = '';
|
|
|
344 |
// Récupération des coordonnées depuis l'id station
|
940 |
jpm |
345 |
extract($this->decomposerParametreStation());
|
938 |
jpm |
346 |
if (isset($type)) {
|
954 |
jpm |
347 |
if ($type == 'COMMUNE') {
|
|
|
348 |
$lat = $this->proteger($lat);
|
|
|
349 |
$lng = $this->proteger($lng);
|
|
|
350 |
$sql = " AND (wgs84_latitude = $lat AND wgs84_longitude = $lng) ";
|
|
|
351 |
} else if ($type == 'POINT') {
|
|
|
352 |
$lat = $this->proteger($lat);
|
|
|
353 |
$lng = $this->proteger($lng);
|
|
|
354 |
$sql = " AND (coord_x = $lat AND coord_y = $lng) ";
|
938 |
jpm |
355 |
}
|
|
|
356 |
}
|
|
|
357 |
return $sql;
|
|
|
358 |
}
|
|
|
359 |
|
940 |
jpm |
360 |
private function construireWhereCommentaire() {
|
|
|
361 |
$sql = '';
|
|
|
362 |
list($type, $commentaire) = $this->decomposerParametreCommentaire();
|
|
|
363 |
if (!$this->etreNull($commentaire)) {
|
|
|
364 |
$commentaire = $this->proteger('%'.$commentaire.'%');
|
|
|
365 |
switch ($type) {
|
|
|
366 |
case '*' :
|
|
|
367 |
$sql = $this->obtenirConditionPourCommentaires($commentaire);
|
|
|
368 |
$sql = " AND (commentaire LIKE $commentaire OR ($sql)) ";
|
|
|
369 |
break;
|
|
|
370 |
case 'observation' :
|
|
|
371 |
$sql = " AND commentaire LIKE $commentaire ";
|
|
|
372 |
break;
|
|
|
373 |
case 'photo' :
|
|
|
374 |
$sql = ' AND '.$this->obtenirConditionPourCommentaires($commentaire).' ';
|
|
|
375 |
break;
|
|
|
376 |
case 'photo.meta' :
|
|
|
377 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireMeta($commentaire).' ';
|
|
|
378 |
break;
|
|
|
379 |
case 'photo.utilisateur' :
|
|
|
380 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireUtilisateur($commentaire).' ';
|
|
|
381 |
break;
|
|
|
382 |
default:
|
|
|
383 |
$sql = " AND commentaire LIKE $commentaire ";
|
|
|
384 |
}
|
|
|
385 |
}
|
|
|
386 |
return $sql;
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
|
938 |
jpm |
390 |
private function construireWhereNomTaxon() {
|
|
|
391 |
$sql = '';
|
940 |
jpm |
392 |
list($type, $nom) = $this->decomposerParametreTaxon();
|
|
|
393 |
if (!$this->etreNull($nom)) {
|
938 |
jpm |
394 |
$nom = $this->proteger($nom.'%');
|
|
|
395 |
switch ($type) {
|
|
|
396 |
case '*' :
|
|
|
397 |
$sql = " AND (nom_ret LIKE $nom OR nom_sel LIKE $nom OR famille LIKE $nom) ";
|
|
|
398 |
break;
|
940 |
jpm |
399 |
case 'retenu' :
|
938 |
jpm |
400 |
$sql = " AND nom_ret LIKE $nom ";
|
|
|
401 |
break;
|
940 |
jpm |
402 |
case 'selectionne' :
|
938 |
jpm |
403 |
$sql = " AND nom_sel LIKE $nom ";
|
|
|
404 |
break;
|
940 |
jpm |
405 |
case 'famille' :
|
938 |
jpm |
406 |
$sql = " AND famille LIKE $nom ";
|
|
|
407 |
break;
|
|
|
408 |
default:
|
|
|
409 |
$sql = " AND nom_ret LIKE $nom ";
|
|
|
410 |
}
|
|
|
411 |
}
|
|
|
412 |
return $sql;
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
private function construireWhereDate() {
|
|
|
416 |
$sql = '';
|
|
|
417 |
// Récupération des coordonnées depuis l'id station
|
940 |
jpm |
418 |
list($type, $date) = $this->decomposerParametreDate();
|
|
|
419 |
|
938 |
jpm |
420 |
if (!$this->etreNull($date)) {
|
|
|
421 |
$date = $this->proteger($date.'%');
|
|
|
422 |
switch ($type) {
|
|
|
423 |
case '*' :
|
|
|
424 |
$sql = " AND (
|
|
|
425 |
date_observation LIKE $date
|
|
|
426 |
OR date_creation LIKE $date
|
|
|
427 |
OR date_modification LIKE $date
|
|
|
428 |
OR date_transmission LIKE $date) ";
|
|
|
429 |
break;
|
|
|
430 |
case 'observation' :
|
|
|
431 |
$sql = " AND date_observation LIKE $date ";
|
|
|
432 |
break;
|
|
|
433 |
case 'creation' :
|
|
|
434 |
$sql = " AND date_creation LIKE $date ";
|
|
|
435 |
break;
|
|
|
436 |
case 'modification' :
|
|
|
437 |
$sql = " AND date_modification LIKE $date ";
|
|
|
438 |
break;
|
|
|
439 |
case 'transmission' :
|
|
|
440 |
$sql = " AND date_transmission LIKE $date ";
|
|
|
441 |
break;
|
940 |
jpm |
442 |
case 'photo' :
|
|
|
443 |
$sql = $this->obtenirConditionPourDatePhoto($date);
|
|
|
444 |
break;
|
|
|
445 |
case 'ajout' :
|
|
|
446 |
$sql = $this->obtenirConditionPourDateAjout($date);
|
|
|
447 |
break;
|
938 |
jpm |
448 |
case 'liaison' :
|
940 |
jpm |
449 |
$sql = $this->obtenirConditionPourDateLiaison($date);
|
938 |
jpm |
450 |
break;
|
|
|
451 |
default:
|
|
|
452 |
$sql = " AND date_observation LIKE $date ";
|
|
|
453 |
}
|
|
|
454 |
}
|
|
|
455 |
return $sql;
|
|
|
456 |
}
|
|
|
457 |
|
940 |
jpm |
458 |
private function obtenirConditionPourDatePhoto($date) {
|
|
|
459 |
$observations = $this->obtenirObsLieesImg('date.photo', $date);
|
|
|
460 |
if (is_null($observations)) {
|
|
|
461 |
$this->debug[] = "Aucune observation n'est liée à une photo prise à la date : $date";
|
|
|
462 |
}
|
|
|
463 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
464 |
return $sql;
|
|
|
465 |
}
|
|
|
466 |
|
|
|
467 |
private function obtenirConditionPourDateLiaison($date) {
|
|
|
468 |
$observations = $this->obtenirObsLieesImg('date.liaison', $date);
|
|
|
469 |
if (is_null($observations)) {
|
|
|
470 |
$this->debug[] = "Aucune observation n'a été liée à une image à à la date : $date";
|
|
|
471 |
}
|
|
|
472 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
473 |
return $sql;
|
|
|
474 |
}
|
|
|
475 |
|
|
|
476 |
private function obtenirConditionPourDateAjout($date) {
|
|
|
477 |
$observations = $this->obtenirObsLieesImg('date.ajout', $date);
|
|
|
478 |
if (is_null($observations)) {
|
|
|
479 |
$this->debug[] = "Aucune observation n'est liée à une image ajoutée à la date : $date";
|
|
|
480 |
}
|
|
|
481 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
482 |
return $sql;
|
|
|
483 |
}
|
|
|
484 |
|
|
|
485 |
private function obtenirConditionPourCommentaireMeta($commentaire) {
|
|
|
486 |
$observations = $this->obtenirObsLieesImg('commentaire.meta', $commentaire);
|
|
|
487 |
if (is_null($observations)) {
|
|
|
488 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des méta-données correspond à : $commmentaire";
|
|
|
489 |
}
|
|
|
490 |
$operateur = '';
|
|
|
491 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
492 |
return $sql;
|
|
|
493 |
}
|
|
|
494 |
|
|
|
495 |
private function obtenirConditionPourCommentaireUtilisateur($commentaire) {
|
|
|
496 |
$observations = $this->obtenirObsLieesImg('commentaire.utilisateur', $commentaire);
|
|
|
497 |
if (is_null($observations)) {
|
|
|
498 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des utilisateur correspond à : $commmentaire";
|
|
|
499 |
}
|
|
|
500 |
$operateur = '';
|
|
|
501 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
502 |
return $sql;
|
|
|
503 |
}
|
|
|
504 |
|
|
|
505 |
private function obtenirConditionPourCommentaires($commentaire) {
|
|
|
506 |
$observations = $this->obtenirObsLieesImg('commentaire.*', $commentaire);
|
|
|
507 |
if (is_null($observations)) {
|
|
|
508 |
$this->debug[] = "Aucune observation n'est liée à une image dont un des commentaires correspond à : $commmentaire";
|
|
|
509 |
}
|
|
|
510 |
$operateur = '';
|
|
|
511 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
512 |
return $sql;
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
/**
|
|
|
516 |
* Récupération des identifiant d'utilisateur et des ordres des observations correspondant à une date.
|
|
|
517 |
* Retour sous forme de tableau : array[identifiant] = array(ordre, ordre...);
|
|
|
518 |
*/
|
|
|
519 |
private function obtenirObsLieesImg($type, $param) {
|
|
|
520 |
// Construction de la requête
|
|
|
521 |
$requete = 'SELECT DISTINCT coi_ce_observation AS ordre, coi_ce_utilisateur AS utilisateur '.
|
|
|
522 |
'FROM cel_images '.
|
|
|
523 |
' LEFT JOIN cel_obs_images '.
|
|
|
524 |
' ON (ci_id_image = coi_ce_image) '.
|
|
|
525 |
' LEFT JOIN cel_inventory AS i '.
|
|
|
526 |
' ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
|
|
|
527 |
' LEFT JOIN locations AS l '.
|
|
|
528 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
|
|
529 |
"WHERE transmission = '1' ".
|
|
|
530 |
($type == 'date.photo' ? " AND (ci_meta_date_time LIKE ".str_replace('-', ':', $param)." OR ci_meta_date LIKE $param) " : '').
|
|
|
531 |
($type == 'date.ajout' ? " AND ci_meta_date_ajout LIKE $param " : '').
|
|
|
532 |
($type == 'date.liaison' ? " AND coi_date_liaison LIKE $param " : '').
|
|
|
533 |
($type == 'commentaire.meta' ? " AND ci_meta_comment LIKE $param " : '').
|
|
|
534 |
($type == 'commentaire.utilisateur' ? " AND ci_meta_user_comment LIKE $param " : '').
|
|
|
535 |
($type == 'commentaire.*' ? " AND (ci_meta_comment LIKE $param OR ci_meta_user_comment LIKE $param) " : '').
|
|
|
536 |
$this->construireWhereCoordonnees().
|
|
|
537 |
$this->construireWhereDept().
|
|
|
538 |
$this->construireWhereCommune().
|
|
|
539 |
$this->construireWhereUtilisateur().
|
|
|
540 |
$this->construireWhereNumTaxon().
|
|
|
541 |
$this->construireWhereNomTaxon().
|
|
|
542 |
$this->construireWhereProjet().
|
|
|
543 |
$this->construireWhereTag().
|
|
|
544 |
'ORDER BY utilisateur ASC, ordre ASC';
|
|
|
545 |
//$this->debug[] = $requete;
|
|
|
546 |
//die($requete);
|
|
|
547 |
$resultats = $this->executerRequete($requete);
|
|
|
548 |
|
|
|
549 |
$observations = null;
|
|
|
550 |
if ($resultats != false) {
|
|
|
551 |
$observations = array();
|
|
|
552 |
foreach ($resultats as $occurence) {
|
|
|
553 |
$utilisateur = $occurence['utilisateur'];
|
|
|
554 |
$ordre = $occurence['ordre'];
|
|
|
555 |
if (!array_key_exists($utilisateur, $observations)) {
|
|
|
556 |
$observations[$utilisateur] = array();
|
|
|
557 |
}
|
|
|
558 |
if (!array_key_exists($ordre, $observations[$utilisateur])) {
|
|
|
559 |
$observations[$utilisateur][$ordre] = $ordre;
|
|
|
560 |
}
|
|
|
561 |
}
|
|
|
562 |
}
|
|
|
563 |
return $observations;
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
private function assemblerObsEnConditionSql($observations, $operateur = 'AND') {
|
|
|
567 |
$sql = '';
|
|
|
568 |
if ($observations != null) {
|
|
|
569 |
// Pré-construction du where de la requête
|
|
|
570 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
|
|
571 |
foreach ($observations as $utilisateur => $ordres) {
|
|
|
572 |
$morceaux_requete[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
|
|
573 |
}
|
|
|
574 |
if (count($morceaux_requete) > 0) {
|
|
|
575 |
$sql = implode(" \nOR ", $morceaux_requete);
|
|
|
576 |
}
|
|
|
577 |
} else {
|
|
|
578 |
// Nous voulons que la requête ne retourne rien
|
|
|
579 |
$sql = "identifiant = '' AND ordre = ''";
|
|
|
580 |
}
|
|
|
581 |
$sql = " $operateur ($sql) ";
|
|
|
582 |
return $sql;
|
|
|
583 |
}
|
|
|
584 |
|
938 |
jpm |
585 |
private function construireWhereDept() {
|
|
|
586 |
$sql = '';
|
|
|
587 |
// Récupération des coordonnées depuis l'id station
|
|
|
588 |
extract($this->parametres);
|
|
|
589 |
if (!$this->etreNull($dept)) {
|
|
|
590 |
$dept = $this->traiterValeursMultiples($dept);
|
|
|
591 |
$sql = " AND code IN ($dept) ";
|
|
|
592 |
}
|
|
|
593 |
return $sql;
|
|
|
594 |
}
|
|
|
595 |
|
|
|
596 |
private function construireWhereCommune() {
|
|
|
597 |
$sql = '';
|
|
|
598 |
// Récupération des coordonnées depuis l'id station
|
|
|
599 |
extract($this->parametres);
|
|
|
600 |
if (!$this->etreNull($commune)) {
|
|
|
601 |
$commune = $this->proteger($commune);
|
|
|
602 |
$sql = " AND location LIKE $commune ";
|
|
|
603 |
}
|
|
|
604 |
return $sql;
|
|
|
605 |
}
|
|
|
606 |
|
|
|
607 |
|
|
|
608 |
private function construireWhereUtilisateur() {
|
|
|
609 |
$sql = '';
|
|
|
610 |
// Récupération des coordonnées depuis l'id station
|
|
|
611 |
extract($this->parametres);
|
|
|
612 |
if (!$this->etreNull($utilisateur)) {
|
|
|
613 |
$utilisateur = $this->proteger($utilisateur);
|
|
|
614 |
$sql = " AND identifiant = $utilisateur ";
|
|
|
615 |
}
|
|
|
616 |
return $sql;
|
|
|
617 |
}
|
|
|
618 |
|
|
|
619 |
private function construireWhereNumTaxon() {
|
|
|
620 |
$sql = '';
|
|
|
621 |
// Récupération des coordonnées depuis l'id station
|
|
|
622 |
extract($this->parametres);
|
|
|
623 |
if (!$this->etreNull($num_taxon)) {
|
|
|
624 |
$num_taxon = $this->proteger($num_taxon);
|
|
|
625 |
$sql = " AND num_taxon = $num_taxon ";
|
|
|
626 |
}
|
|
|
627 |
return $sql;
|
|
|
628 |
}
|
|
|
629 |
|
|
|
630 |
private function construireWhereProjet() {
|
|
|
631 |
$sql = '';
|
|
|
632 |
// Récupération des coordonnées depuis l'id station
|
|
|
633 |
extract($this->parametres);
|
|
|
634 |
$projet_sql = $this->getSqlWhereProjet($projet);
|
|
|
635 |
if (!$this->etreNull($projet_sql)) {
|
|
|
636 |
$sql = " AND ($projet_sql) ";
|
|
|
637 |
}
|
|
|
638 |
return $sql;
|
|
|
639 |
}
|
|
|
640 |
|
840 |
jpm |
641 |
/**
|
938 |
jpm |
642 |
* Traitement de $projet pour construction du filtre dans la requête
|
478 |
jpm |
643 |
*/
|
938 |
jpm |
644 |
private function getSqlWhereProjet($projet) {
|
|
|
645 |
$sql = null;
|
|
|
646 |
if (! $this->etreNull($projet)) {
|
|
|
647 |
$mot_cle_encode = $this->bdd->quote($this->encoderMotCle($projet));
|
|
|
648 |
|
|
|
649 |
// Construction de la requête
|
|
|
650 |
$requete = 'SELECT * '.
|
|
|
651 |
'FROM cel_mots_cles_obs '.
|
|
|
652 |
"WHERE cmc_id_mot_cle_general = $mot_cle_encode ";
|
|
|
653 |
$elements_projet = $this->executerRequete($requete);
|
|
|
654 |
|
|
|
655 |
$requete_projet = array();
|
|
|
656 |
if ($elements_projet != false && count($elements_projet) > 0) {
|
|
|
657 |
// Pré-construction du where de la requête
|
|
|
658 |
$tpl_where = '(mots_cles LIKE "%%%s%%" AND identifiant = %s )';
|
|
|
659 |
|
|
|
660 |
foreach ($elements_projet as $occurence) {
|
|
|
661 |
$requete_projet[] = sprintf($tpl_where, $occurence['cmc_id_mot_cle_utilisateur'], $this->bdd->quote($occurence['cmc_id_proprietaire']));
|
|
|
662 |
}
|
|
|
663 |
} else {
|
|
|
664 |
$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
|
|
|
665 |
}
|
|
|
666 |
if (count($requete_projet) > 0) {
|
|
|
667 |
$sql = implode(" \nOR ", $requete_projet);
|
|
|
668 |
}
|
|
|
669 |
}
|
|
|
670 |
return $sql;
|
|
|
671 |
}
|
|
|
672 |
|
|
|
673 |
private function construireWhereTag() {
|
|
|
674 |
$sql = '';
|
|
|
675 |
// Récupération des coordonnées depuis l'id station
|
840 |
jpm |
676 |
extract($this->parametres);
|
938 |
jpm |
677 |
$tag_sql = $this->getSqlWhereObsAvecImagesTaguees($tag);
|
|
|
678 |
if (!$this->etreNull($tag_sql)) {
|
|
|
679 |
$sql = " AND ($tag_sql) ";
|
489 |
jpm |
680 |
}
|
938 |
jpm |
681 |
return $sql;
|
|
|
682 |
}
|
|
|
683 |
|
|
|
684 |
/**
|
|
|
685 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
686 |
*/
|
|
|
687 |
private function getSqlWhereObsAvecImagesTaguees($tag) {
|
|
|
688 |
$sql = null;
|
|
|
689 |
if (! $this->etreNull($tag)) {
|
|
|
690 |
$tag_sql = $this->getSqlWhereMotsCles($tag);
|
|
|
691 |
// Construction de la requête
|
|
|
692 |
$requete = 'SELECT DISTINCT coi_ce_observation AS ordre, coi_ce_utilisateur AS utilisateur '.
|
|
|
693 |
'FROM cel_images '.
|
|
|
694 |
' LEFT JOIN cel_obs_images '.
|
|
|
695 |
' ON (ci_id_image = coi_ce_image) '.
|
|
|
696 |
' LEFT JOIN cel_inventory AS i '.
|
|
|
697 |
' ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
|
|
|
698 |
' LEFT JOIN locations AS l '.
|
|
|
699 |
" ON (l.name = i.location AND l.code = i.id_location) ".
|
|
|
700 |
"WHERE transmission = '1' ".
|
|
|
701 |
$this->construireWhereCoordonnees().
|
|
|
702 |
$this->construireWhereUtilisateur().
|
|
|
703 |
$this->construireWhereNumTaxon().
|
|
|
704 |
$this->construireWhereNomTaxon().
|
|
|
705 |
$this->construireWhereProjet().
|
|
|
706 |
(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
|
|
|
707 |
'ORDER BY utilisateur ASC, ordre ASC';
|
|
|
708 |
//$this->debug[] = $requete;
|
|
|
709 |
//die($requete);
|
|
|
710 |
$elements_tag = $this->executerRequete($requete);
|
|
|
711 |
|
|
|
712 |
$requete_tag = array();
|
|
|
713 |
if ($elements_tag != false && count($elements_tag) > 0) {
|
|
|
714 |
|
|
|
715 |
$filtres = array();
|
|
|
716 |
foreach ($elements_tag as $occurence) {
|
|
|
717 |
$utilisateur = $occurence['utilisateur'];
|
|
|
718 |
$ordre = $occurence['ordre'];
|
|
|
719 |
if (!array_key_exists($utilisateur, $filtres)) {
|
|
|
720 |
$filtres[$utilisateur] = array();
|
|
|
721 |
}
|
|
|
722 |
if (!array_key_exists($ordre, $filtres[$utilisateur])) {
|
|
|
723 |
$filtres[$utilisateur][$ordre] = $ordre;
|
|
|
724 |
}
|
|
|
725 |
}
|
|
|
726 |
|
|
|
727 |
// Pré-construction du where de la requête
|
|
|
728 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
|
|
729 |
foreach ($filtres as $utilisateur => $ordres) {
|
|
|
730 |
$requete_tag[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
|
|
731 |
}
|
|
|
732 |
|
|
|
733 |
} else {
|
|
|
734 |
$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
|
|
|
735 |
}
|
|
|
736 |
if (count($requete_tag) > 0) {
|
|
|
737 |
$sql = implode(" \nOR ", $requete_tag);
|
|
|
738 |
}
|
489 |
jpm |
739 |
}
|
938 |
jpm |
740 |
return $sql;
|
478 |
jpm |
741 |
}
|
|
|
742 |
|
487 |
jpm |
743 |
/**
|
938 |
jpm |
744 |
* Traitement de $tag pour construction du filtre dans la requête
|
487 |
jpm |
745 |
*/
|
938 |
jpm |
746 |
private function getSqlWhereMotsCles($tag) {
|
|
|
747 |
$sql = null;
|
940 |
jpm |
748 |
$mots_cles = $this->decomposerParametreTag($tag);
|
487 |
jpm |
749 |
|
|
|
750 |
// Construction de la requête
|
938 |
jpm |
751 |
$requete = 'SELECT cmc_id_proprietaire AS utilisateur, cmc_id_mot_cle_general AS mot_cle_general, '.
|
|
|
752 |
' cmc_id_mot_cle_utilisateur AS mot_cle_utilisateur '.
|
|
|
753 |
'FROM cel_mots_cles_images '.
|
|
|
754 |
'WHERE '.$this->getSqlWhereMotsClesImages($mots_cles['motsClesEncodesProteges']);
|
487 |
jpm |
755 |
$elements_projet = $this->executerRequete($requete);
|
938 |
jpm |
756 |
//$this->debug[] = $requete;
|
487 |
jpm |
757 |
|
|
|
758 |
$requete_projet = array();
|
|
|
759 |
if ($elements_projet != false && count($elements_projet) > 0) {
|
|
|
760 |
// Pré-construction du where de la requête
|
938 |
jpm |
761 |
if ($mots_cles['type'] == 'OR') {
|
|
|
762 |
$tpl_where = '(ci_meta_mots_cles LIKE "%%%s,%%" AND ci_ce_utilisateur = %s )';
|
|
|
763 |
foreach ($elements_projet as $occurence) {
|
|
|
764 |
$requete_projet[] = sprintf($tpl_where, $occurence['mot_cle_utilisateur'], $this->bdd->quote($occurence['utilisateur']));
|
|
|
765 |
}
|
|
|
766 |
} else {
|
|
|
767 |
$tpl_where_mc = "ci_meta_mots_cles LIKE '%%%s,%%'";
|
|
|
768 |
$tpl_where = '((%s) AND ci_ce_utilisateur = %s)';
|
|
|
769 |
$utilisateur_mc = array();
|
|
|
770 |
foreach ($elements_projet as $occurence) {
|
|
|
771 |
if (!isset($utilisateur_mc[$occurence['utilisateur']][$occurence['mot_cle_general']])) {
|
|
|
772 |
$utilisateur_mc[$occurence['utilisateur']][$occurence['mot_cle_general']] = $occurence['mot_cle_utilisateur'];
|
|
|
773 |
}
|
|
|
774 |
}
|
|
|
775 |
|
|
|
776 |
foreach ($utilisateur_mc as $utilisateur => $mots_cles_utilisateur) {
|
|
|
777 |
if (count($mots_cles_utilisateur) == count($mots_cles['motsCles'])) {
|
|
|
778 |
$where_mots_cles_utilisateur = array();
|
|
|
779 |
foreach ($mots_cles_utilisateur as $mot_cle) {
|
|
|
780 |
$where_mots_cles_utilisateur[] = sprintf($tpl_where_mc, $mot_cle);
|
|
|
781 |
}
|
|
|
782 |
$where_mots_cles_utilisateur = implode(' AND ', $where_mots_cles_utilisateur);
|
|
|
783 |
$utilisateur = $this->bdd->quote($utilisateur);
|
|
|
784 |
$requete_projet[] = sprintf($tpl_where, $where_mots_cles_utilisateur, $utilisateur);
|
|
|
785 |
}
|
|
|
786 |
}
|
487 |
jpm |
787 |
}
|
|
|
788 |
} else {
|
|
|
789 |
$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
|
|
|
790 |
}
|
|
|
791 |
|
|
|
792 |
$sql = implode(" \nOR ", $requete_projet);
|
938 |
jpm |
793 |
//$this->debug[] = $sql;
|
487 |
jpm |
794 |
return $sql;
|
840 |
jpm |
795 |
}
|
938 |
jpm |
796 |
|
|
|
797 |
/**
|
|
|
798 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
799 |
*/
|
|
|
800 |
private function getSqlWhereMotsClesImages($mots_cles_encodes) {
|
|
|
801 |
$where_mots_cles_images = array();
|
|
|
802 |
foreach ($mots_cles_encodes as $mot_cle_encode) {
|
|
|
803 |
$where_mots_cles_images[] = "cmc_id_mot_cle_general = $mot_cle_encode";
|
|
|
804 |
}
|
|
|
805 |
$where_mots_cles_images = implode(' OR ', $where_mots_cles_images);
|
|
|
806 |
return $where_mots_cles_images;
|
|
|
807 |
}
|
|
|
808 |
|
940 |
jpm |
809 |
private function decomposerParametreTag($tags) {
|
938 |
jpm |
810 |
$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
|
|
|
811 |
if (preg_match('/.+OU.+/', $tags)) {
|
|
|
812 |
$mots_cles['type'] = 'OR';
|
|
|
813 |
$mots_cles['motsCles'] = explode('OU', $tags);
|
|
|
814 |
} else if (preg_match('/.+ET.+/', $tags)) {
|
|
|
815 |
$mots_cles['type'] = 'AND';
|
|
|
816 |
$mots_cles['motsCles'] = explode('ET', $tags);
|
|
|
817 |
} else {
|
|
|
818 |
$mots_cles['motsCles'][] = $tags;
|
|
|
819 |
}
|
|
|
820 |
|
|
|
821 |
foreach ($mots_cles['motsCles'] as $mot) {
|
|
|
822 |
$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote($this->encoderMotCle($mot));
|
|
|
823 |
}
|
|
|
824 |
$this->debug[] = $mots_cles;
|
|
|
825 |
return $mots_cles;
|
|
|
826 |
}
|
|
|
827 |
|
940 |
jpm |
828 |
private function decomposerParametreStation() {
|
938 |
jpm |
829 |
$station_infos = array();
|
|
|
830 |
if (isset($this->parametres['station'])) {
|
|
|
831 |
$station = $this->parametres['station'];
|
|
|
832 |
$this->debug[] = $station;
|
|
|
833 |
list($type, $coord) = explode(':', $station);
|
954 |
jpm |
834 |
list($lat, $lng) = explode('-', $coord);
|
938 |
jpm |
835 |
|
954 |
jpm |
836 |
$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
|
938 |
jpm |
837 |
}
|
|
|
838 |
return $station_infos;
|
|
|
839 |
}
|
940 |
jpm |
840 |
|
|
|
841 |
private function decomposerParametreDate() {
|
|
|
842 |
$date_infos = array();
|
|
|
843 |
if (isset($this->parametres['date'])) {
|
|
|
844 |
$date = $this->parametres['date'];
|
|
|
845 |
if (strpos($date, ':')) {
|
|
|
846 |
list($type, $date) = explode(':', $date);
|
|
|
847 |
} else {
|
|
|
848 |
$type = 'observation';
|
|
|
849 |
}
|
|
|
850 |
|
|
|
851 |
$date = str_replace('/', '-', $date);
|
|
|
852 |
if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $date, $matches)) {
|
|
|
853 |
$date = $matches[3].'-'.$matches[2].'-'.$matches[1];
|
|
|
854 |
}
|
|
|
855 |
|
|
|
856 |
$date_infos = array($type, $date);
|
|
|
857 |
}
|
|
|
858 |
return $date_infos;
|
|
|
859 |
}
|
|
|
860 |
|
|
|
861 |
private function decomposerParametreTaxon() {
|
|
|
862 |
$nom_infos = array();
|
|
|
863 |
if (isset($this->parametres['taxon'])) {
|
|
|
864 |
$taxon = $this->parametres['taxon'];
|
|
|
865 |
if (strpos($taxon, ':')) {
|
|
|
866 |
$nom_infos = explode(':', $taxon);
|
|
|
867 |
} else {
|
|
|
868 |
$nom_infos = array('retenu', $taxon);
|
|
|
869 |
}
|
|
|
870 |
}
|
|
|
871 |
return $nom_infos;
|
|
|
872 |
}
|
|
|
873 |
|
|
|
874 |
private function decomposerParametreCommentaire() {
|
|
|
875 |
$commentaire_infos = array();
|
|
|
876 |
if (isset($this->parametres['commentaire'])) {
|
|
|
877 |
$commentaire = $this->parametres['commentaire'];
|
|
|
878 |
if (strpos($commentaire, ':')) {
|
|
|
879 |
$commentaire_infos = explode(':', $commentaire);
|
|
|
880 |
} else {
|
|
|
881 |
$commentaire_infos = array('observation', $commentaire);
|
|
|
882 |
}
|
|
|
883 |
}
|
|
|
884 |
return $commentaire_infos;
|
|
|
885 |
}
|
416 |
aurelien |
886 |
}
|