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:
|
2446 |
jpm |
18 |
* machin ET bidule ET chose => observations ayant tous les mots-clés (intersection)
|
2282 |
mathias |
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 '.
|
2449 |
jpm |
110 |
' LEFT JOIN cel_zones_geo AS zg '.
|
|
|
111 |
' ON (zg.nom = co.zone_geo AND zg.id_zone_geo = co.ce_zone_geo) '.
|
1622 |
aurelien |
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 '.
|
2449 |
jpm |
148 |
' LEFT JOIN cel_zones_geo AS zg '.
|
|
|
149 |
' ON (zg.nom = co.zone_geo AND zg.id_zone_geo = co.ce_zone_geo) '.
|
1622 |
aurelien |
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 '.
|
2449 |
jpm |
336 |
' LEFT JOIN cel_zones_geo AS zg '.
|
|
|
337 |
" ON (zg.nom = co.zone_geo AND zg.id_zone_geo = co.ce_zone_geo) ".
|
1622 |
aurelien |
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 '.
|
2449 |
jpm |
482 |
' LEFT JOIN cel_zones_geo AS zg '.
|
|
|
483 |
' ON (zg.nom = co.zone_geo AND zg.id_zone_geo = co.ce_zone_geo) '.
|
1622 |
aurelien |
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
|
2446 |
jpm |
739 |
$requete = 'SELECT DISTINCT co.id_obs, ci.ce_utilisateur AS utilisateur '.
|
2449 |
jpm |
740 |
'FROM cel_images AS ci '.
|
1339 |
aurelien |
741 |
' LEFT JOIN cel_obs AS co '.
|
2446 |
jpm |
742 |
' ON (ci.ce_observation = co.id_observation) '.
|
2449 |
jpm |
743 |
' LEFT JOIN cel_zones_geo AS zg '.
|
|
|
744 |
' ON (zg.nom = co.zone_geo AND zg.id_zone_geo = co.ce_zone_geo) '.
|
2446 |
jpm |
745 |
"WHERE co.transmission = '1' ".
|
|
|
746 |
($type == 'date.photo' ? " AND (ci.date_prise_de_vue LIKE ".str_replace('-', ':', $param).' ' : '').
|
|
|
747 |
($type == 'date.creation' ? " AND ci.date_creation LIKE $param " : '').
|
|
|
748 |
($type == 'date.liaison' ? " AND ci.date_liaison LIKE $param " : '').
|
|
|
749 |
($type == 'commentaire.img' ? " AND ci.commentaire LIKE $param " : '').
|
|
|
750 |
($type == 'commentaire.obs' ? " AND co.commentaire LIKE $param " : '').
|
|
|
751 |
($type == 'commentaire.*' ? " AND (co.commentaire LIKE $param OR ci.commentaire LIKE $param) " : '').
|
1003 |
jpm |
752 |
$this->construireWhereCoordonnees().
|
940 |
jpm |
753 |
$this->construireWhereDept().
|
|
|
754 |
$this->construireWhereCommune().
|
|
|
755 |
$this->construireWhereUtilisateur().
|
|
|
756 |
$this->construireWhereNumTaxon().
|
|
|
757 |
$this->construireWhereNomTaxon().
|
1497 |
aurelien |
758 |
$this->construireWhereReferentiel().
|
940 |
jpm |
759 |
$this->construireWhereProjet().
|
|
|
760 |
$this->construireWhereTag().
|
|
|
761 |
'ORDER BY utilisateur ASC, ordre ASC';
|
|
|
762 |
//$this->debug[] = $requete;
|
|
|
763 |
//die($requete);
|
2143 |
jpm |
764 |
$resultats = Cel::db()->requeter($requete);
|
1003 |
jpm |
765 |
|
940 |
jpm |
766 |
$observations = null;
|
|
|
767 |
if ($resultats != false) {
|
|
|
768 |
$observations = array();
|
|
|
769 |
foreach ($resultats as $occurence) {
|
|
|
770 |
$utilisateur = $occurence['utilisateur'];
|
|
|
771 |
$ordre = $occurence['ordre'];
|
|
|
772 |
if (!array_key_exists($utilisateur, $observations)) {
|
|
|
773 |
$observations[$utilisateur] = array();
|
|
|
774 |
}
|
|
|
775 |
if (!array_key_exists($ordre, $observations[$utilisateur])) {
|
|
|
776 |
$observations[$utilisateur][$ordre] = $ordre;
|
|
|
777 |
}
|
|
|
778 |
}
|
|
|
779 |
}
|
|
|
780 |
return $observations;
|
|
|
781 |
}
|
1003 |
jpm |
782 |
|
940 |
jpm |
783 |
private function assemblerObsEnConditionSql($observations, $operateur = 'AND') {
|
|
|
784 |
$sql = '';
|
|
|
785 |
if ($observations != null) {
|
|
|
786 |
// Pré-construction du where de la requête
|
|
|
787 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
|
|
788 |
foreach ($observations as $utilisateur => $ordres) {
|
|
|
789 |
$morceaux_requete[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
|
|
790 |
}
|
|
|
791 |
if (count($morceaux_requete) > 0) {
|
|
|
792 |
$sql = implode(" \nOR ", $morceaux_requete);
|
|
|
793 |
}
|
|
|
794 |
} else {
|
|
|
795 |
// Nous voulons que la requête ne retourne rien
|
|
|
796 |
$sql = "identifiant = '' AND ordre = ''";
|
|
|
797 |
}
|
|
|
798 |
$sql = " $operateur ($sql) ";
|
|
|
799 |
return $sql;
|
|
|
800 |
}
|
1003 |
jpm |
801 |
|
981 |
jpm |
802 |
private function construireWhereRectangleStation() {
|
|
|
803 |
$sql = '';
|
1132 |
aurelien |
804 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
805 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
806 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
807 |
|
981 |
jpm |
808 |
$latMin = $sw['lat'];
|
|
|
809 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
810 |
|
981 |
jpm |
811 |
$latMax = $ne['lat'];
|
|
|
812 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
813 |
|
1339 |
aurelien |
814 |
// ATTENTION : latitude correspond bien à la LATITUDE!
|
|
|
815 |
$sql = " AND (latitude != 0 AND longitude != 0) ".
|
|
|
816 |
" AND latitude > $latMin ".
|
|
|
817 |
" AND latitude < $latMax ".
|
|
|
818 |
" AND longitude > $lngMin ".
|
|
|
819 |
" AND longitude < $lngMax ";
|
981 |
jpm |
820 |
}
|
|
|
821 |
return $sql;
|
|
|
822 |
}
|
1003 |
jpm |
823 |
|
981 |
jpm |
824 |
private function construireWhereRectangleStationOR() {
|
|
|
825 |
$sql = '';
|
1132 |
aurelien |
826 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
827 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
828 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
829 |
|
981 |
jpm |
830 |
$latMin = $sw['lat'];
|
|
|
831 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
832 |
|
981 |
jpm |
833 |
$latMax = $ne['lat'];
|
|
|
834 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
835 |
|
1339 |
aurelien |
836 |
$sql = "( (latitude != 0 AND longitude != 0) ".
|
1466 |
aurelien |
837 |
" AND latitude BETWEEN $latMin AND $latMax ".
|
|
|
838 |
" AND longitude BETWEEN $lngMin AND $lngMax )";
|
2143 |
jpm |
839 |
|
1466 |
aurelien |
840 |
/*$sql = " MBRWithin(mon_point, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
|
|
|
841 |
$latMax.' '.$lngMin.','.
|
|
|
842 |
$latMax.' '.$lngMax.','.
|
|
|
843 |
$latMax.' '.$lngMin.','.
|
2143 |
jpm |
844 |
$latMin.' '.$lngMin."))')) "; */
|
981 |
jpm |
845 |
}
|
|
|
846 |
return $sql;
|
|
|
847 |
}
|
1003 |
jpm |
848 |
|
981 |
jpm |
849 |
private function construireWhereRectangleCommune() {
|
|
|
850 |
$sql = '';
|
1132 |
aurelien |
851 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
852 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
853 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
854 |
|
981 |
jpm |
855 |
$latMin = $sw['lat'];
|
|
|
856 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
857 |
|
981 |
jpm |
858 |
$latMax = $ne['lat'];
|
|
|
859 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
860 |
|
|
|
861 |
$sql = "AND wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
1466 |
aurelien |
862 |
" AND wgs84_latitude BETWEEN $latMin AND $latMax ".
|
|
|
863 |
" AND wgs84_longitude BETWEEN $lngMin AND $lngMax ";
|
981 |
jpm |
864 |
}
|
|
|
865 |
return $sql;
|
|
|
866 |
}
|
1003 |
jpm |
867 |
|
981 |
jpm |
868 |
private function construireWhereRectangleCommuneOR() {
|
|
|
869 |
$sql = '';
|
1132 |
aurelien |
870 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
871 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
872 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
873 |
|
981 |
jpm |
874 |
$latMin = $sw['lat'];
|
|
|
875 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
876 |
|
981 |
jpm |
877 |
$latMax = $ne['lat'];
|
|
|
878 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
879 |
|
|
|
880 |
$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
1466 |
aurelien |
881 |
" AND wgs84_latitude BETWEEN $latMin AND $latMax ".
|
|
|
882 |
" AND wgs84_longitude BETWEEN $lngMin AND $lngMax )";
|
2143 |
jpm |
883 |
|
1466 |
aurelien |
884 |
/*$sql = " MBRWithin(point_commune, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
|
|
|
885 |
$latMax.' '.$lngMin.','.
|
|
|
886 |
$latMax.' '.$lngMax.','.
|
|
|
887 |
$latMax.' '.$lngMin.','.
|
|
|
888 |
$latMin.' '.$lngMin."))')) ";*/
|
981 |
jpm |
889 |
}
|
|
|
890 |
return $sql;
|
|
|
891 |
}
|
1003 |
jpm |
892 |
|
938 |
jpm |
893 |
private function construireWhereDept() {
|
|
|
894 |
$sql = '';
|
|
|
895 |
// Récupération des coordonnées depuis l'id station
|
|
|
896 |
extract($this->parametres);
|
1339 |
aurelien |
897 |
if (isset($dept) && !$this->etreNull($dept)) {
|
|
|
898 |
$valeurs_a_proteger = explode(',',trim($dept));
|
|
|
899 |
foreach ($valeurs_a_proteger as $valeur) {
|
1765 |
raphael |
900 |
$valeurs_protegees[] = '(ce_zone_geo LIKE '.Cel::db()->quote('INSEE-C:'.$valeur.'%').') ';
|
1339 |
aurelien |
901 |
}
|
|
|
902 |
$valeurs = implode(' OR ', $valeurs_protegees);
|
|
|
903 |
$sql = " AND ($valeurs) ";
|
938 |
jpm |
904 |
}
|
|
|
905 |
return $sql;
|
|
|
906 |
}
|
1003 |
jpm |
907 |
|
938 |
jpm |
908 |
private function construireWhereCommune() {
|
|
|
909 |
$sql = '';
|
|
|
910 |
// Récupération des coordonnées depuis l'id station
|
|
|
911 |
extract($this->parametres);
|
1132 |
aurelien |
912 |
if (isset($this->parametres['commune']) && !$this->etreNull($commune)) {
|
1765 |
raphael |
913 |
$commune = Cel::db()->proteger($commune);
|
2170 |
mathias |
914 |
$sql = " AND zone_geo LIKE $commune";
|
938 |
jpm |
915 |
}
|
2170 |
mathias |
916 |
if (isset($this->parametres['zonegeo']) && !$this->etreNull($zonegeo)) {
|
|
|
917 |
$zonegeo = Cel::db()->proteger($zonegeo);
|
|
|
918 |
$sql = " AND ce_zone_geo = $zonegeo";
|
|
|
919 |
}
|
938 |
jpm |
920 |
return $sql;
|
|
|
921 |
}
|
1003 |
jpm |
922 |
|
1092 |
aurelien |
923 |
private function construireWhereCommuneSansCoordonneesAvecSensibles() {
|
1043 |
aurelien |
924 |
$sql = '';
|
|
|
925 |
// Récupération des coordonnées depuis l'id station
|
|
|
926 |
extract($this->parametres);
|
1132 |
aurelien |
927 |
if (isset($this->parametres['commune']) && !$this->etreNull($commune)) {
|
1765 |
raphael |
928 |
$commune = Cel::db()->proteger($commune);
|
2170 |
mathias |
929 |
$sql = " AND zone_geo LIKE $commune";
|
1092 |
aurelien |
930 |
$sql .= " AND (
|
|
|
931 |
(
|
1411 |
aurelien |
932 |
(latitude = '000null' OR latitude = '' OR latitude = 0 OR latitude IS NULL) ".
|
|
|
933 |
" AND (longitude = '000null' OR longitude = '' OR longitude = 0 OR longitude IS NULL)".
|
1092 |
aurelien |
934 |
')'.
|
|
|
935 |
' OR mots_cles_texte LIKE "%sensible%"'.
|
|
|
936 |
') ';
|
2143 |
jpm |
937 |
|
1043 |
aurelien |
938 |
}
|
2170 |
mathias |
939 |
if (isset($this->parametres['zonegeo']) && !$this->etreNull($zonegeo)) {
|
|
|
940 |
$zonegeo = Cel::db()->proteger($zonegeo);
|
|
|
941 |
$sql = " AND ce_zone_geo = $zonegeo";
|
|
|
942 |
}
|
1043 |
aurelien |
943 |
return $sql;
|
|
|
944 |
}
|
2143 |
jpm |
945 |
|
|
|
946 |
|
1466 |
aurelien |
947 |
private function construireWherePhotosSeulement() {
|
|
|
948 |
$sql = '';
|
|
|
949 |
if (isset($this->parametres['photos']) && $this->parametres['photos'] == 1) {
|
2446 |
jpm |
950 |
$sql = 'AND co.id_observation IN (SELECT DISTINCT ce_observation FROM cel_images) ';
|
1466 |
aurelien |
951 |
}
|
|
|
952 |
return $sql;
|
|
|
953 |
}
|
1003 |
jpm |
954 |
|
938 |
jpm |
955 |
private function construireWhereUtilisateur() {
|
|
|
956 |
$sql = '';
|
1339 |
aurelien |
957 |
// TODO tester si l'on recoit un id, un mail ou bien un nom ou prenom
|
|
|
958 |
// pour en faire une fonction polyvalente
|
938 |
jpm |
959 |
extract($this->parametres);
|
1132 |
aurelien |
960 |
if (isset($this->parametres['utilisateur']) && !$this->etreNull($utilisateur)) {
|
1765 |
raphael |
961 |
$utilisateur = Cel::db()->proteger($utilisateur);
|
1339 |
aurelien |
962 |
$sql = " AND co.courriel_utilisateur = $utilisateur ";
|
938 |
jpm |
963 |
}
|
|
|
964 |
return $sql;
|
|
|
965 |
}
|
2143 |
jpm |
966 |
|
|
|
967 |
|
938 |
jpm |
968 |
private function construireWhereNumTaxon() {
|
|
|
969 |
$sql = '';
|
|
|
970 |
// Récupération des coordonnées depuis l'id station
|
|
|
971 |
extract($this->parametres);
|
1428 |
aurelien |
972 |
if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
|
1765 |
raphael |
973 |
$num_taxon = Cel::db()->proteger($num_taxon);
|
1568 |
aurelien |
974 |
$sql = " AND nt = $num_taxon ";
|
|
|
975 |
}
|
|
|
976 |
return $sql;
|
|
|
977 |
}
|
2143 |
jpm |
978 |
|
1568 |
aurelien |
979 |
private function construireWhereNumTaxonAvecSousTaxons() {
|
|
|
980 |
$sql = '';
|
|
|
981 |
// Récupération des coordonnées depuis l'id station
|
|
|
982 |
extract($this->parametres);
|
|
|
983 |
if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
|
|
|
984 |
$sous_taxons = $this->obtenirSousTaxons($this->parametres['num_taxon']);
|
1765 |
raphael |
985 |
$num_taxon = Cel::db()->proteger($num_taxon);
|
1568 |
aurelien |
986 |
if(!empty($sous_taxons)) {
|
|
|
987 |
$sql_in_sous_tax = implode(',', $sous_taxons);
|
|
|
988 |
$sql = " AND (nt = $num_taxon OR ".
|
|
|
989 |
"nom_sel_nn IN (".$sql_in_sous_tax.") OR ".
|
|
|
990 |
"nom_ret_nn IN (".$sql_in_sous_tax.") ".
|
|
|
991 |
") ";
|
|
|
992 |
}
|
|
|
993 |
else {
|
|
|
994 |
$sql = " AND nt = $num_taxon ";
|
|
|
995 |
}
|
938 |
jpm |
996 |
}
|
|
|
997 |
return $sql;
|
|
|
998 |
}
|
2143 |
jpm |
999 |
|
1568 |
aurelien |
1000 |
private function obtenirSousTaxons($nt) {
|
|
|
1001 |
$referentiel = 'bdtfx';
|
2010 |
mathias |
1002 |
if(isset($this->parametres['referentiel']) && $this->parametres['referentiel'] != "" && $this->parametres['referentiel'] != '*') {
|
1568 |
aurelien |
1003 |
$referentiel = $this->parametres['referentiel'];
|
|
|
1004 |
}
|
|
|
1005 |
$nn_sous_taxons = array();
|
|
|
1006 |
$sous_taxons = $this->obtenirSousTaxonsPourNt($referentiel, $nt);
|
|
|
1007 |
foreach($sous_taxons as $sous_tax) {
|
|
|
1008 |
$nn_sous_taxons[] = $sous_tax['num_nom'];
|
|
|
1009 |
}
|
|
|
1010 |
return $nn_sous_taxons;
|
|
|
1011 |
}
|
1003 |
jpm |
1012 |
|
1466 |
aurelien |
1013 |
private function construireWhereProjet() {
|
938 |
jpm |
1014 |
$sql = '';
|
|
|
1015 |
extract($this->parametres);
|
1339 |
aurelien |
1016 |
$projet_sql = isset($projet) ? $this->getSqlWhereProjet($projet) : null;
|
|
|
1017 |
if (!$this->etreNull($projet_sql)) {
|
|
|
1018 |
$sql = " AND ($projet_sql) ";
|
938 |
jpm |
1019 |
}
|
|
|
1020 |
return $sql;
|
|
|
1021 |
}
|
2143 |
jpm |
1022 |
|
840 |
jpm |
1023 |
/**
|
938 |
jpm |
1024 |
* Traitement de $projet pour construction du filtre dans la requête
|
2446 |
jpm |
1025 |
*
|
2282 |
mathias |
1026 |
* projet1 ET projet2 ET projet3 => intersection
|
|
|
1027 |
* projet1 OU projet2 OU projet3 => union
|
2446 |
jpm |
1028 |
* projet1 ET projet2 OU projet3 => ATTENTION indéfini
|
478 |
jpm |
1029 |
*/
|
938 |
jpm |
1030 |
private function getSqlWhereProjet($projet) {
|
|
|
1031 |
$sql = null;
|
2446 |
jpm |
1032 |
if (isset($projet) && !$this->etreNull($projet)) {
|
2282 |
mathias |
1033 |
if (strpos($projet, ' ET ')) {
|
|
|
1034 |
// intersection
|
|
|
1035 |
$projets = explode(' ET ', $projet);
|
|
|
1036 |
$clauses = array();
|
|
|
1037 |
foreach ($projets as $proj) {
|
|
|
1038 |
if ($proj != '') {
|
|
|
1039 |
$clauses[] = 'co.mots_cles_texte LIKE '.Cel::db()->proteger('%'.$proj.'%');
|
|
|
1040 |
}
|
|
|
1041 |
}
|
|
|
1042 |
$sql = implode($clauses, ' AND ');
|
|
|
1043 |
} else if (strpos($projet, ' OU ')) {
|
|
|
1044 |
// union
|
|
|
1045 |
$projets = explode(' OU ', $projet);
|
|
|
1046 |
$clauses = array();
|
|
|
1047 |
foreach ($projets as $proj) {
|
|
|
1048 |
if ($proj != '') {
|
|
|
1049 |
$clauses[] = 'co.mots_cles_texte LIKE '.Cel::db()->proteger('%'.$proj.'%');
|
|
|
1050 |
}
|
|
|
1051 |
}
|
|
|
1052 |
$sql = implode($clauses, ' OR ');
|
|
|
1053 |
} else {
|
|
|
1054 |
// simple
|
|
|
1055 |
$sql = 'co.mots_cles_texte LIKE '.Cel::db()->proteger('%'.$projet.'%');
|
|
|
1056 |
}
|
938 |
jpm |
1057 |
}
|
|
|
1058 |
return $sql;
|
|
|
1059 |
}
|
2143 |
jpm |
1060 |
|
938 |
jpm |
1061 |
private function construireWhereTag() {
|
|
|
1062 |
$sql = '';
|
840 |
jpm |
1063 |
extract($this->parametres);
|
1339 |
aurelien |
1064 |
$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
|
|
|
1065 |
if (!$this->etreNull($tag_sql)) {
|
|
|
1066 |
$sql = " AND ($tag_sql) ";
|
489 |
jpm |
1067 |
}
|
938 |
jpm |
1068 |
return $sql;
|
|
|
1069 |
}
|
2143 |
jpm |
1070 |
|
1484 |
aurelien |
1071 |
private function construireWhereNombreDeJours() {
|
|
|
1072 |
$sql = null;
|
|
|
1073 |
extract($this->parametres);
|
|
|
1074 |
if (isset($nbjours) && !$this->etreNull($nbjours)) {
|
1765 |
raphael |
1075 |
$sql = ' AND DATEDIFF(CURDATE(),co.date_creation) <= '.Cel::db()->proteger($nbjours).' ';
|
1484 |
aurelien |
1076 |
}
|
|
|
1077 |
return $sql;
|
|
|
1078 |
}
|
2143 |
jpm |
1079 |
|
2291 |
mathias |
1080 |
private function construireWhereAnnee() {
|
|
|
1081 |
$sql = null;
|
|
|
1082 |
extract($this->parametres);
|
|
|
1083 |
if (isset($annee) && !$this->etreNull($annee)) {
|
|
|
1084 |
$sql = ' AND YEAR(co.date_creation) = ' . Cel::db()->proteger($annee) . ' ';
|
|
|
1085 |
}
|
|
|
1086 |
return $sql;
|
|
|
1087 |
}
|
|
|
1088 |
|
938 |
jpm |
1089 |
/**
|
|
|
1090 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1091 |
*/
|
|
|
1092 |
private function getSqlWhereObsAvecImagesTaguees($tag) {
|
|
|
1093 |
$sql = null;
|
1339 |
aurelien |
1094 |
if (isset($tag) && !$this->etreNull($tag)) {
|
938 |
jpm |
1095 |
$tag_sql = $this->getSqlWhereMotsCles($tag);
|
|
|
1096 |
// Construction de la requête
|
2446 |
jpm |
1097 |
$requete = 'SELECT DISTINCT co.id_observation AS id_obs, ci.ce_utilisateur AS utilisateur '.
|
1339 |
aurelien |
1098 |
'FROM cel_images ci'.
|
2446 |
jpm |
1099 |
' INNER JOIN cel_obs AS co '.
|
|
|
1100 |
' ON (ci.ce_observation = co.id_observation) '.
|
2449 |
jpm |
1101 |
' LEFT JOIN cel_zones_geo AS zg '.
|
|
|
1102 |
" ON (zg.nom = co.zone_geo AND zg.id_zone_geo = co.ce_zone_geo) ".
|
2446 |
jpm |
1103 |
"WHERE co.transmission = '1' ".
|
938 |
jpm |
1104 |
$this->construireWhereCoordonnees().
|
|
|
1105 |
$this->construireWhereUtilisateur().
|
|
|
1106 |
$this->construireWhereNumTaxon().
|
|
|
1107 |
$this->construireWhereNomTaxon().
|
1497 |
aurelien |
1108 |
$this->construireWhereReferentiel().
|
938 |
jpm |
1109 |
$this->construireWhereProjet().
|
|
|
1110 |
(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
|
1339 |
aurelien |
1111 |
'ORDER BY utilisateur ASC, ci.ordre ASC';
|
938 |
jpm |
1112 |
//$this->debug[] = $requete;
|
|
|
1113 |
//die($requete);
|
2143 |
jpm |
1114 |
$elements_tag = Cel::db()->requeter($requete);
|
|
|
1115 |
|
938 |
jpm |
1116 |
$requete_tag = array();
|
|
|
1117 |
if ($elements_tag != false && count($elements_tag) > 0) {
|
2143 |
jpm |
1118 |
|
938 |
jpm |
1119 |
$filtres = array();
|
|
|
1120 |
foreach ($elements_tag as $occurence) {
|
|
|
1121 |
$utilisateur = $occurence['utilisateur'];
|
1339 |
aurelien |
1122 |
$id_obs = $occurence['id_obs'];
|
938 |
jpm |
1123 |
if (!array_key_exists($utilisateur, $filtres)) {
|
|
|
1124 |
$filtres[$utilisateur] = array();
|
|
|
1125 |
}
|
1339 |
aurelien |
1126 |
if (!array_key_exists($id_obs, $filtres[$utilisateur])) {
|
|
|
1127 |
$filtres[$utilisateur][$id_obs] = $id_obs;
|
938 |
jpm |
1128 |
}
|
|
|
1129 |
}
|
2143 |
jpm |
1130 |
|
938 |
jpm |
1131 |
// Pré-construction du where de la requête
|
1339 |
aurelien |
1132 |
$tpl_where = "(id_observation IN (%s))";
|
|
|
1133 |
foreach ($filtres as $utilisateur => $id_obs) {
|
|
|
1134 |
$requete_tag[] = sprintf($tpl_where, implode(',', $id_obs));
|
938 |
jpm |
1135 |
}
|
2143 |
jpm |
1136 |
|
938 |
jpm |
1137 |
} else {
|
|
|
1138 |
$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
|
|
|
1139 |
}
|
|
|
1140 |
if (count($requete_tag) > 0) {
|
|
|
1141 |
$sql = implode(" \nOR ", $requete_tag);
|
|
|
1142 |
}
|
489 |
jpm |
1143 |
}
|
938 |
jpm |
1144 |
return $sql;
|
478 |
jpm |
1145 |
}
|
2143 |
jpm |
1146 |
|
487 |
jpm |
1147 |
/**
|
938 |
jpm |
1148 |
* Traitement de $tag pour construction du filtre dans la requête
|
487 |
jpm |
1149 |
*/
|
938 |
jpm |
1150 |
private function getSqlWhereMotsCles($tag) {
|
|
|
1151 |
$sql = null;
|
940 |
jpm |
1152 |
$mots_cles = $this->decomposerParametreTag($tag);
|
1339 |
aurelien |
1153 |
$requete_projet = $this->getSqlWhereMotsClesImages($mots_cles);
|
|
|
1154 |
$sql = $requete_projet;
|
938 |
jpm |
1155 |
//$this->debug[] = $sql;
|
487 |
jpm |
1156 |
return $sql;
|
840 |
jpm |
1157 |
}
|
2143 |
jpm |
1158 |
|
938 |
jpm |
1159 |
/**
|
|
|
1160 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1161 |
*/
|
|
|
1162 |
private function getSqlWhereMotsClesImages($mots_cles_encodes) {
|
|
|
1163 |
$where_mots_cles_images = array();
|
1339 |
aurelien |
1164 |
foreach ($mots_cles_encodes['motsClesEncodesProteges'] as $mot_cle_encode) {
|
|
|
1165 |
$where_mots_cles_images[] = "ci.mots_cles_texte LIKE $mot_cle_encode";
|
938 |
jpm |
1166 |
}
|
1339 |
aurelien |
1167 |
$where_mots_cles_images = implode(' '.$mots_cles_encodes['type'].' ', $where_mots_cles_images);
|
938 |
jpm |
1168 |
return $where_mots_cles_images;
|
|
|
1169 |
}
|
2143 |
jpm |
1170 |
|
940 |
jpm |
1171 |
private function decomposerParametreTag($tags) {
|
2143 |
jpm |
1172 |
|
938 |
jpm |
1173 |
$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
|
|
|
1174 |
if (preg_match('/.+OU.+/', $tags)) {
|
|
|
1175 |
$mots_cles['type'] = 'OR';
|
|
|
1176 |
$mots_cles['motsCles'] = explode('OU', $tags);
|
|
|
1177 |
} else if (preg_match('/.+ET.+/', $tags)) {
|
|
|
1178 |
$mots_cles['type'] = 'AND';
|
|
|
1179 |
$mots_cles['motsCles'] = explode('ET', $tags);
|
|
|
1180 |
} else {
|
|
|
1181 |
$mots_cles['motsCles'][] = $tags;
|
|
|
1182 |
}
|
2143 |
jpm |
1183 |
|
938 |
jpm |
1184 |
foreach ($mots_cles['motsCles'] as $mot) {
|
1765 |
raphael |
1185 |
$mots_cles['motsClesEncodesProteges'][] = Cel::db()->quote('%'.$mot.'%');
|
938 |
jpm |
1186 |
}
|
|
|
1187 |
$this->debug[] = $mots_cles;
|
|
|
1188 |
return $mots_cles;
|
|
|
1189 |
}
|
1003 |
jpm |
1190 |
|
981 |
jpm |
1191 |
private function decomposerLatLng($coord) {
|
|
|
1192 |
$lat_lng = array();
|
|
|
1193 |
if (isset($coord)) {
|
|
|
1194 |
list($lat, $lng) = explode('|', $coord);
|
|
|
1195 |
$lat_lng = array('lat' => $lat, 'lng' => $lng);
|
|
|
1196 |
}
|
|
|
1197 |
return $lat_lng;
|
|
|
1198 |
}
|
1003 |
jpm |
1199 |
|
940 |
jpm |
1200 |
private function decomposerParametreStation() {
|
938 |
jpm |
1201 |
$station_infos = array();
|
|
|
1202 |
if (isset($this->parametres['station'])) {
|
|
|
1203 |
$station = $this->parametres['station'];
|
|
|
1204 |
$this->debug[] = $station;
|
1033 |
aurelien |
1205 |
@list($type, $coord) = explode(':', $station);
|
|
|
1206 |
@list($lat, $lng) = explode('|', $coord);
|
1003 |
jpm |
1207 |
|
954 |
jpm |
1208 |
$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
|
938 |
jpm |
1209 |
}
|
|
|
1210 |
return $station_infos;
|
|
|
1211 |
}
|
1003 |
jpm |
1212 |
|
940 |
jpm |
1213 |
private function decomposerParametreDate() {
|
1132 |
aurelien |
1214 |
$date_infos = array(null,null);
|
940 |
jpm |
1215 |
if (isset($this->parametres['date'])) {
|
|
|
1216 |
$date = $this->parametres['date'];
|
|
|
1217 |
if (strpos($date, ':')) {
|
|
|
1218 |
list($type, $date) = explode(':', $date);
|
|
|
1219 |
} else {
|
|
|
1220 |
$type = 'observation';
|
|
|
1221 |
}
|
1003 |
jpm |
1222 |
|
940 |
jpm |
1223 |
$date = str_replace('/', '-', $date);
|
|
|
1224 |
if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $date, $matches)) {
|
|
|
1225 |
$date = $matches[3].'-'.$matches[2].'-'.$matches[1];
|
|
|
1226 |
}
|
1003 |
jpm |
1227 |
|
940 |
jpm |
1228 |
$date_infos = array($type, $date);
|
|
|
1229 |
}
|
|
|
1230 |
return $date_infos;
|
|
|
1231 |
}
|
1003 |
jpm |
1232 |
|
940 |
jpm |
1233 |
private function decomposerParametreTaxon() {
|
1132 |
aurelien |
1234 |
$nom_infos = array(null,null);
|
940 |
jpm |
1235 |
if (isset($this->parametres['taxon'])) {
|
|
|
1236 |
$taxon = $this->parametres['taxon'];
|
|
|
1237 |
if (strpos($taxon, ':')) {
|
|
|
1238 |
$nom_infos = explode(':', $taxon);
|
|
|
1239 |
} else {
|
|
|
1240 |
$nom_infos = array('retenu', $taxon);
|
|
|
1241 |
}
|
|
|
1242 |
}
|
|
|
1243 |
return $nom_infos;
|
|
|
1244 |
}
|
1003 |
jpm |
1245 |
|
940 |
jpm |
1246 |
private function decomposerParametreCommentaire() {
|
1132 |
aurelien |
1247 |
$commentaire_infos = array(null,null);
|
940 |
jpm |
1248 |
if (isset($this->parametres['commentaire'])) {
|
|
|
1249 |
$commentaire = $this->parametres['commentaire'];
|
|
|
1250 |
if (strpos($commentaire, ':')) {
|
|
|
1251 |
$commentaire_infos = explode(':', $commentaire);
|
|
|
1252 |
} else {
|
|
|
1253 |
$commentaire_infos = array('observation', $commentaire);
|
|
|
1254 |
}
|
|
|
1255 |
}
|
|
|
1256 |
return $commentaire_infos;
|
|
|
1257 |
}
|
1172 |
aurelien |
1258 |
}
|
|
|
1259 |
?>
|