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