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) {
|
1003 |
jpm |
93 |
|
1148 |
aurelien |
94 |
$emplacements = null;
|
1399 |
aurelien |
95 |
$concatenation_id = "CONCAT(IFNULL(latitude,''),IFNULL(longitude,''), IFNULL(wgs84_latitude,''),IFNULL(wgs84_longitude,'')) ";
|
1092 |
aurelien |
96 |
|
1466 |
aurelien |
97 |
$requete = 'SELECT ce_zone_geo, zone_geo, station, '.
|
1148 |
aurelien |
98 |
"mots_cles_texte, ".
|
1339 |
aurelien |
99 |
"latitude, ".
|
1148 |
aurelien |
100 |
"wgs84_latitude, ".
|
1339 |
aurelien |
101 |
"longitude, ".
|
1148 |
aurelien |
102 |
"wgs84_longitude, ".
|
|
|
103 |
$concatenation_id." as id_coord ".
|
1339 |
aurelien |
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) '.
|
981 |
jpm |
107 |
"WHERE transmission = '1' ".
|
1003 |
jpm |
108 |
" AND (".
|
1148 |
aurelien |
109 |
$this->construireWhereRectangleStationOR()." OR ".
|
|
|
110 |
$this->construireWhereRectangleCommuneOR().") ".
|
981 |
jpm |
111 |
$this->construireWhereDept().
|
|
|
112 |
$this->construireWhereCommune().
|
|
|
113 |
$this->construireWhereUtilisateur().
|
|
|
114 |
$this->construireWhereNumTaxon().
|
|
|
115 |
$this->construireWhereNomTaxon().
|
1497 |
aurelien |
116 |
$this->construireWhereReferentiel().
|
981 |
jpm |
117 |
$this->construireWhereDate().
|
|
|
118 |
$this->construireWhereCommentaire().
|
1466 |
aurelien |
119 |
$this->construireWherePhotosSeulement().
|
981 |
jpm |
120 |
$this->construireWhereProjet().
|
1484 |
aurelien |
121 |
$this->construireWhereTag().
|
|
|
122 |
$this->construireWhereNombreDeJours().
|
|
|
123 |
' GROUP BY id_coord';
|
1466 |
aurelien |
124 |
|
1106 |
aurelien |
125 |
$resultats_emplacements = $this->executerRequete($requete);
|
|
|
126 |
$emplacements = $this->traiterEmplacements($resultats_emplacements, $this->compterObservations($params));
|
|
|
127 |
return $emplacements;
|
981 |
jpm |
128 |
}
|
1092 |
aurelien |
129 |
|
|
|
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 '.
|
1339 |
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) '.
|
1039 |
aurelien |
144 |
"WHERE transmission = '1' ".
|
1172 |
aurelien |
145 |
" AND (".
|
|
|
146 |
$this->construireWhereRectangleStationOR()." OR ".
|
|
|
147 |
$this->construireWhereRectangleCommuneOR().") ".
|
1039 |
aurelien |
148 |
$this->construireWhereDept().
|
|
|
149 |
$this->construireWhereCommune().
|
|
|
150 |
$this->construireWhereUtilisateur().
|
|
|
151 |
$this->construireWhereNumTaxon().
|
|
|
152 |
$this->construireWhereNomTaxon().
|
1497 |
aurelien |
153 |
$this->construireWhereReferentiel().
|
1039 |
aurelien |
154 |
$this->construireWhereDate().
|
|
|
155 |
$this->construireWhereCommentaire().
|
1466 |
aurelien |
156 |
$this->construireWherePhotosSeulement().
|
1039 |
aurelien |
157 |
$this->construireWhereProjet().
|
1484 |
aurelien |
158 |
$this->construireWhereTag().
|
|
|
159 |
$this->construireWhereNombreDeJours();
|
1339 |
aurelien |
160 |
//echo $requete;exit;
|
1039 |
aurelien |
161 |
$resultats_nb_obs = $this->executerRequete($requete);
|
|
|
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']);
|
|
|
252 |
$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree(&$points, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
|
|
|
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 |
}
|
1466 |
aurelien |
307 |
|
1165 |
aurelien |
308 |
private function communeEstDemandee() {
|
|
|
309 |
$station_infos = $this->decomposerParametreStation();
|
|
|
310 |
$commune_demandee = true;
|
|
|
311 |
if($station_infos['type'] == self::MARQUEUR_STATION) {
|
|
|
312 |
$commune_demandee = false;
|
|
|
313 |
}
|
|
|
314 |
return $commune_demandee;
|
|
|
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, '.
|
|
|
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 '.
|
|
|
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) ".
|
938 |
jpm |
331 |
"WHERE transmission = '1' ".
|
1165 |
aurelien |
332 |
(($this->communeEstDemandee()) ? $this->construireWhereCommuneSansCoordonneesAvecSensibles() : $this->construireWhereCoordonneesSansSensibles()).
|
1148 |
aurelien |
333 |
$this->construireWhereDept().
|
938 |
jpm |
334 |
$this->construireWhereUtilisateur().
|
|
|
335 |
$this->construireWhereNumTaxon().
|
|
|
336 |
$this->construireWhereNomTaxon().
|
1497 |
aurelien |
337 |
$this->construireWhereReferentiel().
|
938 |
jpm |
338 |
$this->construireWhereDate().
|
940 |
jpm |
339 |
$this->construireWhereCommentaire().
|
1466 |
aurelien |
340 |
$this->construireWherePhotosSeulement().
|
938 |
jpm |
341 |
$this->construireWhereProjet().
|
|
|
342 |
$this->construireWhereTag().
|
1484 |
aurelien |
343 |
$this->construireWhereNombreDeJours().
|
938 |
jpm |
344 |
'ORDER BY nom_sel ASC '.
|
|
|
345 |
"LIMIT {$this->start},{$this->limit} ";
|
1339 |
aurelien |
346 |
//echo $requete;exit;
|
938 |
jpm |
347 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
|
|
348 |
$requete = 'SELECT FOUND_ROWS()';
|
|
|
349 |
$total = (int) $this->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;
|
|
|
376 |
$observation['urlEflore'] = $this->getUrlEflore($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 getUrlEflore($nn) {
|
|
|
392 |
$urlEflore = null;
|
|
|
393 |
if (! $this->etreNull($nn)) {
|
|
|
394 |
$urlEflore = sprintf($this->config['settings']['efloreUrlTpl'], $nn, 'illustration');
|
|
|
395 |
}
|
|
|
396 |
return $urlEflore;
|
|
|
397 |
}
|
1003 |
jpm |
398 |
|
938 |
jpm |
399 |
private function traiterLieu($donnee) {
|
|
|
400 |
$lieu = array();
|
|
|
401 |
if (!$this->etreNull($donnee->lieudit)) {
|
|
|
402 |
$lieu[] = $donnee->lieudit;
|
|
|
403 |
}
|
|
|
404 |
if (!$this->etreNull($donnee->milieu)) {
|
|
|
405 |
$lieu[] = $donnee->milieu;
|
|
|
406 |
}
|
|
|
407 |
return implode(', ', $lieu);
|
|
|
408 |
}
|
1003 |
jpm |
409 |
|
938 |
jpm |
410 |
private function chargerImages(Array $obs_ids) {
|
|
|
411 |
// Récupération des données au format Json
|
|
|
412 |
$service = 'CelImage/liste-ids?obsId='.implode(',', $obs_ids);
|
|
|
413 |
$url = sprintf($this->config['settings']['baseURLServicesCelTpl'], $service);
|
|
|
414 |
$json = $this->getRestClient()->consulter($url);
|
|
|
415 |
$donnees = json_decode($json);
|
1003 |
jpm |
416 |
|
938 |
jpm |
417 |
// Post-traitement des données
|
|
|
418 |
$images = $this->traiterImages($donnees);
|
1003 |
jpm |
419 |
|
938 |
jpm |
420 |
return $images;
|
474 |
jpm |
421 |
}
|
1003 |
jpm |
422 |
|
938 |
jpm |
423 |
private function traiterImages($donnees) {
|
|
|
424 |
$images = array();
|
|
|
425 |
if (count($donnees) > 0) {
|
|
|
426 |
foreach ($donnees as $id_obs => $id_images) {
|
|
|
427 |
foreach ($id_images as $id_img) {
|
|
|
428 |
$urls['idImg'] = $id_img;
|
|
|
429 |
$urls['guid'] = sprintf($this->config['settings']['guidImgTpl'], $id_img);
|
|
|
430 |
$urls['miniature'] = $this->getUrlImage($id_img, 'CXS');
|
|
|
431 |
$urls['normale'] = $this->getUrlImage($id_img, 'XL');
|
|
|
432 |
$images[$id_obs][] = $urls;
|
1003 |
jpm |
433 |
}
|
938 |
jpm |
434 |
}
|
|
|
435 |
}
|
|
|
436 |
return $images;
|
|
|
437 |
}
|
1003 |
jpm |
438 |
|
938 |
jpm |
439 |
private function ajouterImagesAuxObs($observations) {
|
|
|
440 |
$images = $this->chargerImages(array_keys($observations['observations']));
|
|
|
441 |
foreach ($observations['observations'] as $id => $infos) {
|
1043 |
aurelien |
442 |
if(isset($images[$id])) {
|
|
|
443 |
$infos['images'] = $images[$id];
|
|
|
444 |
$observations['observations'][$id] = $infos;
|
|
|
445 |
}
|
938 |
jpm |
446 |
}
|
|
|
447 |
return $observations;
|
|
|
448 |
}
|
1339 |
aurelien |
449 |
|
938 |
jpm |
450 |
private function ajouterAuteursAuxObs($observations) {
|
944 |
jpm |
451 |
$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
|
938 |
jpm |
452 |
unset($observations['observateurs']);
|
|
|
453 |
foreach ($observations['observations'] as $id => $infos) {
|
1482 |
aurelien |
454 |
$courriel = strtolower($infos['observateur']);
|
1339 |
aurelien |
455 |
if(isset($observateurs[$courriel])) {
|
|
|
456 |
$infos['observateur'] = $observateurs[$courriel]['intitule'];
|
|
|
457 |
$infos['observateurId'] = $observateurs[$courriel]['id'];
|
|
|
458 |
}
|
938 |
jpm |
459 |
$observations['observations'][$id] = $infos;
|
|
|
460 |
}
|
|
|
461 |
return $observations;
|
|
|
462 |
}
|
1003 |
jpm |
463 |
|
938 |
jpm |
464 |
private function supprimerIdDesObs($observations) {
|
|
|
465 |
// Le tableau de sortie ne doit pas avoir les id des obs en clé car sinon Jquery Template ne fonctionne pas
|
|
|
466 |
$observationSansId = $observations;
|
|
|
467 |
unset($observationSansId['observations']);
|
|
|
468 |
foreach ($observations['observations'] as $id => $infos) {
|
|
|
469 |
$observationSansId['observations'][] = $infos;
|
|
|
470 |
}
|
|
|
471 |
return $observationSansId;
|
|
|
472 |
}
|
1003 |
jpm |
473 |
|
478 |
jpm |
474 |
/**
|
938 |
jpm |
475 |
* Liste des taxons présents sur la carte
|
840 |
jpm |
476 |
*/
|
938 |
jpm |
477 |
public function getTaxons($params) {
|
840 |
jpm |
478 |
$json = null;
|
1003 |
jpm |
479 |
|
1339 |
aurelien |
480 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, nom_ret_nn, nt, famille '.
|
|
|
481 |
'FROM cel_obs AS co '.
|
|
|
482 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
483 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
840 |
jpm |
484 |
"WHERE transmission = '1' ".
|
938 |
jpm |
485 |
" AND nom_ret != '' ".
|
|
|
486 |
$this->construireWhereDept().
|
|
|
487 |
$this->construireWhereCommune().
|
|
|
488 |
$this->construireWhereUtilisateur().
|
|
|
489 |
$this->construireWhereNumTaxon().
|
|
|
490 |
$this->construireWhereNomTaxon().
|
1497 |
aurelien |
491 |
$this->construireWhereReferentiel().
|
938 |
jpm |
492 |
$this->construireWhereDate().
|
940 |
jpm |
493 |
$this->construireWhereCommentaire().
|
1466 |
aurelien |
494 |
$this->construireWherePhotosSeulement().
|
938 |
jpm |
495 |
$this->construireWhereProjet().
|
981 |
jpm |
496 |
$this->construireWhereTag().
|
1484 |
aurelien |
497 |
$this->construireWhereNombreDeJours().
|
938 |
jpm |
498 |
'ORDER BY nom_ret ASC '.
|
|
|
499 |
"LIMIT {$this->start},{$this->limit} ";
|
|
|
500 |
//$this->debug[] = $requete;
|
|
|
501 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
1339 |
aurelien |
502 |
//echo $requete;exit;
|
938 |
jpm |
503 |
$requete = 'SELECT FOUND_ROWS()';
|
|
|
504 |
$taxons['total'] = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
|
1003 |
jpm |
505 |
|
938 |
jpm |
506 |
// Post-traitement
|
|
|
507 |
$taxons['taxons'] = $this->traiterTaxons($resultats);
|
1003 |
jpm |
508 |
|
938 |
jpm |
509 |
return $taxons;
|
840 |
jpm |
510 |
}
|
1003 |
jpm |
511 |
|
938 |
jpm |
512 |
private function traiterTaxons($donnees) {
|
|
|
513 |
$taxons = array();
|
|
|
514 |
if (is_array($donnees) && count($donnees) > 0) {
|
|
|
515 |
foreach ($donnees as $donnee) {
|
1339 |
aurelien |
516 |
if (!isset($taxons[$donnee->nt]) && ! $this->etreNull($donnee->nom_ret)) {
|
938 |
jpm |
517 |
$taxon = array();
|
1339 |
aurelien |
518 |
$taxon['nn'] = $donnee->nom_ret_nn;
|
|
|
519 |
$taxon['nt'] = $donnee->nt;
|
938 |
jpm |
520 |
$taxon['nom'] = $this->nettoyerTexte($donnee->nom_ret);
|
|
|
521 |
$taxon['famille'] = $this->nettoyerTexte($donnee->famille);
|
1339 |
aurelien |
522 |
$taxons[$donnee->nt] = $taxon;
|
938 |
jpm |
523 |
}
|
|
|
524 |
}
|
|
|
525 |
}
|
|
|
526 |
$taxons = array_values($taxons);
|
|
|
527 |
return $taxons;
|
|
|
528 |
}
|
1003 |
jpm |
529 |
|
938 |
jpm |
530 |
private function construireWhereCoordonnees() {
|
|
|
531 |
$sql = '';
|
|
|
532 |
// Récupération des coordonnées depuis l'id station
|
940 |
jpm |
533 |
extract($this->decomposerParametreStation());
|
938 |
jpm |
534 |
if (isset($type)) {
|
981 |
jpm |
535 |
if ($type == self::MARQUEUR_COMMUNE) {
|
1341 |
aurelien |
536 |
$lat = $this->proteger($lat.'%');
|
|
|
537 |
$lng = $this->proteger($lng.'%');
|
|
|
538 |
$sql = " AND wgs84_latitude LIKE $lat AND wgs84_longitude LIKE $lng ";
|
981 |
jpm |
539 |
} else if ($type == self::MARQUEUR_STATION) {
|
1339 |
aurelien |
540 |
$lat = $this->proteger($lat.'%');
|
|
|
541 |
$lng = $this->proteger($lng.'%');
|
|
|
542 |
$sql = " AND (latitude LIKE $lat AND longitude LIKE $lng) ";
|
938 |
jpm |
543 |
}
|
1003 |
jpm |
544 |
}
|
938 |
jpm |
545 |
return $sql;
|
|
|
546 |
}
|
1092 |
aurelien |
547 |
|
|
|
548 |
private function construireWhereCoordonneesSansSensibles() {
|
|
|
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 = $this->proteger($lat);
|
|
|
555 |
$lng = $this->proteger($lng);
|
1341 |
aurelien |
556 |
$sql = " AND wgs84_latitude LIKE $lat AND wgs84_longitude LIKE $lng ";
|
1092 |
aurelien |
557 |
} else if ($type == self::MARQUEUR_STATION) {
|
1339 |
aurelien |
558 |
$lat = $this->proteger($lat.'%');
|
|
|
559 |
$lng = $this->proteger($lng.'%');
|
|
|
560 |
$sql = " AND (latitude LIKE $lat AND longitude LIKE $lng) ";
|
1092 |
aurelien |
561 |
}
|
|
|
562 |
}
|
1165 |
aurelien |
563 |
$sql .= ' AND (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE "%sensible%" ) ';
|
1092 |
aurelien |
564 |
return $sql;
|
|
|
565 |
}
|
1003 |
jpm |
566 |
|
940 |
jpm |
567 |
private function construireWhereCommentaire() {
|
|
|
568 |
$sql = '';
|
|
|
569 |
list($type, $commentaire) = $this->decomposerParametreCommentaire();
|
|
|
570 |
if (!$this->etreNull($commentaire)) {
|
|
|
571 |
$commentaire = $this->proteger('%'.$commentaire.'%');
|
|
|
572 |
switch ($type) {
|
|
|
573 |
case '*' :
|
|
|
574 |
$sql = $this->obtenirConditionPourCommentaires($commentaire);
|
|
|
575 |
$sql = " AND (commentaire LIKE $commentaire OR ($sql)) ";
|
|
|
576 |
break;
|
|
|
577 |
case 'observation' :
|
|
|
578 |
$sql = " AND commentaire LIKE $commentaire ";
|
|
|
579 |
break;
|
|
|
580 |
case 'photo' :
|
|
|
581 |
$sql = ' AND '.$this->obtenirConditionPourCommentaires($commentaire).' ';
|
|
|
582 |
break;
|
|
|
583 |
case 'photo.meta' :
|
|
|
584 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireMeta($commentaire).' ';
|
|
|
585 |
break;
|
|
|
586 |
case 'photo.utilisateur' :
|
|
|
587 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireUtilisateur($commentaire).' ';
|
|
|
588 |
break;
|
|
|
589 |
default:
|
|
|
590 |
$sql = " AND commentaire LIKE $commentaire ";
|
1003 |
jpm |
591 |
}
|
940 |
jpm |
592 |
}
|
|
|
593 |
return $sql;
|
|
|
594 |
}
|
1003 |
jpm |
595 |
|
|
|
596 |
|
938 |
jpm |
597 |
private function construireWhereNomTaxon() {
|
|
|
598 |
$sql = '';
|
940 |
jpm |
599 |
list($type, $nom) = $this->decomposerParametreTaxon();
|
|
|
600 |
if (!$this->etreNull($nom)) {
|
938 |
jpm |
601 |
$nom = $this->proteger($nom.'%');
|
|
|
602 |
switch ($type) {
|
|
|
603 |
case '*' :
|
|
|
604 |
$sql = " AND (nom_ret LIKE $nom OR nom_sel LIKE $nom OR famille LIKE $nom) ";
|
|
|
605 |
break;
|
940 |
jpm |
606 |
case 'retenu' :
|
938 |
jpm |
607 |
$sql = " AND nom_ret LIKE $nom ";
|
|
|
608 |
break;
|
940 |
jpm |
609 |
case 'selectionne' :
|
938 |
jpm |
610 |
$sql = " AND nom_sel LIKE $nom ";
|
|
|
611 |
break;
|
940 |
jpm |
612 |
case 'famille' :
|
938 |
jpm |
613 |
$sql = " AND famille LIKE $nom ";
|
|
|
614 |
break;
|
|
|
615 |
default:
|
|
|
616 |
$sql = " AND nom_ret LIKE $nom ";
|
1003 |
jpm |
617 |
}
|
938 |
jpm |
618 |
}
|
|
|
619 |
return $sql;
|
|
|
620 |
}
|
1497 |
aurelien |
621 |
|
|
|
622 |
private function construireWhereReferentiel() {
|
|
|
623 |
$sql = '';
|
|
|
624 |
extract($this->parametres);
|
|
|
625 |
if (isset($referentiel) && !$this->etreNull($referentiel)) {
|
|
|
626 |
$referentiel = $this->proteger($referentiel.'%');
|
|
|
627 |
$sql = ' AND co.nom_referentiel LIKE '.$referentiel.' ';
|
|
|
628 |
}
|
|
|
629 |
return $sql;
|
|
|
630 |
}
|
1003 |
jpm |
631 |
|
938 |
jpm |
632 |
private function construireWhereDate() {
|
|
|
633 |
$sql = '';
|
|
|
634 |
// Récupération des coordonnées depuis l'id station
|
940 |
jpm |
635 |
list($type, $date) = $this->decomposerParametreDate();
|
1003 |
jpm |
636 |
|
938 |
jpm |
637 |
if (!$this->etreNull($date)) {
|
|
|
638 |
$date = $this->proteger($date.'%');
|
|
|
639 |
switch ($type) {
|
|
|
640 |
case '*' :
|
|
|
641 |
$sql = " AND (
|
1003 |
jpm |
642 |
date_observation LIKE $date
|
|
|
643 |
OR date_creation LIKE $date
|
|
|
644 |
OR date_modification LIKE $date
|
938 |
jpm |
645 |
OR date_transmission LIKE $date) ";
|
|
|
646 |
break;
|
|
|
647 |
case 'observation' :
|
|
|
648 |
$sql = " AND date_observation LIKE $date ";
|
|
|
649 |
break;
|
|
|
650 |
case 'creation' :
|
|
|
651 |
$sql = " AND date_creation LIKE $date ";
|
|
|
652 |
break;
|
|
|
653 |
case 'modification' :
|
|
|
654 |
$sql = " AND date_modification LIKE $date ";
|
|
|
655 |
break;
|
|
|
656 |
case 'transmission' :
|
|
|
657 |
$sql = " AND date_transmission LIKE $date ";
|
|
|
658 |
break;
|
940 |
jpm |
659 |
case 'photo' :
|
|
|
660 |
$sql = $this->obtenirConditionPourDatePhoto($date);
|
|
|
661 |
break;
|
|
|
662 |
case 'ajout' :
|
|
|
663 |
$sql = $this->obtenirConditionPourDateAjout($date);
|
|
|
664 |
break;
|
938 |
jpm |
665 |
case 'liaison' :
|
940 |
jpm |
666 |
$sql = $this->obtenirConditionPourDateLiaison($date);
|
938 |
jpm |
667 |
break;
|
|
|
668 |
default:
|
|
|
669 |
$sql = " AND date_observation LIKE $date ";
|
|
|
670 |
}
|
|
|
671 |
}
|
|
|
672 |
return $sql;
|
|
|
673 |
}
|
1003 |
jpm |
674 |
|
940 |
jpm |
675 |
private function obtenirConditionPourDatePhoto($date) {
|
|
|
676 |
$observations = $this->obtenirObsLieesImg('date.photo', $date);
|
|
|
677 |
if (is_null($observations)) {
|
|
|
678 |
$this->debug[] = "Aucune observation n'est liée à une photo prise à la date : $date";
|
|
|
679 |
}
|
|
|
680 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
681 |
return $sql;
|
|
|
682 |
}
|
1003 |
jpm |
683 |
|
940 |
jpm |
684 |
private function obtenirConditionPourDateLiaison($date) {
|
|
|
685 |
$observations = $this->obtenirObsLieesImg('date.liaison', $date);
|
|
|
686 |
if (is_null($observations)) {
|
|
|
687 |
$this->debug[] = "Aucune observation n'a été liée à une image à à la date : $date";
|
|
|
688 |
}
|
|
|
689 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
690 |
return $sql;
|
|
|
691 |
}
|
|
|
692 |
|
|
|
693 |
private function obtenirConditionPourDateAjout($date) {
|
|
|
694 |
$observations = $this->obtenirObsLieesImg('date.ajout', $date);
|
|
|
695 |
if (is_null($observations)) {
|
|
|
696 |
$this->debug[] = "Aucune observation n'est liée à une image ajoutée à la date : $date";
|
|
|
697 |
}
|
|
|
698 |
$sql = $this->assemblerObsEnConditionSql($observations);
|
|
|
699 |
return $sql;
|
|
|
700 |
}
|
1003 |
jpm |
701 |
|
940 |
jpm |
702 |
private function obtenirConditionPourCommentaireMeta($commentaire) {
|
|
|
703 |
$observations = $this->obtenirObsLieesImg('commentaire.meta', $commentaire);
|
|
|
704 |
if (is_null($observations)) {
|
|
|
705 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des méta-données correspond à : $commmentaire";
|
|
|
706 |
}
|
|
|
707 |
$operateur = '';
|
|
|
708 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
709 |
return $sql;
|
|
|
710 |
}
|
1003 |
jpm |
711 |
|
940 |
jpm |
712 |
private function obtenirConditionPourCommentaireUtilisateur($commentaire) {
|
|
|
713 |
$observations = $this->obtenirObsLieesImg('commentaire.utilisateur', $commentaire);
|
|
|
714 |
if (is_null($observations)) {
|
|
|
715 |
$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des utilisateur correspond à : $commmentaire";
|
|
|
716 |
}
|
|
|
717 |
$operateur = '';
|
|
|
718 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
719 |
return $sql;
|
|
|
720 |
}
|
1003 |
jpm |
721 |
|
940 |
jpm |
722 |
private function obtenirConditionPourCommentaires($commentaire) {
|
|
|
723 |
$observations = $this->obtenirObsLieesImg('commentaire.*', $commentaire);
|
|
|
724 |
if (is_null($observations)) {
|
|
|
725 |
$this->debug[] = "Aucune observation n'est liée à une image dont un des commentaires correspond à : $commmentaire";
|
|
|
726 |
}
|
|
|
727 |
$operateur = '';
|
|
|
728 |
$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
|
|
|
729 |
return $sql;
|
|
|
730 |
}
|
1003 |
jpm |
731 |
|
940 |
jpm |
732 |
/**
|
|
|
733 |
* Récupération des identifiant d'utilisateur et des ordres des observations correspondant à une date.
|
|
|
734 |
* Retour sous forme de tableau : array[identifiant] = array(ordre, ordre...);
|
|
|
735 |
*/
|
|
|
736 |
private function obtenirObsLieesImg($type, $param) {
|
|
|
737 |
// Construction de la requête
|
1339 |
aurelien |
738 |
$requete = 'SELECT DISTINCT co.id_obs, ci.ce_utilisateur AS utilisateur '.
|
940 |
jpm |
739 |
'FROM cel_images '.
|
1339 |
aurelien |
740 |
' LEFT JOIN cel_obs_images coi '.
|
|
|
741 |
' ON (ci.id_image = coi.id_image) '.
|
|
|
742 |
' LEFT JOIN cel_obs AS co '.
|
|
|
743 |
' ON (coi.id_observation = co.id_observation) '.
|
|
|
744 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
745 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
940 |
jpm |
746 |
"WHERE transmission = '1' ".
|
|
|
747 |
($type == 'date.photo' ? " AND (ci_meta_date_time LIKE ".str_replace('-', ':', $param)." OR ci_meta_date LIKE $param) " : '').
|
|
|
748 |
($type == 'date.ajout' ? " AND ci_meta_date_ajout LIKE $param " : '').
|
|
|
749 |
($type == 'date.liaison' ? " AND coi_date_liaison LIKE $param " : '').
|
|
|
750 |
($type == 'commentaire.meta' ? " AND ci_meta_comment LIKE $param " : '').
|
|
|
751 |
($type == 'commentaire.utilisateur' ? " AND ci_meta_user_comment LIKE $param " : '').
|
|
|
752 |
($type == 'commentaire.*' ? " AND (ci_meta_comment LIKE $param OR ci_meta_user_comment LIKE $param) " : '').
|
1003 |
jpm |
753 |
$this->construireWhereCoordonnees().
|
940 |
jpm |
754 |
$this->construireWhereDept().
|
|
|
755 |
$this->construireWhereCommune().
|
|
|
756 |
$this->construireWhereUtilisateur().
|
|
|
757 |
$this->construireWhereNumTaxon().
|
|
|
758 |
$this->construireWhereNomTaxon().
|
1497 |
aurelien |
759 |
$this->construireWhereReferentiel().
|
940 |
jpm |
760 |
$this->construireWhereProjet().
|
|
|
761 |
$this->construireWhereTag().
|
|
|
762 |
'ORDER BY utilisateur ASC, ordre ASC';
|
|
|
763 |
//$this->debug[] = $requete;
|
|
|
764 |
//die($requete);
|
|
|
765 |
$resultats = $this->executerRequete($requete);
|
1003 |
jpm |
766 |
|
940 |
jpm |
767 |
$observations = null;
|
|
|
768 |
if ($resultats != false) {
|
|
|
769 |
$observations = array();
|
|
|
770 |
foreach ($resultats as $occurence) {
|
|
|
771 |
$utilisateur = $occurence['utilisateur'];
|
|
|
772 |
$ordre = $occurence['ordre'];
|
|
|
773 |
if (!array_key_exists($utilisateur, $observations)) {
|
|
|
774 |
$observations[$utilisateur] = array();
|
|
|
775 |
}
|
|
|
776 |
if (!array_key_exists($ordre, $observations[$utilisateur])) {
|
|
|
777 |
$observations[$utilisateur][$ordre] = $ordre;
|
|
|
778 |
}
|
|
|
779 |
}
|
|
|
780 |
}
|
|
|
781 |
return $observations;
|
|
|
782 |
}
|
1003 |
jpm |
783 |
|
940 |
jpm |
784 |
private function assemblerObsEnConditionSql($observations, $operateur = 'AND') {
|
|
|
785 |
$sql = '';
|
|
|
786 |
if ($observations != null) {
|
|
|
787 |
// Pré-construction du where de la requête
|
|
|
788 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
|
|
789 |
foreach ($observations as $utilisateur => $ordres) {
|
|
|
790 |
$morceaux_requete[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
|
|
791 |
}
|
|
|
792 |
if (count($morceaux_requete) > 0) {
|
|
|
793 |
$sql = implode(" \nOR ", $morceaux_requete);
|
|
|
794 |
}
|
|
|
795 |
} else {
|
|
|
796 |
// Nous voulons que la requête ne retourne rien
|
|
|
797 |
$sql = "identifiant = '' AND ordre = ''";
|
|
|
798 |
}
|
|
|
799 |
$sql = " $operateur ($sql) ";
|
|
|
800 |
return $sql;
|
|
|
801 |
}
|
1003 |
jpm |
802 |
|
981 |
jpm |
803 |
private function construireWhereRectangleStation() {
|
|
|
804 |
$sql = '';
|
1132 |
aurelien |
805 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
806 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
807 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
808 |
|
981 |
jpm |
809 |
$latMin = $sw['lat'];
|
|
|
810 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
811 |
|
981 |
jpm |
812 |
$latMax = $ne['lat'];
|
|
|
813 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
814 |
|
1339 |
aurelien |
815 |
// ATTENTION : latitude correspond bien à la LATITUDE!
|
|
|
816 |
$sql = " AND (latitude != 0 AND longitude != 0) ".
|
|
|
817 |
" AND latitude > $latMin ".
|
|
|
818 |
" AND latitude < $latMax ".
|
|
|
819 |
" AND longitude > $lngMin ".
|
|
|
820 |
" AND longitude < $lngMax ";
|
981 |
jpm |
821 |
}
|
|
|
822 |
return $sql;
|
|
|
823 |
}
|
1003 |
jpm |
824 |
|
981 |
jpm |
825 |
private function construireWhereRectangleStationOR() {
|
|
|
826 |
$sql = '';
|
1132 |
aurelien |
827 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
828 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
829 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
830 |
|
981 |
jpm |
831 |
$latMin = $sw['lat'];
|
|
|
832 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
833 |
|
981 |
jpm |
834 |
$latMax = $ne['lat'];
|
|
|
835 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
836 |
|
1339 |
aurelien |
837 |
$sql = "( (latitude != 0 AND longitude != 0) ".
|
1466 |
aurelien |
838 |
" AND latitude BETWEEN $latMin AND $latMax ".
|
|
|
839 |
" AND longitude BETWEEN $lngMin AND $lngMax )";
|
|
|
840 |
|
|
|
841 |
/*$sql = " MBRWithin(mon_point, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
|
|
|
842 |
$latMax.' '.$lngMin.','.
|
|
|
843 |
$latMax.' '.$lngMax.','.
|
|
|
844 |
$latMax.' '.$lngMin.','.
|
|
|
845 |
$latMin.' '.$lngMin."))')) "; */
|
981 |
jpm |
846 |
}
|
|
|
847 |
return $sql;
|
|
|
848 |
}
|
1003 |
jpm |
849 |
|
981 |
jpm |
850 |
private function construireWhereRectangleCommune() {
|
|
|
851 |
$sql = '';
|
1132 |
aurelien |
852 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
853 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
854 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
855 |
|
981 |
jpm |
856 |
$latMin = $sw['lat'];
|
|
|
857 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
858 |
|
981 |
jpm |
859 |
$latMax = $ne['lat'];
|
|
|
860 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
861 |
|
|
|
862 |
$sql = "AND wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
1466 |
aurelien |
863 |
" AND wgs84_latitude BETWEEN $latMin AND $latMax ".
|
|
|
864 |
" AND wgs84_longitude BETWEEN $lngMin AND $lngMax ";
|
981 |
jpm |
865 |
}
|
|
|
866 |
return $sql;
|
|
|
867 |
}
|
1003 |
jpm |
868 |
|
981 |
jpm |
869 |
private function construireWhereRectangleCommuneOR() {
|
|
|
870 |
$sql = '';
|
1132 |
aurelien |
871 |
if (isset($this->parametres['ne']) && isset($this->parametres['sw']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
|
981 |
jpm |
872 |
$ne = $this->decomposerLatLng($this->parametres['ne']);
|
|
|
873 |
$sw = $this->decomposerLatLng($this->parametres['sw']);
|
1003 |
jpm |
874 |
|
981 |
jpm |
875 |
$latMin = $sw['lat'];
|
|
|
876 |
$lngMin = $sw['lng'];
|
1003 |
jpm |
877 |
|
981 |
jpm |
878 |
$latMax = $ne['lat'];
|
|
|
879 |
$lngMax = $ne['lng'];
|
1003 |
jpm |
880 |
|
|
|
881 |
$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
|
1466 |
aurelien |
882 |
" AND wgs84_latitude BETWEEN $latMin AND $latMax ".
|
|
|
883 |
" AND wgs84_longitude BETWEEN $lngMin AND $lngMax )";
|
|
|
884 |
|
|
|
885 |
/*$sql = " MBRWithin(point_commune, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
|
|
|
886 |
$latMax.' '.$lngMin.','.
|
|
|
887 |
$latMax.' '.$lngMax.','.
|
|
|
888 |
$latMax.' '.$lngMin.','.
|
|
|
889 |
$latMin.' '.$lngMin."))')) ";*/
|
981 |
jpm |
890 |
}
|
|
|
891 |
return $sql;
|
|
|
892 |
}
|
1003 |
jpm |
893 |
|
938 |
jpm |
894 |
private function construireWhereDept() {
|
|
|
895 |
$sql = '';
|
|
|
896 |
// Récupération des coordonnées depuis l'id station
|
|
|
897 |
extract($this->parametres);
|
1339 |
aurelien |
898 |
if (isset($dept) && !$this->etreNull($dept)) {
|
|
|
899 |
$valeurs_a_proteger = explode(',',trim($dept));
|
|
|
900 |
foreach ($valeurs_a_proteger as $valeur) {
|
|
|
901 |
$valeurs_protegees[] = '(ce_zone_geo LIKE '.$this->bdd->quote('INSEE-C:'.$valeur.'%').') ';
|
|
|
902 |
}
|
|
|
903 |
$valeurs = implode(' OR ', $valeurs_protegees);
|
|
|
904 |
$sql = " AND ($valeurs) ";
|
938 |
jpm |
905 |
}
|
|
|
906 |
return $sql;
|
|
|
907 |
}
|
1003 |
jpm |
908 |
|
938 |
jpm |
909 |
private function construireWhereCommune() {
|
|
|
910 |
$sql = '';
|
|
|
911 |
// Récupération des coordonnées depuis l'id station
|
|
|
912 |
extract($this->parametres);
|
1132 |
aurelien |
913 |
if (isset($this->parametres['commune']) && !$this->etreNull($commune)) {
|
938 |
jpm |
914 |
$commune = $this->proteger($commune);
|
1339 |
aurelien |
915 |
$sql = " AND zone_geo LIKE $commune ";
|
938 |
jpm |
916 |
}
|
|
|
917 |
return $sql;
|
|
|
918 |
}
|
1003 |
jpm |
919 |
|
1092 |
aurelien |
920 |
private function construireWhereCommuneSansCoordonneesAvecSensibles() {
|
1043 |
aurelien |
921 |
$sql = '';
|
|
|
922 |
// Récupération des coordonnées depuis l'id station
|
|
|
923 |
extract($this->parametres);
|
1132 |
aurelien |
924 |
if (isset($this->parametres['commune']) && !$this->etreNull($commune)) {
|
1043 |
aurelien |
925 |
$commune = $this->proteger($commune);
|
1339 |
aurelien |
926 |
$sql = " AND zone_geo LIKE $commune ";
|
1092 |
aurelien |
927 |
$sql .= " AND (
|
|
|
928 |
(
|
1411 |
aurelien |
929 |
(latitude = '000null' OR latitude = '' OR latitude = 0 OR latitude IS NULL) ".
|
|
|
930 |
" AND (longitude = '000null' OR longitude = '' OR longitude = 0 OR longitude IS NULL)".
|
1092 |
aurelien |
931 |
')'.
|
|
|
932 |
' OR mots_cles_texte LIKE "%sensible%"'.
|
|
|
933 |
') ';
|
|
|
934 |
|
1043 |
aurelien |
935 |
}
|
|
|
936 |
return $sql;
|
|
|
937 |
}
|
1466 |
aurelien |
938 |
|
|
|
939 |
|
|
|
940 |
private function construireWherePhotosSeulement() {
|
|
|
941 |
$sql = '';
|
|
|
942 |
if (isset($this->parametres['photos']) && $this->parametres['photos'] == 1) {
|
|
|
943 |
$sql = 'AND co.id_observation IN (SELECT DISTINCT id_observation FROM cel_obs_images) ';
|
|
|
944 |
}
|
|
|
945 |
return $sql;
|
|
|
946 |
}
|
1003 |
jpm |
947 |
|
938 |
jpm |
948 |
private function construireWhereUtilisateur() {
|
|
|
949 |
$sql = '';
|
1339 |
aurelien |
950 |
// TODO tester si l'on recoit un id, un mail ou bien un nom ou prenom
|
|
|
951 |
// pour en faire une fonction polyvalente
|
938 |
jpm |
952 |
extract($this->parametres);
|
1132 |
aurelien |
953 |
if (isset($this->parametres['utilisateur']) && !$this->etreNull($utilisateur)) {
|
938 |
jpm |
954 |
$utilisateur = $this->proteger($utilisateur);
|
1339 |
aurelien |
955 |
$sql = " AND co.courriel_utilisateur = $utilisateur ";
|
938 |
jpm |
956 |
}
|
|
|
957 |
return $sql;
|
|
|
958 |
}
|
1003 |
jpm |
959 |
|
938 |
jpm |
960 |
private function construireWhereNumTaxon() {
|
|
|
961 |
$sql = '';
|
|
|
962 |
// Récupération des coordonnées depuis l'id station
|
|
|
963 |
extract($this->parametres);
|
1428 |
aurelien |
964 |
if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
|
938 |
jpm |
965 |
$num_taxon = $this->proteger($num_taxon);
|
1339 |
aurelien |
966 |
$sql = " AND nt = $num_taxon ";
|
938 |
jpm |
967 |
}
|
|
|
968 |
return $sql;
|
|
|
969 |
}
|
1003 |
jpm |
970 |
|
1466 |
aurelien |
971 |
private function construireWhereProjet() {
|
938 |
jpm |
972 |
$sql = '';
|
|
|
973 |
// Récupération des coordonnées depuis l'id station
|
|
|
974 |
extract($this->parametres);
|
1339 |
aurelien |
975 |
$projet_sql = isset($projet) ? $this->getSqlWhereProjet($projet) : null;
|
|
|
976 |
if (!$this->etreNull($projet_sql)) {
|
|
|
977 |
$sql = " AND ($projet_sql) ";
|
938 |
jpm |
978 |
}
|
|
|
979 |
return $sql;
|
|
|
980 |
}
|
1339 |
aurelien |
981 |
|
840 |
jpm |
982 |
/**
|
938 |
jpm |
983 |
* Traitement de $projet pour construction du filtre dans la requête
|
478 |
jpm |
984 |
*/
|
938 |
jpm |
985 |
private function getSqlWhereProjet($projet) {
|
|
|
986 |
$sql = null;
|
1339 |
aurelien |
987 |
if (isset($projet) && !$this->etreNull($projet)) {
|
1394 |
aurelien |
988 |
$sql = 'co.mots_cles_texte LIKE '.$this->proteger('%'.$projet.'%');
|
938 |
jpm |
989 |
}
|
|
|
990 |
return $sql;
|
|
|
991 |
}
|
1339 |
aurelien |
992 |
|
938 |
jpm |
993 |
private function construireWhereTag() {
|
|
|
994 |
$sql = '';
|
840 |
jpm |
995 |
extract($this->parametres);
|
1339 |
aurelien |
996 |
$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
|
|
|
997 |
if (!$this->etreNull($tag_sql)) {
|
|
|
998 |
$sql = " AND ($tag_sql) ";
|
489 |
jpm |
999 |
}
|
938 |
jpm |
1000 |
return $sql;
|
|
|
1001 |
}
|
1339 |
aurelien |
1002 |
|
1484 |
aurelien |
1003 |
private function construireWhereNombreDeJours() {
|
|
|
1004 |
$sql = null;
|
|
|
1005 |
extract($this->parametres);
|
|
|
1006 |
if (isset($nbjours) && !$this->etreNull($nbjours)) {
|
|
|
1007 |
$sql = ' AND DATEDIFF(CURDATE(),co.date_creation) <= '.$this->proteger($nbjours).' ';
|
|
|
1008 |
}
|
|
|
1009 |
return $sql;
|
|
|
1010 |
}
|
|
|
1011 |
|
938 |
jpm |
1012 |
/**
|
|
|
1013 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1014 |
*/
|
|
|
1015 |
private function getSqlWhereObsAvecImagesTaguees($tag) {
|
|
|
1016 |
$sql = null;
|
1339 |
aurelien |
1017 |
if (isset($tag) && !$this->etreNull($tag)) {
|
938 |
jpm |
1018 |
$tag_sql = $this->getSqlWhereMotsCles($tag);
|
|
|
1019 |
// Construction de la requête
|
1339 |
aurelien |
1020 |
$requete = 'SELECT DISTINCT coi.id_observation AS id_obs, ci.ce_utilisateur AS utilisateur '.
|
|
|
1021 |
'FROM cel_images ci'.
|
|
|
1022 |
' LEFT JOIN cel_obs_images coi'.
|
|
|
1023 |
' ON (ci.id_image = coi.id_image) '.
|
|
|
1024 |
' LEFT JOIN cel_obs AS co '.
|
|
|
1025 |
' ON (coi.id_observation = co.id_observation) '.
|
|
|
1026 |
' LEFT JOIN cel_zones_geo AS l '.
|
|
|
1027 |
" ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) ".
|
|
|
1028 |
"WHERE transmission = '1' ".
|
938 |
jpm |
1029 |
$this->construireWhereCoordonnees().
|
|
|
1030 |
$this->construireWhereUtilisateur().
|
|
|
1031 |
$this->construireWhereNumTaxon().
|
|
|
1032 |
$this->construireWhereNomTaxon().
|
1497 |
aurelien |
1033 |
$this->construireWhereReferentiel().
|
938 |
jpm |
1034 |
$this->construireWhereProjet().
|
|
|
1035 |
(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
|
1339 |
aurelien |
1036 |
'ORDER BY utilisateur ASC, ci.ordre ASC';
|
938 |
jpm |
1037 |
//$this->debug[] = $requete;
|
|
|
1038 |
//die($requete);
|
|
|
1039 |
$elements_tag = $this->executerRequete($requete);
|
1339 |
aurelien |
1040 |
|
938 |
jpm |
1041 |
$requete_tag = array();
|
|
|
1042 |
if ($elements_tag != false && count($elements_tag) > 0) {
|
1339 |
aurelien |
1043 |
|
938 |
jpm |
1044 |
$filtres = array();
|
|
|
1045 |
foreach ($elements_tag as $occurence) {
|
|
|
1046 |
$utilisateur = $occurence['utilisateur'];
|
1339 |
aurelien |
1047 |
$id_obs = $occurence['id_obs'];
|
938 |
jpm |
1048 |
if (!array_key_exists($utilisateur, $filtres)) {
|
|
|
1049 |
$filtres[$utilisateur] = array();
|
|
|
1050 |
}
|
1339 |
aurelien |
1051 |
if (!array_key_exists($id_obs, $filtres[$utilisateur])) {
|
|
|
1052 |
$filtres[$utilisateur][$id_obs] = $id_obs;
|
938 |
jpm |
1053 |
}
|
|
|
1054 |
}
|
1339 |
aurelien |
1055 |
|
938 |
jpm |
1056 |
// Pré-construction du where de la requête
|
1339 |
aurelien |
1057 |
$tpl_where = "(id_observation IN (%s))";
|
|
|
1058 |
foreach ($filtres as $utilisateur => $id_obs) {
|
|
|
1059 |
$requete_tag[] = sprintf($tpl_where, implode(',', $id_obs));
|
938 |
jpm |
1060 |
}
|
1339 |
aurelien |
1061 |
|
938 |
jpm |
1062 |
} else {
|
|
|
1063 |
$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
|
|
|
1064 |
}
|
|
|
1065 |
if (count($requete_tag) > 0) {
|
|
|
1066 |
$sql = implode(" \nOR ", $requete_tag);
|
|
|
1067 |
}
|
489 |
jpm |
1068 |
}
|
938 |
jpm |
1069 |
return $sql;
|
478 |
jpm |
1070 |
}
|
1339 |
aurelien |
1071 |
|
487 |
jpm |
1072 |
/**
|
938 |
jpm |
1073 |
* Traitement de $tag pour construction du filtre dans la requête
|
487 |
jpm |
1074 |
*/
|
938 |
jpm |
1075 |
private function getSqlWhereMotsCles($tag) {
|
|
|
1076 |
$sql = null;
|
940 |
jpm |
1077 |
$mots_cles = $this->decomposerParametreTag($tag);
|
1339 |
aurelien |
1078 |
$requete_projet = $this->getSqlWhereMotsClesImages($mots_cles);
|
|
|
1079 |
$sql = $requete_projet;
|
938 |
jpm |
1080 |
//$this->debug[] = $sql;
|
487 |
jpm |
1081 |
return $sql;
|
840 |
jpm |
1082 |
}
|
1339 |
aurelien |
1083 |
|
938 |
jpm |
1084 |
/**
|
|
|
1085 |
* Traitement de $tag pour construction du filtre dans la requête
|
|
|
1086 |
*/
|
|
|
1087 |
private function getSqlWhereMotsClesImages($mots_cles_encodes) {
|
|
|
1088 |
$where_mots_cles_images = array();
|
1339 |
aurelien |
1089 |
foreach ($mots_cles_encodes['motsClesEncodesProteges'] as $mot_cle_encode) {
|
|
|
1090 |
$where_mots_cles_images[] = "ci.mots_cles_texte LIKE $mot_cle_encode";
|
938 |
jpm |
1091 |
}
|
1339 |
aurelien |
1092 |
$where_mots_cles_images = implode(' '.$mots_cles_encodes['type'].' ', $where_mots_cles_images);
|
938 |
jpm |
1093 |
return $where_mots_cles_images;
|
|
|
1094 |
}
|
1339 |
aurelien |
1095 |
|
940 |
jpm |
1096 |
private function decomposerParametreTag($tags) {
|
1339 |
aurelien |
1097 |
|
938 |
jpm |
1098 |
$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
|
|
|
1099 |
if (preg_match('/.+OU.+/', $tags)) {
|
|
|
1100 |
$mots_cles['type'] = 'OR';
|
|
|
1101 |
$mots_cles['motsCles'] = explode('OU', $tags);
|
|
|
1102 |
} else if (preg_match('/.+ET.+/', $tags)) {
|
|
|
1103 |
$mots_cles['type'] = 'AND';
|
|
|
1104 |
$mots_cles['motsCles'] = explode('ET', $tags);
|
|
|
1105 |
} else {
|
|
|
1106 |
$mots_cles['motsCles'][] = $tags;
|
|
|
1107 |
}
|
1339 |
aurelien |
1108 |
|
938 |
jpm |
1109 |
foreach ($mots_cles['motsCles'] as $mot) {
|
1339 |
aurelien |
1110 |
$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote('%'.$mot.'%');
|
938 |
jpm |
1111 |
}
|
|
|
1112 |
$this->debug[] = $mots_cles;
|
|
|
1113 |
return $mots_cles;
|
|
|
1114 |
}
|
1003 |
jpm |
1115 |
|
981 |
jpm |
1116 |
private function decomposerLatLng($coord) {
|
|
|
1117 |
$lat_lng = array();
|
|
|
1118 |
if (isset($coord)) {
|
|
|
1119 |
list($lat, $lng) = explode('|', $coord);
|
|
|
1120 |
$lat_lng = array('lat' => $lat, 'lng' => $lng);
|
|
|
1121 |
}
|
|
|
1122 |
return $lat_lng;
|
|
|
1123 |
}
|
1003 |
jpm |
1124 |
|
940 |
jpm |
1125 |
private function decomposerParametreStation() {
|
938 |
jpm |
1126 |
$station_infos = array();
|
|
|
1127 |
if (isset($this->parametres['station'])) {
|
|
|
1128 |
$station = $this->parametres['station'];
|
|
|
1129 |
$this->debug[] = $station;
|
1033 |
aurelien |
1130 |
@list($type, $coord) = explode(':', $station);
|
|
|
1131 |
@list($lat, $lng) = explode('|', $coord);
|
1003 |
jpm |
1132 |
|
954 |
jpm |
1133 |
$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
|
938 |
jpm |
1134 |
}
|
|
|
1135 |
return $station_infos;
|
|
|
1136 |
}
|
1003 |
jpm |
1137 |
|
940 |
jpm |
1138 |
private function decomposerParametreDate() {
|
1132 |
aurelien |
1139 |
$date_infos = array(null,null);
|
940 |
jpm |
1140 |
if (isset($this->parametres['date'])) {
|
|
|
1141 |
$date = $this->parametres['date'];
|
|
|
1142 |
if (strpos($date, ':')) {
|
|
|
1143 |
list($type, $date) = explode(':', $date);
|
|
|
1144 |
} else {
|
|
|
1145 |
$type = 'observation';
|
|
|
1146 |
}
|
1003 |
jpm |
1147 |
|
940 |
jpm |
1148 |
$date = str_replace('/', '-', $date);
|
|
|
1149 |
if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $date, $matches)) {
|
|
|
1150 |
$date = $matches[3].'-'.$matches[2].'-'.$matches[1];
|
|
|
1151 |
}
|
1003 |
jpm |
1152 |
|
940 |
jpm |
1153 |
$date_infos = array($type, $date);
|
|
|
1154 |
}
|
|
|
1155 |
return $date_infos;
|
|
|
1156 |
}
|
1003 |
jpm |
1157 |
|
940 |
jpm |
1158 |
private function decomposerParametreTaxon() {
|
1132 |
aurelien |
1159 |
$nom_infos = array(null,null);
|
940 |
jpm |
1160 |
if (isset($this->parametres['taxon'])) {
|
|
|
1161 |
$taxon = $this->parametres['taxon'];
|
|
|
1162 |
if (strpos($taxon, ':')) {
|
|
|
1163 |
$nom_infos = explode(':', $taxon);
|
|
|
1164 |
} else {
|
|
|
1165 |
$nom_infos = array('retenu', $taxon);
|
|
|
1166 |
}
|
|
|
1167 |
}
|
|
|
1168 |
return $nom_infos;
|
|
|
1169 |
}
|
1003 |
jpm |
1170 |
|
940 |
jpm |
1171 |
private function decomposerParametreCommentaire() {
|
1132 |
aurelien |
1172 |
$commentaire_infos = array(null,null);
|
940 |
jpm |
1173 |
if (isset($this->parametres['commentaire'])) {
|
|
|
1174 |
$commentaire = $this->parametres['commentaire'];
|
|
|
1175 |
if (strpos($commentaire, ':')) {
|
|
|
1176 |
$commentaire_infos = explode(':', $commentaire);
|
|
|
1177 |
} else {
|
|
|
1178 |
$commentaire_infos = array('observation', $commentaire);
|
|
|
1179 |
}
|
|
|
1180 |
}
|
|
|
1181 |
return $commentaire_infos;
|
|
|
1182 |
}
|
1172 |
aurelien |
1183 |
}
|
|
|
1184 |
?>
|