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