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