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