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