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