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.
|
1339 |
aurelien |
12 |
* /CelWidgetMap/Carte/Utilisateur/Projet/dept/nt : 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 '.
|
1339 |
aurelien |
98 |
'FROM cel_obs AS co '.
|
|
|
99 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
100 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
938 |
jpm |
101 |
"WHERE transmission = '1' ".
|
981 |
jpm |
102 |
" AND (( ".
|
1339 |
aurelien |
103 |
" (latitude = '' OR latitude IS NULL OR latitude = '000null') ".
|
|
|
104 |
" AND (longitude = '' OR longitude IS NULL OR longitude = '000null') ".
|
981 |
jpm |
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 |
|
1339 |
aurelien |
119 |
$requete = 'SELECT latitude AS lat, longitude AS lng, location AS nom '.
|
|
|
120 |
'FROM cel_obs AS co '.
|
|
|
121 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
122 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
981 |
jpm |
123 |
"WHERE transmission = '1' ".
|
1339 |
aurelien |
124 |
" AND latitude != '' AND latitude IS NOT NULL AND latitude != '000null' ".
|
|
|
125 |
" AND longitude != '' AND longitude IS NOT NULL AND longitude != '000null' ".
|
981 |
jpm |
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;
|
1399 |
aurelien |
147 |
$concatenation_id = "CONCAT(IFNULL(latitude,''),IFNULL(longitude,''), IFNULL(wgs84_latitude,''),IFNULL(wgs84_longitude,'')) ";
|
1092 |
aurelien |
148 |
|
1339 |
aurelien |
149 |
$requete = 'SELECT DISTINCT *, zone_geo AS nom, '.
|
1148 |
aurelien |
150 |
"mots_cles_texte, ".
|
1339 |
aurelien |
151 |
"latitude, ".
|
1148 |
aurelien |
152 |
"wgs84_latitude, ".
|
1339 |
aurelien |
153 |
"longitude, ".
|
1148 |
aurelien |
154 |
"wgs84_longitude, ".
|
|
|
155 |
$concatenation_id." as id_coord ".
|
1339 |
aurelien |
156 |
'FROM cel_obs AS co '.
|
|
|
157 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
158 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
981 |
jpm |
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';
|
1339 |
aurelien |
172 |
//echo $requete;exit;
|
1106 |
aurelien |
173 |
$resultats_emplacements = $this->executerRequete($requete);
|
|
|
174 |
$emplacements = $this->traiterEmplacements($resultats_emplacements, $this->compterObservations($params));
|
|
|
175 |
return $emplacements;
|
981 |
jpm |
176 |
}
|
1092 |
aurelien |
177 |
|
|
|
178 |
private function afficherRequeteFormatee($requete) {
|
|
|
179 |
$requete = str_replace(')',')<br />',$requete);
|
|
|
180 |
$requete = str_replace('(',' <br /> (',$requete);
|
|
|
181 |
echo '<pre>'.$requete.'</pre>';
|
|
|
182 |
exit;
|
|
|
183 |
}
|
1003 |
jpm |
184 |
|
1039 |
aurelien |
185 |
private $nb_obs = 0;
|
|
|
186 |
|
|
|
187 |
private function compterObservations($params) {
|
1172 |
aurelien |
188 |
$requete = 'SELECT COUNT(*) as nb '.
|
1339 |
aurelien |
189 |
'FROM cel_obs AS co '.
|
|
|
190 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
191 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
1039 |
aurelien |
192 |
"WHERE transmission = '1' ".
|
1172 |
aurelien |
193 |
" AND (".
|
|
|
194 |
$this->construireWhereRectangleStationOR()." OR ".
|
|
|
195 |
$this->construireWhereRectangleCommuneOR().") ".
|
1039 |
aurelien |
196 |
$this->construireWhereDept().
|
|
|
197 |
$this->construireWhereCommune().
|
|
|
198 |
$this->construireWhereUtilisateur().
|
|
|
199 |
$this->construireWhereNumTaxon().
|
|
|
200 |
$this->construireWhereNomTaxon().
|
|
|
201 |
$this->construireWhereDate().
|
|
|
202 |
$this->construireWhereCommentaire().
|
|
|
203 |
$this->construireWhereProjet().
|
|
|
204 |
$this->construireWhereTag();
|
1339 |
aurelien |
205 |
//echo $requete;exit;
|
1039 |
aurelien |
206 |
$resultats_nb_obs = $this->executerRequete($requete);
|
|
|
207 |
return $resultats_nb_obs[0]['nb'];
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
private function traiterEmplacements(&$emplacements, $nb_total_observation) {
|
981 |
jpm |
211 |
$zoom = (int) array_key_exists('zoom', $this->parametres) ? $this->parametres['zoom'] : 11;
|
|
|
212 |
$distance = (int) array_key_exists('distance', $this->parametres) ? $this->parametres['distance'] : 20;
|
1003 |
jpm |
213 |
|
981 |
jpm |
214 |
$marqueurs = array(
|
|
|
215 |
'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
|
|
|
216 |
'points' => null
|
|
|
217 |
);
|
1003 |
jpm |
218 |
|
1132 |
aurelien |
219 |
if (isset($this->parametres['ne']) && $this->parametres['sw'] && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
220 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
221 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
|
|
222 |
$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree($emplacements, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
|
1003 |
jpm |
223 |
|
|
|
224 |
// laisser la classe cartoGroupage compter les élements simplifie le comptage
|
982 |
jpm |
225 |
// et permet de ne pas reparser le tableau pour compter les différents éléments
|
981 |
jpm |
226 |
$nb_elements = CartoGroupage::getNbElements();
|
1148 |
aurelien |
227 |
// les bornes servent à centrer la carte dans le cas ou l'on demande des paramètres précis
|
1106 |
aurelien |
228 |
$marqueurs['stats']['coordmax'] = CartoGroupage::getBornes();
|
981 |
jpm |
229 |
$marqueurs['stats']['stations'] = $nb_elements['stations'];
|
|
|
230 |
$marqueurs['stats']['communes'] = $nb_elements['communes'];
|
1039 |
aurelien |
231 |
$marqueurs['stats']['observations'] = (int)$nb_total_observation;
|
981 |
jpm |
232 |
} else {
|
|
|
233 |
$marqueurs['points'] = $emplacements;
|
938 |
jpm |
234 |
}
|
981 |
jpm |
235 |
|
|
|
236 |
return $marqueurs;
|
938 |
jpm |
237 |
}
|
1003 |
jpm |
238 |
|
981 |
jpm |
239 |
private function traiterStations($communes, $stations) {
|
|
|
240 |
$zoom = (int) array_key_exists('zoom', $this->parametres) ? $this->parametres['zoom'] : 11;
|
|
|
241 |
$distance = (int) array_key_exists('distance', $this->parametres) ? $this->parametres['distance'] : 20;
|
1003 |
jpm |
242 |
|
981 |
jpm |
243 |
$marqueurs = array(
|
954 |
jpm |
244 |
'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
|
|
|
245 |
'points' => null
|
|
|
246 |
);
|
981 |
jpm |
247 |
$marqueurs['stats']['observations'] = $this->traiterNbreObs($communes) + $this->traiterNbreObs($stations);
|
1003 |
jpm |
248 |
|
954 |
jpm |
249 |
$points = array();
|
981 |
jpm |
250 |
if ($communes !== false) {
|
|
|
251 |
foreach ($communes as $commune) {
|
|
|
252 |
if (is_numeric($commune['lat']) && is_numeric($commune['lng'])) {
|
|
|
253 |
extract($commune);
|
|
|
254 |
$id = self::MARQUEUR_COMMUNE.':'.$lat.'|'.$lng;
|
|
|
255 |
$lata = round($lat, 5);
|
|
|
256 |
$lnga = round($lng, 5);
|
1003 |
jpm |
257 |
|
954 |
jpm |
258 |
if (!isset($points[$id])) {
|
981 |
jpm |
259 |
$points[$id]['id'] = $id;
|
|
|
260 |
$points[$id]['nom'] = $nom;
|
|
|
261 |
$points[$id]['lat'] = $lata;
|
|
|
262 |
$points[$id]['lng'] = $lnga;
|
954 |
jpm |
263 |
$points[$id]['nbre'] = 1;
|
981 |
jpm |
264 |
$marqueurs['stats']['communes']++;
|
840 |
jpm |
265 |
} else {
|
954 |
jpm |
266 |
$points[$id]['nbre']++;
|
840 |
jpm |
267 |
}
|
981 |
jpm |
268 |
}
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
if ($stations !== false) {
|
|
|
272 |
foreach ($stations as $station) {
|
|
|
273 |
if (is_numeric($station['lat']) && is_numeric($station['lng'])) {
|
|
|
274 |
extract($station);
|
|
|
275 |
$id = self::MARQUEUR_STATION.':'.$lat.'|'.$lng;
|
|
|
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'])) {
|
1339 |
aurelien |
369 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS id_observation, ce_utilisateur, courriel_utilisateur, nom_utilisateur, prenom_utilisateur, '.
|
|
|
370 |
' nom_sel, nom_ret, nom_sel_nn, nom_ret_nn, nt, famille, '.
|
|
|
371 |
' lieudit, zone_geo, date_observation, milieu, commentaire, '.
|
|
|
372 |
' utm_secteur, utm_x, utm_y, code, date_transmission '.
|
|
|
373 |
'FROM cel_obs AS co '.
|
|
|
374 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
375 |
" ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) ".
|
938 |
jpm |
376 |
"WHERE transmission = '1' ".
|
1165 |
aurelien |
377 |
(($this->communeEstDemandee()) ? $this->construireWhereCommuneSansCoordonneesAvecSensibles() : $this->construireWhereCoordonneesSansSensibles()).
|
1148 |
aurelien |
378 |
$this->construireWhereDept().
|
938 |
jpm |
379 |
$this->construireWhereUtilisateur().
|
|
|
380 |
$this->construireWhereNumTaxon().
|
|
|
381 |
$this->construireWhereNomTaxon().
|
|
|
382 |
$this->construireWhereDate().
|
940 |
jpm |
383 |
$this->construireWhereCommentaire().
|
938 |
jpm |
384 |
$this->construireWhereProjet().
|
|
|
385 |
$this->construireWhereTag().
|
|
|
386 |
'ORDER BY nom_sel ASC '.
|
|
|
387 |
"LIMIT {$this->start},{$this->limit} ";
|
1339 |
aurelien |
388 |
//echo $requete;exit;
|
938 |
jpm |
389 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
|
|
390 |
$requete = 'SELECT FOUND_ROWS()';
|
|
|
391 |
$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
|
474 |
jpm |
392 |
}
|
1003 |
jpm |
393 |
|
474 |
jpm |
394 |
// Post-traitement
|
938 |
jpm |
395 |
$observations = $this->traiterObservations($resultats, $total);
|
1039 |
aurelien |
396 |
$observations = $this->ajouterImagesAuxObs($observations);
|
|
|
397 |
$observations = $this->ajouterAuteursAuxObs($observations);
|
938 |
jpm |
398 |
$observations = $this->supprimerIdDesObs($observations);
|
1003 |
jpm |
399 |
|
938 |
jpm |
400 |
return $observations;
|
|
|
401 |
}
|
1003 |
jpm |
402 |
|
938 |
jpm |
403 |
private function traiterObservations($donnees, $total) {
|
|
|
404 |
$observations = array('commune' => '', 'observations' => array(), 'observateurs' => array());
|
|
|
405 |
$observations['total'] = (isset($total)) ? $total : 0;
|
|
|
406 |
if (is_array($donnees) && count($donnees) > 0) {
|
|
|
407 |
foreach ($donnees as $donnee) {
|
1339 |
aurelien |
408 |
//echo '<pre>'.print_r($donnee,true).'</pre>';exit;
|
938 |
jpm |
409 |
$observation = array();
|
1339 |
aurelien |
410 |
$observation['idObs'] = $donnee->id_observation;
|
|
|
411 |
$observation['nn'] = $this->etreNull($donnee->nom_sel_nn) ? null : $donnee->nom_sel_nn;
|
938 |
jpm |
412 |
$observation['nomSci'] = $this->nettoyerTexte($donnee->nom_sel);
|
1411 |
aurelien |
413 |
$observation['date'] = ($donnee->date_observation != '0000-00-00 00:00:00') ? $this->formaterDate($donnee->date_observation, '%d/%m/%Y') : '';
|
938 |
jpm |
414 |
$observation['datePubli'] = $this->formaterDate($donnee->date_transmission);
|
|
|
415 |
$observation['lieu'] = $this->traiterLieu($donnee);
|
1339 |
aurelien |
416 |
$observation['observateur'] = $donnee->courriel_utilisateur;
|
|
|
417 |
$observation['observateurId'] = $donnee->ce_utilisateur;
|
|
|
418 |
$observation['urlEflore'] = $this->getUrlEflore($donnee->nom_sel_nn);
|
1003 |
jpm |
419 |
|
1339 |
aurelien |
420 |
if (isset($donnee->zone_geo)) {
|
|
|
421 |
$observations['commune'] = $this->nettoyerTexte($donnee->zone_geo);
|
938 |
jpm |
422 |
}
|
1339 |
aurelien |
423 |
$observations['observations'][$donnee->id_observation] = $observation;
|
1003 |
jpm |
424 |
|
1339 |
aurelien |
425 |
if (! array_key_exists($donnee->ce_utilisateur, $observations['observateurs'])) {
|
|
|
426 |
$observations['observateurs'][$donnee->courriel_utilisateur] = $donnee->courriel_utilisateur;
|
938 |
jpm |
427 |
}
|
|
|
428 |
}
|
487 |
jpm |
429 |
}
|
938 |
jpm |
430 |
return $observations;
|
|
|
431 |
}
|
1003 |
jpm |
432 |
|
938 |
jpm |
433 |
private function getUrlEflore($nn) {
|
|
|
434 |
$urlEflore = null;
|
|
|
435 |
if (! $this->etreNull($nn)) {
|
|
|
436 |
$urlEflore = sprintf($this->config['settings']['efloreUrlTpl'], $nn, 'illustration');
|
|
|
437 |
}
|
|
|
438 |
return $urlEflore;
|
|
|
439 |
}
|
1003 |
jpm |
440 |
|
938 |
jpm |
441 |
private function traiterLieu($donnee) {
|
|
|
442 |
$lieu = array();
|
|
|
443 |
if (!$this->etreNull($donnee->lieudit)) {
|
|
|
444 |
$lieu[] = $donnee->lieudit;
|
|
|
445 |
}
|
|
|
446 |
if (!$this->etreNull($donnee->milieu)) {
|
|
|
447 |
$lieu[] = $donnee->milieu;
|
|
|
448 |
}
|
|
|
449 |
return implode(', ', $lieu);
|
|
|
450 |
}
|
1003 |
jpm |
451 |
|
938 |
jpm |
452 |
private function chargerImages(Array $obs_ids) {
|
|
|
453 |
// Récupération des données au format Json
|
|
|
454 |
$service = 'CelImage/liste-ids?obsId='.implode(',', $obs_ids);
|
|
|
455 |
$url = sprintf($this->config['settings']['baseURLServicesCelTpl'], $service);
|
|
|
456 |
$json = $this->getRestClient()->consulter($url);
|
|
|
457 |
$donnees = json_decode($json);
|
1003 |
jpm |
458 |
|
938 |
jpm |
459 |
// Post-traitement des données
|
|
|
460 |
$images = $this->traiterImages($donnees);
|
1003 |
jpm |
461 |
|
938 |
jpm |
462 |
return $images;
|
474 |
jpm |
463 |
}
|
1003 |
jpm |
464 |
|
938 |
jpm |
465 |
private function traiterImages($donnees) {
|
|
|
466 |
$images = array();
|
|
|
467 |
if (count($donnees) > 0) {
|
|
|
468 |
foreach ($donnees as $id_obs => $id_images) {
|
|
|
469 |
foreach ($id_images as $id_img) {
|
|
|
470 |
$urls['idImg'] = $id_img;
|
|
|
471 |
$urls['guid'] = sprintf($this->config['settings']['guidImgTpl'], $id_img);
|
|
|
472 |
$urls['miniature'] = $this->getUrlImage($id_img, 'CXS');
|
|
|
473 |
$urls['normale'] = $this->getUrlImage($id_img, 'XL');
|
|
|
474 |
$images[$id_obs][] = $urls;
|
1003 |
jpm |
475 |
}
|
938 |
jpm |
476 |
}
|
|
|
477 |
}
|
|
|
478 |
return $images;
|
|
|
479 |
}
|
1003 |
jpm |
480 |
|
938 |
jpm |
481 |
private function ajouterImagesAuxObs($observations) {
|
|
|
482 |
$images = $this->chargerImages(array_keys($observations['observations']));
|
|
|
483 |
foreach ($observations['observations'] as $id => $infos) {
|
1043 |
aurelien |
484 |
if(isset($images[$id])) {
|
|
|
485 |
$infos['images'] = $images[$id];
|
|
|
486 |
$observations['observations'][$id] = $infos;
|
|
|
487 |
}
|
938 |
jpm |
488 |
}
|
|
|
489 |
return $observations;
|
|
|
490 |
}
|
1339 |
aurelien |
491 |
|
938 |
jpm |
492 |
private function ajouterAuteursAuxObs($observations) {
|
944 |
jpm |
493 |
$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
|
938 |
jpm |
494 |
unset($observations['observateurs']);
|
|
|
495 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
496 |
$courriel = $infos['observateur'];
|
1339 |
aurelien |
497 |
if(isset($observateurs[$courriel])) {
|
|
|
498 |
$infos['observateur'] = $observateurs[$courriel]['intitule'];
|
|
|
499 |
$infos['observateurId'] = $observateurs[$courriel]['id'];
|
|
|
500 |
}
|
938 |
jpm |
501 |
$observations['observations'][$id] = $infos;
|
|
|
502 |
}
|
|
|
503 |
return $observations;
|
|
|
504 |
}
|
1003 |
jpm |
505 |
|
938 |
jpm |
506 |
private function supprimerIdDesObs($observations) {
|
|
|
507 |
// Le tableau de sortie ne doit pas avoir les id des obs en clé car sinon Jquery Template ne fonctionne pas
|
|
|
508 |
$observationSansId = $observations;
|
|
|
509 |
unset($observationSansId['observations']);
|
|
|
510 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
511 |
$observationSansId['observations'][] = $infos;
|
|
|
512 |
}
|
|
|
513 |
return $observationSansId;
|
|
|
514 |
}
|
1003 |
jpm |
515 |
|
478 |
jpm |
516 |
/**
|
938 |
jpm |
517 |
* Liste des taxons présents sur la carte
|
840 |
jpm |
518 |
*/
|
938 |
jpm |
519 |
public function getTaxons($params) {
|
840 |
jpm |
520 |
$json = null;
|
1003 |
jpm |
521 |
|
1339 |
aurelien |
522 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, nom_ret_nn, nt, famille '.
|
|
|
523 |
'FROM cel_obs AS co '.
|
|
|
524 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
525 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
840 |
jpm |
526 |
"WHERE transmission = '1' ".
|
938 |
jpm |
527 |
" AND nom_ret != '' ".
|
|
|
528 |
$this->construireWhereDept().
|
|
|
529 |
$this->construireWhereCommune().
|
|
|
530 |
$this->construireWhereUtilisateur().
|
|
|
531 |
$this->construireWhereNumTaxon().
|
|
|
532 |
$this->construireWhereNomTaxon().
|
|
|
533 |
$this->construireWhereDate().
|
940 |
jpm |
534 |
$this->construireWhereCommentaire().
|
938 |
jpm |
535 |
$this->construireWhereProjet().
|
981 |
jpm |
536 |
$this->construireWhereTag().
|
938 |
jpm |
537 |
'ORDER BY nom_ret ASC '.
|
|
|
538 |
"LIMIT {$this->start},{$this->limit} ";
|
|
|
539 |
//$this->debug[] = $requete;
|
|
|
540 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
1339 |
aurelien |
541 |
//echo $requete;exit;
|
938 |
jpm |
542 |
$requete = 'SELECT FOUND_ROWS()';
|
|
|
543 |
$taxons['total'] = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
|
1003 |
jpm |
544 |
|
938 |
jpm |
545 |
// Post-traitement
|
|
|
546 |
$taxons['taxons'] = $this->traiterTaxons($resultats);
|
1003 |
jpm |
547 |
|
938 |
jpm |
548 |
return $taxons;
|
840 |
jpm |
549 |
}
|
1003 |
jpm |
550 |
|
938 |
jpm |
551 |
private function traiterTaxons($donnees) {
|
|
|
552 |
$taxons = array();
|
|
|
553 |
if (is_array($donnees) && count($donnees) > 0) {
|
|
|
554 |
foreach ($donnees as $donnee) {
|
1339 |
aurelien |
555 |
if (!isset($taxons[$donnee->nt]) && ! $this->etreNull($donnee->nom_ret)) {
|
938 |
jpm |
556 |
$taxon = array();
|
1339 |
aurelien |
557 |
$taxon['nn'] = $donnee->nom_ret_nn;
|
|
|
558 |
$taxon['nt'] = $donnee->nt;
|
938 |
jpm |
559 |
$taxon['nom'] = $this->nettoyerTexte($donnee->nom_ret);
|
|
|
560 |
$taxon['famille'] = $this->nettoyerTexte($donnee->famille);
|
1339 |
aurelien |
561 |
$taxons[$donnee->nt] = $taxon;
|
938 |
jpm |
562 |
}
|
|
|
563 |
}
|
|
|
564 |
}
|
|
|
565 |
$taxons = array_values($taxons);
|
|
|
566 |
return $taxons;
|
|
|
567 |
}
|
1003 |
jpm |
568 |
|
938 |
jpm |
569 |
private function construireWhereCoordonnees() {
|
|
|
570 |
$sql = '';
|
|
|
571 |
// Récupération des coordonnées depuis l'id station
|
940 |
jpm |
572 |
extract($this->decomposerParametreStation());
|
938 |
jpm |
573 |
if (isset($type)) {
|
981 |
jpm |
574 |
if ($type == self::MARQUEUR_COMMUNE) {
|
1341 |
aurelien |
575 |
$lat = $this->proteger($lat.'%');
|
|
|
576 |
$lng = $this->proteger($lng.'%');
|
|
|
577 |
$sql = " AND wgs84_latitude LIKE $lat AND wgs84_longitude LIKE $lng ";
|
981 |
jpm |
578 |
} else if ($type == self::MARQUEUR_STATION) {
|
1339 |
aurelien |
579 |
$lat = $this->proteger($lat.'%');
|
|
|
580 |
$lng = $this->proteger($lng.'%');
|
|
|
581 |
$sql = " AND (latitude LIKE $lat AND longitude LIKE $lng) ";
|
938 |
jpm |
582 |
}
|
1003 |
jpm |
583 |
}
|
938 |
jpm |
584 |
return $sql;
|
|
|
585 |
}
|
1092 |
aurelien |
586 |
|
|
|
587 |
private function construireWhereCoordonneesSansSensibles() {
|
|
|
588 |
$sql = '(';
|
|
|
589 |
// Récupération des coordonnées depuis l'id station
|
|
|
590 |
extract($this->decomposerParametreStation());
|
|
|
591 |
if (isset($type)) {
|
|
|
592 |
if ($type == self::MARQUEUR_COMMUNE) {
|
|
|
593 |
$lat = $this->proteger($lat);
|
|
|
594 |
$lng = $this->proteger($lng);
|
1341 |
aurelien |
595 |
$sql = " AND wgs84_latitude LIKE $lat AND wgs84_longitude LIKE $lng ";
|
1092 |
aurelien |
596 |
} else if ($type == self::MARQUEUR_STATION) {
|
1339 |
aurelien |
597 |
$lat = $this->proteger($lat.'%');
|
|
|
598 |
$lng = $this->proteger($lng.'%');
|
|
|
599 |
$sql = " AND (latitude LIKE $lat AND longitude LIKE $lng) ";
|
1092 |
aurelien |
600 |
}
|
|
|
601 |
}
|
1165 |
aurelien |
602 |
$sql .= ' AND (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE "%sensible%" ) ';
|
1092 |
aurelien |
603 |
return $sql;
|
|
|
604 |
}
|
1003 |
jpm |
605 |
|
940 |
jpm |
606 |
private function construireWhereCommentaire() {
|
|
|
607 |
$sql = '';
|
|
|
608 |
list($type, $commentaire) = $this->decomposerParametreCommentaire();
|
|
|
609 |
if (!$this->etreNull($commentaire)) {
|
|
|
610 |
$commentaire = $this->proteger('%'.$commentaire.'%');
|
|
|
611 |
switch ($type) {
|
|
|
612 |
case '*' :
|
|
|
613 |
$sql = $this->obtenirConditionPourCommentaires($commentaire);
|
|
|
614 |
$sql = " AND (commentaire LIKE $commentaire OR ($sql)) ";
|
|
|
615 |
break;
|
|
|
616 |
case 'observation' :
|
|
|
617 |
$sql = " AND commentaire LIKE $commentaire ";
|
|
|
618 |
break;
|
|
|
619 |
case 'photo' :
|
|
|
620 |
$sql = ' AND '.$this->obtenirConditionPourCommentaires($commentaire).' ';
|
|
|
621 |
break;
|
|
|
622 |
case 'photo.meta' :
|
|
|
623 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireMeta($commentaire).' ';
|
|
|
624 |
break;
|
|
|
625 |
case 'photo.utilisateur' :
|
|
|
626 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireUtilisateur($commentaire).' ';
|
|
|
627 |
break;
|
|
|
628 |
default:
|
|
|
629 |
$sql = " AND commentaire LIKE $commentaire ";
|
1003 |
jpm |
630 |
}
|
940 |
jpm |
631 |
}
|
|
|
632 |
return $sql;
|
|
|
633 |
}
|
1003 |
jpm |
634 |
|
|
|
635 |
|
938 |
jpm |
636 |
private function construireWhereNomTaxon() {
|
|
|
637 |
$sql = '';
|
940 |
jpm |
638 |
list($type, $nom) = $this->decomposerParametreTaxon();
|
|
|
639 |
if (!$this->etreNull($nom)) {
|
938 |
jpm |
640 |
$nom = $this->proteger($nom.'%');
|
|
|
641 |
switch ($type) {
|
|
|
642 |
case '*' :
|
|
|
643 |
$sql = " AND (nom_ret LIKE $nom OR nom_sel LIKE $nom OR famille LIKE $nom) ";
|
|
|
644 |
break;
|
940 |
jpm |
645 |
case 'retenu' :
|
938 |
jpm |
646 |
$sql = " AND nom_ret LIKE $nom ";
|
|
|
647 |
break;
|
940 |
jpm |
648 |
case 'selectionne' :
|
938 |
jpm |
649 |
$sql = " AND nom_sel LIKE $nom ";
|
|
|
650 |
break;
|
940 |
jpm |
651 |
case 'famille' :
|
938 |
jpm |
652 |
$sql = " AND famille LIKE $nom ";
|
|
|
653 |
break;
|
|
|
654 |
default:
|
|
|
655 |
$sql = " AND nom_ret LIKE $nom ";
|
1003 |
jpm |
656 |
}
|
938 |
jpm |
657 |
}
|
|
|
658 |
return $sql;
|
|
|
659 |
}
|
1003 |
jpm |
660 |
|
938 |
jpm |
661 |
private function construireWhereDate() {
|
|
|
662 |
$sql = '';
|
|
|
663 |
// Récupération des coordonnées depuis l'id station
|
940 |
jpm |
664 |
list($type, $date) = $this->decomposerParametreDate();
|
1003 |
jpm |
665 |
|
938 |
jpm |
666 |
if (!$this->etreNull($date)) {
|
|
|
667 |
$date = $this->proteger($date.'%');
|
|
|
668 |
switch ($type) {
|
|
|
669 |
case '*' :
|
|
|
670 |
$sql = " AND (
|
1003 |
jpm |
671 |
date_observation LIKE $date
|
|
|
672 |
OR date_creation LIKE $date
|
|
|
673 |
OR date_modification LIKE $date
|
938 |
jpm |
674 |
OR date_transmission LIKE $date) ";
|
|
|
675 |
break;
|
|
|
676 |
case 'observation' :
|
|
|
677 |
$sql = " AND date_observation LIKE $date ";
|
|
|
678 |
break;
|
|
|
679 |
case 'creation' :
|
|
|
680 |
$sql = " AND date_creation LIKE $date ";
|
|
|
681 |
break;
|
|
|
682 |
case 'modification' :
|
|
|
683 |
$sql = " AND date_modification LIKE $date ";
|
|
|
684 |
break;
|
|
|
685 |
case 'transmission' :
|
|
|
686 |
$sql = " AND date_transmission LIKE $date ";
|
|
|
687 |
break;
|
940 |
jpm |
688 |
case 'photo' :
|
|
|
689 |
$sql = $this->obtenirConditionPourDatePhoto($date);
|
|
|
690 |
break;
|
|
|
691 |
case 'ajout' :
|
|
|
692 |
$sql = $this->obtenirConditionPourDateAjout($date);
|
|
|
693 |
break;
|
938 |
jpm |
694 |
case 'liaison' :
|
940 |
jpm |
695 |
$sql = $this->obtenirConditionPourDateLiaison($date);
|
938 |
jpm |
696 |
break;
|
|
|
697 |
default:
|
|
|
698 |
$sql = " AND date_observation LIKE $date ";
|
|
|
699 |
}
|
|
|
700 |
}
|
|
|
701 |
return $sql;
|
|
|
702 |
}
|
1003 |
jpm |
703 |
|
940 |
jpm |
704 |
private function obtenirConditionPourDatePhoto($date) {
|
|
|
705 |
$observations = $this->obtenirObsLieesImg('date.photo', $date);
|
|
|
706 |
if (is_null($observations)) {
|
|
|
707 |
$this->debug[] = "Aucune observation n'est liée à une photo prise à la date : $date";
|
|
|
708 |
}
|
|
|
709 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
710 |
return $sql;
|
|
|
711 |
}
|
1003 |
jpm |
712 |
|
940 |
jpm |
713 |
private function obtenirConditionPourDateLiaison($date) {
|
|
|
714 |
$observations = $this->obtenirObsLieesImg('date.liaison', $date);
|
|
|
715 |
if (is_null($observations)) {
|
|
|
716 |
$this->debug[] = "Aucune observation n'a été liée à une image à à la date : $date";
|
|
|
717 |
}
|
|
|
718 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
719 |
return $sql;
|
|
|
720 |
}
|
|
|
721 |
|
|
|
722 |
private function obtenirConditionPourDateAjout($date) {
|
|
|
723 |
$observations = $this->obtenirObsLieesImg('date.ajout', $date);
|
|
|
724 |
if (is_null($observations)) {
|
|
|
725 |
$this->debug[] = "Aucune observation n'est liée à une image ajoutée à la date : $date";
|
|
|
726 |
}
|
|
|
727 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
728 |
return $sql;
|
|
|
729 |
}
|
1003 |
jpm |
730 |
|
940 |
jpm |
731 |
private function obtenirConditionPourCommentaireMeta($commentaire) {
|
|
|
732 |
$observations = $this->obtenirObsLieesImg('commentaire.meta', $commentaire);
|
|
|
733 |
if (is_null($observations)) {
|
|
|
734 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des méta-données correspond à : $commmentaire";
|
|
|
735 |
}
|
|
|
736 |
$operateur = '';
|
|
|
737 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
738 |
return $sql;
|
|
|
739 |
}
|
1003 |
jpm |
740 |
|
940 |
jpm |
741 |
private function obtenirConditionPourCommentaireUtilisateur($commentaire) {
|
|
|
742 |
$observations = $this->obtenirObsLieesImg('commentaire.utilisateur', $commentaire);
|
|
|
743 |
if (is_null($observations)) {
|
|
|
744 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des utilisateur correspond à : $commmentaire";
|
|
|
745 |
}
|
|
|
746 |
$operateur = '';
|
|
|
747 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
748 |
return $sql;
|
|
|
749 |
}
|
1003 |
jpm |
750 |
|
940 |
jpm |
751 |
private function obtenirConditionPourCommentaires($commentaire) {
|
|
|
752 |
$observations = $this->obtenirObsLieesImg('commentaire.*', $commentaire);
|
|
|
753 |
if (is_null($observations)) {
|
|
|
754 |
$this->debug[] = "Aucune observation n'est liée à une image dont un des commentaires correspond à : $commmentaire";
|
|
|
755 |
}
|
|
|
756 |
$operateur = '';
|
|
|
757 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
758 |
return $sql;
|
|
|
759 |
}
|
1003 |
jpm |
760 |
|
940 |
jpm |
761 |
/**
|
|
|
762 |
* Récupération des identifiant d'utilisateur et des ordres des observations correspondant à une date.
|
|
|
763 |
* Retour sous forme de tableau : array[identifiant] = array(ordre, ordre...);
|
|
|
764 |
*/
|
|
|
765 |
private function obtenirObsLieesImg($type, $param) {
|
|
|
766 |
// Construction de la requête
|
1339 |
aurelien |
767 |
$requete = 'SELECT DISTINCT co.id_obs, ci.ce_utilisateur AS utilisateur '.
|
940 |
jpm |
768 |
'FROM cel_images '.
|
1339 |
aurelien |
769 |
' LEFT JOIN cel_obs_images coi '.
|
|
|
770 |
' ON (ci.id_image = coi.id_image) '.
|
|
|
771 |
' LEFT JOIN cel_obs AS co '.
|
|
|
772 |
' ON (coi.id_observation = co.id_observation) '.
|
|
|
773 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
774 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
940 |
jpm |
775 |
"WHERE transmission = '1' ".
|
|
|
776 |
($type == 'date.photo' ? " AND (ci_meta_date_time LIKE ".str_replace('-', ':', $param)." OR ci_meta_date LIKE $param) " : '').
|
|
|
777 |
($type == 'date.ajout' ? " AND ci_meta_date_ajout LIKE $param " : '').
|
|
|
778 |
($type == 'date.liaison' ? " AND coi_date_liaison LIKE $param " : '').
|
|
|
779 |
($type == 'commentaire.meta' ? " AND ci_meta_comment LIKE $param " : '').
|
|
|
780 |
($type == 'commentaire.utilisateur' ? " AND ci_meta_user_comment LIKE $param " : '').
|
|
|
781 |
($type == 'commentaire.*' ? " AND (ci_meta_comment LIKE $param OR ci_meta_user_comment LIKE $param) " : '').
|
1003 |
jpm |
782 |
$this->construireWhereCoordonnees().
|
940 |
jpm |
783 |
$this->construireWhereDept().
|
|
|
784 |
$this->construireWhereCommune().
|
|
|
785 |
$this->construireWhereUtilisateur().
|
|
|
786 |
$this->construireWhereNumTaxon().
|
|
|
787 |
$this->construireWhereNomTaxon().
|
|
|
788 |
$this->construireWhereProjet().
|
|
|
789 |
$this->construireWhereTag().
|
|
|
790 |
'ORDER BY utilisateur ASC, ordre ASC';
|
|
|
791 |
//$this->debug[] = $requete;
|
|
|
792 |
//die($requete);
|
|
|
793 |
$resultats = $this->executerRequete($requete);
|
1003 |
jpm |
794 |
|
940 |
jpm |
795 |
$observations = null;
|
|
|
796 |
if ($resultats != false) {
|
|
|
797 |
$observations = array();
|
|
|
798 |
foreach ($resultats as $occurence) {
|
|
|
799 |
$utilisateur = $occurence['utilisateur'];
|
|
|
800 |
$ordre = $occurence['ordre'];
|
|
|
801 |
if (!array_key_exists($utilisateur, $observations)) {
|
|
|
802 |
$observations[$utilisateur] = array();
|
|
|
803 |
}
|
|
|
804 |
if (!array_key_exists($ordre, $observations[$utilisateur])) {
|
|
|
805 |
$observations[$utilisateur][$ordre] = $ordre;
|
|
|
806 |
}
|
|
|
807 |
}
|
|
|
808 |
}
|
|
|
809 |
return $observations;
|
|
|
810 |
}
|
1003 |
jpm |
811 |
|
940 |
jpm |
812 |
private function assemblerObsEnConditionSql($observations, $operateur = 'AND') {
|
|
|
813 |
$sql = '';
|
|
|
814 |
if ($observations != null) {
|
|
|
815 |
// Pré-construction du where de la requête
|
|
|
816 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
|
|
817 |
foreach ($observations as $utilisateur => $ordres) {
|
|
|
818 |
$morceaux_requete[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
|
|
819 |
}
|
|
|
820 |
if (count($morceaux_requete) > 0) {
|
|
|
821 |
$sql = implode(" \nOR ", $morceaux_requete);
|
|
|
822 |
}
|
|
|
823 |
} else {
|
|
|
824 |
// Nous voulons que la requête ne retourne rien
|
|
|
825 |
$sql = "identifiant = '' AND ordre = ''";
|
|
|
826 |
}
|
|
|
827 |
$sql = " $operateur ($sql) ";
|
|
|
828 |
return $sql;
|
|
|
829 |
}
|
1003 |
jpm |
830 |
|
981 |
jpm |
831 |
private function construireWhereRectangleStation() {
|
|
|
832 |
$sql = '';
|
1132 |
aurelien |
833 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
834 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
835 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
836 |
|
981 |
jpm |
837 |
$latMin = $sw['lat'];
|
|
|
838 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
839 |
|
981 |
jpm |
840 |
$latMax = $ne['lat'];
|
|
|
841 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
842 |
|
1339 |
aurelien |
843 |
// ATTENTION : latitude correspond bien à la LATITUDE!
|
|
|
844 |
$sql = " AND (latitude != 0 AND longitude != 0) ".
|
|
|
845 |
" AND latitude > $latMin ".
|
|
|
846 |
" AND latitude < $latMax ".
|
|
|
847 |
" AND longitude > $lngMin ".
|
|
|
848 |
" AND longitude < $lngMax ";
|
981 |
jpm |
849 |
}
|
|
|
850 |
return $sql;
|
|
|
851 |
}
|
1003 |
jpm |
852 |
|
981 |
jpm |
853 |
private function construireWhereRectangleStationOR() {
|
|
|
854 |
$sql = '';
|
1132 |
aurelien |
855 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
856 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
857 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
858 |
|
981 |
jpm |
859 |
$latMin = $sw['lat'];
|
|
|
860 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
861 |
|
981 |
jpm |
862 |
$latMax = $ne['lat'];
|
|
|
863 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
864 |
|
1339 |
aurelien |
865 |
$sql = "( (latitude != 0 AND longitude != 0) ".
|
|
|
866 |
" AND latitude > $latMin ".
|
|
|
867 |
" AND latitude < $latMax ".
|
|
|
868 |
" AND longitude > $lngMin ".
|
|
|
869 |
" AND longitude < $lngMax )";
|
981 |
jpm |
870 |
}
|
|
|
871 |
return $sql;
|
|
|
872 |
}
|
1003 |
jpm |
873 |
|
981 |
jpm |
874 |
private function construireWhereRectangleCommune() {
|
|
|
875 |
$sql = '';
|
1132 |
aurelien |
876 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
877 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
878 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
879 |
|
981 |
jpm |
880 |
$latMin = $sw['lat'];
|
|
|
881 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
882 |
|
981 |
jpm |
883 |
$latMax = $ne['lat'];
|
|
|
884 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
885 |
|
|
|
886 |
$sql = "AND wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
981 |
jpm |
887 |
" AND wgs84_latitude > $latMin ".
|
|
|
888 |
" AND wgs84_latitude < $latMax ".
|
|
|
889 |
" AND wgs84_longitude > $lngMin ".
|
|
|
890 |
" AND wgs84_longitude < $lngMax ";
|
|
|
891 |
}
|
|
|
892 |
return $sql;
|
|
|
893 |
}
|
1003 |
jpm |
894 |
|
981 |
jpm |
895 |
private function construireWhereRectangleCommuneOR() {
|
|
|
896 |
$sql = '';
|
1132 |
aurelien |
897 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
898 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
899 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
900 |
|
981 |
jpm |
901 |
$latMin = $sw['lat'];
|
|
|
902 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
903 |
|
981 |
jpm |
904 |
$latMax = $ne['lat'];
|
|
|
905 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
906 |
|
|
|
907 |
$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
981 |
jpm |
908 |
" AND wgs84_latitude > $latMin ".
|
|
|
909 |
" AND wgs84_latitude < $latMax ".
|
|
|
910 |
" AND wgs84_longitude > $lngMin ".
|
|
|
911 |
" AND wgs84_longitude < $lngMax )";
|
|
|
912 |
}
|
|
|
913 |
return $sql;
|
|
|
914 |
}
|
1003 |
jpm |
915 |
|
938 |
jpm |
916 |
private function construireWhereDept() {
|
|
|
917 |
$sql = '';
|
|
|
918 |
// Récupération des coordonnées depuis l'id station
|
|
|
919 |
extract($this->parametres);
|
1339 |
aurelien |
920 |
if (isset($dept) && !$this->etreNull($dept)) {
|
|
|
921 |
$valeurs_a_proteger = explode(',',trim($dept));
|
|
|
922 |
foreach ($valeurs_a_proteger as $valeur) {
|
|
|
923 |
$valeurs_protegees[] = '(ce_zone_geo LIKE '.$this->bdd->quote('INSEE-C:'.$valeur.'%').') ';
|
|
|
924 |
}
|
|
|
925 |
$valeurs = implode(' OR ', $valeurs_protegees);
|
|
|
926 |
$sql = " AND ($valeurs) ";
|
938 |
jpm |
927 |
}
|
|
|
928 |
return $sql;
|
|
|
929 |
}
|
1003 |
jpm |
930 |
|
938 |
jpm |
931 |
private function construireWhereCommune() {
|
|
|
932 |
$sql = '';
|
|
|
933 |
// Récupération des coordonnées depuis l'id station
|
|
|
934 |
extract($this->parametres);
|
1132 |
aurelien |
935 |
if (isset($this->parametres['commune']) && !$this->etreNull($commune)) {
|
938 |
jpm |
936 |
$commune = $this->proteger($commune);
|
1339 |
aurelien |
937 |
$sql = " AND zone_geo LIKE $commune ";
|
938 |
jpm |
938 |
}
|
|
|
939 |
return $sql;
|
|
|
940 |
}
|
1003 |
jpm |
941 |
|
1092 |
aurelien |
942 |
private function construireWhereCommuneSansCoordonneesAvecSensibles() {
|
1043 |
aurelien |
943 |
$sql = '';
|
|
|
944 |
// Récupération des coordonnées depuis l'id station
|
|
|
945 |
extract($this->parametres);
|
1132 |
aurelien |
946 |
if (isset($this->parametres['commune']) && !$this->etreNull($commune)) {
|
1043 |
aurelien |
947 |
$commune = $this->proteger($commune);
|
1339 |
aurelien |
948 |
$sql = " AND zone_geo LIKE $commune ";
|
1092 |
aurelien |
949 |
$sql .= " AND (
|
|
|
950 |
(
|
1411 |
aurelien |
951 |
(latitude = '000null' OR latitude = '' OR latitude = 0 OR latitude IS NULL) ".
|
|
|
952 |
" AND (longitude = '000null' OR longitude = '' OR longitude = 0 OR longitude IS NULL)".
|
1092 |
aurelien |
953 |
')'.
|
|
|
954 |
' OR mots_cles_texte LIKE "%sensible%"'.
|
|
|
955 |
') ';
|
|
|
956 |
|
1043 |
aurelien |
957 |
}
|
|
|
958 |
return $sql;
|
|
|
959 |
}
|
1003 |
jpm |
960 |
|
938 |
jpm |
961 |
private function construireWhereUtilisateur() {
|
|
|
962 |
$sql = '';
|
1339 |
aurelien |
963 |
// TODO tester si l'on recoit un id, un mail ou bien un nom ou prenom
|
|
|
964 |
// pour en faire une fonction polyvalente
|
938 |
jpm |
965 |
extract($this->parametres);
|
1132 |
aurelien |
966 |
if (isset($this->parametres['utilisateur']) && !$this->etreNull($utilisateur)) {
|
938 |
jpm |
967 |
$utilisateur = $this->proteger($utilisateur);
|
1339 |
aurelien |
968 |
$sql = " AND co.courriel_utilisateur = $utilisateur ";
|
938 |
jpm |
969 |
}
|
|
|
970 |
return $sql;
|
|
|
971 |
}
|
1003 |
jpm |
972 |
|
938 |
jpm |
973 |
private function construireWhereNumTaxon() {
|
|
|
974 |
$sql = '';
|
|
|
975 |
// Récupération des coordonnées depuis l'id station
|
|
|
976 |
extract($this->parametres);
|
1339 |
aurelien |
977 |
if (isset($this->parametres['nt']) && !$this->etreNull($num_taxon)) {
|
938 |
jpm |
978 |
$num_taxon = $this->proteger($num_taxon);
|
1339 |
aurelien |
979 |
$sql = " AND nt = $num_taxon ";
|
938 |
jpm |
980 |
}
|
|
|
981 |
return $sql;
|
|
|
982 |
}
|
1003 |
jpm |
983 |
|
1339 |
aurelien |
984 |
private function construireWhereProjet() {
|
938 |
jpm |
985 |
$sql = '';
|
|
|
986 |
// Récupération des coordonnées depuis l'id station
|
|
|
987 |
extract($this->parametres);
|
1339 |
aurelien |
988 |
$projet_sql = isset($projet) ? $this->getSqlWhereProjet($projet) : null;
|
|
|
989 |
if (!$this->etreNull($projet_sql)) {
|
|
|
990 |
$sql = " AND ($projet_sql) ";
|
938 |
jpm |
991 |
}
|
|
|
992 |
return $sql;
|
|
|
993 |
}
|
1339 |
aurelien |
994 |
|
840 |
jpm |
995 |
/**
|
938 |
jpm |
996 |
* Traitement de $projet pour construction du filtre dans la requête
|
478 |
jpm |
997 |
*/
|
938 |
jpm |
998 |
private function getSqlWhereProjet($projet) {
|
|
|
999 |
$sql = null;
|
1339 |
aurelien |
1000 |
if (isset($projet) && !$this->etreNull($projet)) {
|
1394 |
aurelien |
1001 |
$sql = 'co.mots_cles_texte LIKE '.$this->proteger('%'.$projet.'%');
|
938 |
jpm |
1002 |
}
|
|
|
1003 |
return $sql;
|
|
|
1004 |
}
|
1339 |
aurelien |
1005 |
|
938 |
jpm |
1006 |
private function construireWhereTag() {
|
|
|
1007 |
$sql = '';
|
840 |
jpm |
1008 |
extract($this->parametres);
|
1339 |
aurelien |
1009 |
$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
|
|
|
1010 |
if (!$this->etreNull($tag_sql)) {
|
|
|
1011 |
$sql = " AND ($tag_sql) ";
|
489 |
jpm |
1012 |
}
|
938 |
jpm |
1013 |
return $sql;
|
|
|
1014 |
}
|
1339 |
aurelien |
1015 |
|
938 |
jpm |
1016 |
/**
|
|
|
1017 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1018 |
*/
|
|
|
1019 |
private function getSqlWhereObsAvecImagesTaguees($tag) {
|
|
|
1020 |
$sql = null;
|
1339 |
aurelien |
1021 |
if (isset($tag) && !$this->etreNull($tag)) {
|
938 |
jpm |
1022 |
$tag_sql = $this->getSqlWhereMotsCles($tag);
|
|
|
1023 |
// Construction de la requête
|
1339 |
aurelien |
1024 |
$requete = 'SELECT DISTINCT coi.id_observation AS id_obs, ci.ce_utilisateur AS utilisateur '.
|
|
|
1025 |
'FROM cel_images ci'.
|
|
|
1026 |
' LEFT JOIN cel_obs_images coi'.
|
|
|
1027 |
' ON (ci.id_image = coi.id_image) '.
|
|
|
1028 |
' LEFT JOIN cel_obs AS co '.
|
|
|
1029 |
' ON (coi.id_observation = co.id_observation) '.
|
|
|
1030 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
1031 |
" ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) ".
|
|
|
1032 |
"WHERE transmission = '1' ".
|
938 |
jpm |
1033 |
$this->construireWhereCoordonnees().
|
|
|
1034 |
$this->construireWhereUtilisateur().
|
|
|
1035 |
$this->construireWhereNumTaxon().
|
|
|
1036 |
$this->construireWhereNomTaxon().
|
|
|
1037 |
$this->construireWhereProjet().
|
|
|
1038 |
(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
|
1339 |
aurelien |
1039 |
'ORDER BY utilisateur ASC, ci.ordre ASC';
|
938 |
jpm |
1040 |
//$this->debug[] = $requete;
|
|
|
1041 |
//die($requete);
|
|
|
1042 |
$elements_tag = $this->executerRequete($requete);
|
1339 |
aurelien |
1043 |
|
938 |
jpm |
1044 |
$requete_tag = array();
|
|
|
1045 |
if ($elements_tag != false && count($elements_tag) > 0) {
|
1339 |
aurelien |
1046 |
|
938 |
jpm |
1047 |
$filtres = array();
|
|
|
1048 |
foreach ($elements_tag as $occurence) {
|
|
|
1049 |
$utilisateur = $occurence['utilisateur'];
|
1339 |
aurelien |
1050 |
$id_obs = $occurence['id_obs'];
|
938 |
jpm |
1051 |
if (!array_key_exists($utilisateur, $filtres)) {
|
|
|
1052 |
$filtres[$utilisateur] = array();
|
|
|
1053 |
}
|
1339 |
aurelien |
1054 |
if (!array_key_exists($id_obs, $filtres[$utilisateur])) {
|
|
|
1055 |
$filtres[$utilisateur][$id_obs] = $id_obs;
|
938 |
jpm |
1056 |
}
|
|
|
1057 |
}
|
1339 |
aurelien |
1058 |
|
938 |
jpm |
1059 |
// Pré-construction du where de la requête
|
1339 |
aurelien |
1060 |
$tpl_where = "(id_observation IN (%s))";
|
|
|
1061 |
foreach ($filtres as $utilisateur => $id_obs) {
|
|
|
1062 |
$requete_tag[] = sprintf($tpl_where, implode(',', $id_obs));
|
938 |
jpm |
1063 |
}
|
1339 |
aurelien |
1064 |
|
938 |
jpm |
1065 |
} else {
|
|
|
1066 |
$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
|
|
|
1067 |
}
|
|
|
1068 |
if (count($requete_tag) > 0) {
|
|
|
1069 |
$sql = implode(" \nOR ", $requete_tag);
|
|
|
1070 |
}
|
489 |
jpm |
1071 |
}
|
938 |
jpm |
1072 |
return $sql;
|
478 |
jpm |
1073 |
}
|
1339 |
aurelien |
1074 |
|
487 |
jpm |
1075 |
/**
|
938 |
jpm |
1076 |
* Traitement de $tag pour construction du filtre dans la requête
|
487 |
jpm |
1077 |
*/
|
938 |
jpm |
1078 |
private function getSqlWhereMotsCles($tag) {
|
|
|
1079 |
$sql = null;
|
940 |
jpm |
1080 |
$mots_cles = $this->decomposerParametreTag($tag);
|
1339 |
aurelien |
1081 |
$requete_projet = $this->getSqlWhereMotsClesImages($mots_cles);
|
|
|
1082 |
$sql = $requete_projet;
|
938 |
jpm |
1083 |
//$this->debug[] = $sql;
|
487 |
jpm |
1084 |
return $sql;
|
840 |
jpm |
1085 |
}
|
1339 |
aurelien |
1086 |
|
938 |
jpm |
1087 |
/**
|
|
|
1088 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1089 |
*/
|
|
|
1090 |
private function getSqlWhereMotsClesImages($mots_cles_encodes) {
|
|
|
1091 |
$where_mots_cles_images = array();
|
1339 |
aurelien |
1092 |
foreach ($mots_cles_encodes['motsClesEncodesProteges'] as $mot_cle_encode) {
|
|
|
1093 |
$where_mots_cles_images[] = "ci.mots_cles_texte LIKE $mot_cle_encode";
|
938 |
jpm |
1094 |
}
|
1339 |
aurelien |
1095 |
$where_mots_cles_images = implode(' '.$mots_cles_encodes['type'].' ', $where_mots_cles_images);
|
938 |
jpm |
1096 |
return $where_mots_cles_images;
|
|
|
1097 |
}
|
1339 |
aurelien |
1098 |
|
940 |
jpm |
1099 |
private function decomposerParametreTag($tags) {
|
1339 |
aurelien |
1100 |
|
938 |
jpm |
1101 |
$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
|
|
|
1102 |
if (preg_match('/.+OU.+/', $tags)) {
|
|
|
1103 |
$mots_cles['type'] = 'OR';
|
|
|
1104 |
$mots_cles['motsCles'] = explode('OU', $tags);
|
|
|
1105 |
} else if (preg_match('/.+ET.+/', $tags)) {
|
|
|
1106 |
$mots_cles['type'] = 'AND';
|
|
|
1107 |
$mots_cles['motsCles'] = explode('ET', $tags);
|
|
|
1108 |
} else {
|
|
|
1109 |
$mots_cles['motsCles'][] = $tags;
|
|
|
1110 |
}
|
1339 |
aurelien |
1111 |
|
938 |
jpm |
1112 |
foreach ($mots_cles['motsCles'] as $mot) {
|
1339 |
aurelien |
1113 |
$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote('%'.$mot.'%');
|
938 |
jpm |
1114 |
}
|
|
|
1115 |
$this->debug[] = $mots_cles;
|
|
|
1116 |
return $mots_cles;
|
|
|
1117 |
}
|
1003 |
jpm |
1118 |
|
981 |
jpm |
1119 |
private function decomposerLatLng($coord) {
|
|
|
1120 |
$lat_lng = array();
|
|
|
1121 |
if (isset($coord)) {
|
|
|
1122 |
list($lat, $lng) = explode('|', $coord);
|
|
|
1123 |
$lat_lng = array('lat' => $lat, 'lng' => $lng);
|
|
|
1124 |
}
|
|
|
1125 |
return $lat_lng;
|
|
|
1126 |
}
|
1003 |
jpm |
1127 |
|
940 |
jpm |
1128 |
private function decomposerParametreStation() {
|
938 |
jpm |
1129 |
$station_infos = array();
|
|
|
1130 |
if (isset($this->parametres['station'])) {
|
|
|
1131 |
$station = $this->parametres['station'];
|
|
|
1132 |
$this->debug[] = $station;
|
1033 |
aurelien |
1133 |
@list($type, $coord) = explode(':', $station);
|
|
|
1134 |
@list($lat, $lng) = explode('|', $coord);
|
1003 |
jpm |
1135 |
|
954 |
jpm |
1136 |
$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
|
938 |
jpm |
1137 |
}
|
|
|
1138 |
return $station_infos;
|
|
|
1139 |
}
|
1003 |
jpm |
1140 |
|
940 |
jpm |
1141 |
private function decomposerParametreDate() {
|
1132 |
aurelien |
1142 |
$date_infos = array(null,null);
|
940 |
jpm |
1143 |
if (isset($this->parametres['date'])) {
|
|
|
1144 |
$date = $this->parametres['date'];
|
|
|
1145 |
if (strpos($date, ':')) {
|
|
|
1146 |
list($type, $date) = explode(':', $date);
|
|
|
1147 |
} else {
|
|
|
1148 |
$type = 'observation';
|
|
|
1149 |
}
|
1003 |
jpm |
1150 |
|
940 |
jpm |
1151 |
$date = str_replace('/', '-', $date);
|
|
|
1152 |
if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $date, $matches)) {
|
|
|
1153 |
$date = $matches[3].'-'.$matches[2].'-'.$matches[1];
|
|
|
1154 |
}
|
1003 |
jpm |
1155 |
|
940 |
jpm |
1156 |
$date_infos = array($type, $date);
|
|
|
1157 |
}
|
|
|
1158 |
return $date_infos;
|
|
|
1159 |
}
|
1003 |
jpm |
1160 |
|
940 |
jpm |
1161 |
private function decomposerParametreTaxon() {
|
1132 |
aurelien |
1162 |
$nom_infos = array(null,null);
|
940 |
jpm |
1163 |
if (isset($this->parametres['taxon'])) {
|
|
|
1164 |
$taxon = $this->parametres['taxon'];
|
|
|
1165 |
if (strpos($taxon, ':')) {
|
|
|
1166 |
$nom_infos = explode(':', $taxon);
|
|
|
1167 |
} else {
|
|
|
1168 |
$nom_infos = array('retenu', $taxon);
|
|
|
1169 |
}
|
|
|
1170 |
}
|
|
|
1171 |
return $nom_infos;
|
|
|
1172 |
}
|
1003 |
jpm |
1173 |
|
940 |
jpm |
1174 |
private function decomposerParametreCommentaire() {
|
1132 |
aurelien |
1175 |
$commentaire_infos = array(null,null);
|
940 |
jpm |
1176 |
if (isset($this->parametres['commentaire'])) {
|
|
|
1177 |
$commentaire = $this->parametres['commentaire'];
|
|
|
1178 |
if (strpos($commentaire, ':')) {
|
|
|
1179 |
$commentaire_infos = explode(':', $commentaire);
|
|
|
1180 |
} else {
|
|
|
1181 |
$commentaire_infos = array('observation', $commentaire);
|
|
|
1182 |
}
|
|
|
1183 |
}
|
|
|
1184 |
return $commentaire_infos;
|
|
|
1185 |
}
|
1172 |
aurelien |
1186 |
}
|
|
|
1187 |
?>
|