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