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