Line 44... |
Line 44... |
44 |
}
|
44 |
}
|
Line 45... |
Line 45... |
45 |
|
45 |
|
46 |
if (is_null($retour)) {
|
46 |
if (is_null($retour)) {
|
47 |
$info = 'Un problème est survenu : '.print_r($this->messages, true);
|
47 |
$info = 'Un problème est survenu : '.print_r($this->messages, true);
|
48 |
$this->envoyer($info);
|
48 |
$this->envoyer($info);
|
Line 49... |
Line 49... |
49 |
} else if ($retour['type'] == 'jsonVar') {
|
49 |
} else if (isset($retour['type']) && $retour['type'] == 'jsonVar') {
|
50 |
|
50 |
|
51 |
$this->envoyerJsonVar($retour['variable_js'], $retour['donnees']);
|
51 |
$this->envoyerJsonVar($retour['variable_js'], $retour['donnees']);
|
52 |
} else if ($retour['type'] == 'jsonP') {
|
52 |
} else if (isset($retour['type']) && $retour['type'] == 'jsonP') {
|
53 |
$this->envoyerJsonp($retour['donnees']);
|
53 |
$this->envoyerJsonp($retour['donnees']);
|
54 |
} else {
|
54 |
} else {
|
55 |
$this->envoyerJson($retour);
|
55 |
$this->envoyerJson($retour);
|
Line 59... |
Line 59... |
59 |
/**
|
59 |
/**
|
60 |
* Les stations de la carte par défaut
|
60 |
* Les stations de la carte par défaut
|
61 |
*/
|
61 |
*/
|
62 |
public function getStations($params) {
|
62 |
public function getStations($params) {
|
63 |
$json = null;
|
63 |
$json = null;
|
64 |
$requete = 'SELECT sector, x_utm, y_utm, wgs84_latitude AS coord_x, wgs84_longitude AS coord_y '.
|
64 |
$requete = 'SELECT utm_secteur, utm_x, utm_y, wgs84_latitude AS latitude, wgs84_longitude AS longitude '.
|
65 |
'FROM cel_inventory AS i '.
|
65 |
'FROM cel_obs AS co '.
|
66 |
' LEFT JOIN locations AS l '.
|
66 |
' LEFT JOIN cel_zones_geo AS l '.
|
67 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
67 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
68 |
"WHERE transmission = '1' ".
|
68 |
"WHERE transmission = '1' ".
|
69 |
$this->construireWhereDept().
|
69 |
$this->construireWhereDept().
|
70 |
$this->construireWhereCommune().
|
70 |
$this->construireWhereCommune().
|
71 |
$this->construireWhereUtilisateur().
|
71 |
$this->construireWhereUtilisateur().
|
72 |
$this->construireWhereNumTaxon().
|
72 |
$this->construireWhereNumTaxon().
|
Line 103... |
Line 103... |
103 |
|
103 |
|
104 |
private function traiterStations($resultats) {
|
104 |
private function traiterStations($resultats) {
|
105 |
$stations = array();
|
105 |
$stations = array();
|
106 |
if ($resultats !== false) {
|
106 |
if ($resultats !== false) {
|
107 |
foreach ($resultats as $enrg) {
|
107 |
foreach ($resultats as $enrg) {
|
108 |
if ($enrg['coord_x'] != null && $enrg['coord_y'] != null) {
|
108 |
if ($enrg['latitude'] != null && $enrg['longitude'] != null) {
|
109 |
$id = $enrg['coord_x'].'-'.$enrg['coord_y'];
|
109 |
$id = $enrg['latitude'].'-'.$enrg['longitude'];
|
110 |
if (!isset($stations[$id])) {
|
110 |
if (!isset($stations[$id])) {
|
111 |
$enrg['id'] = 'UTM:'.$enrg['x_utm'].'-'.$enrg['y_utm'].'-'.$enrg['sector'];
|
111 |
$enrg['id'] = 'UTM:'.$enrg['utm_x'].'-'.$enrg['utm_y'].'-'.$enrg['utm_secteur'];
|
112 |
unset($enrg['x_utm']);
|
112 |
unset($enrg['utm_x']);
|
113 |
unset($enrg['y_utm']);
|
113 |
unset($enrg['utm_y']);
|
114 |
unset($enrg['sector']);
|
114 |
unset($enrg['utm_secteur']);
|
115 |
$stations[$id] = $enrg;
|
115 |
$stations[$id] = $enrg;
|
116 |
$stations[$id]['nbre'] = 1;
|
116 |
$stations[$id]['nbre'] = 1;
|
117 |
} else {
|
117 |
} else {
|
118 |
$stations[$id]['nbre']++;
|
118 |
$stations[$id]['nbre']++;
|
Line 129... |
Line 129... |
129 |
*/
|
129 |
*/
|
130 |
public function getObservations($params) {
|
130 |
public function getObservations($params) {
|
131 |
$resultats = array();
|
131 |
$resultats = array();
|
132 |
$total = 0;
|
132 |
$total = 0;
|
133 |
if (!$this->etreNull($this->parametres['station'])) {
|
133 |
if (!$this->etreNull($this->parametres['station'])) {
|
134 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS id, identifiant, nom_sel, nom_ret, num_nom_sel, num_nom_ret, num_taxon, famille, '.
|
134 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS id_observation, ce_utilisateur, courriel_utilisateur, '.
|
- |
|
135 |
' nom_sel, nom_ret, nom_sel_nn, nom_ret_nn, nt, famille, '.
|
135 |
' lieudit, location, date_observation, milieu, commentaire, '.
|
136 |
' lieudit, zone_geo, date_observation, milieu, commentaire, '.
|
136 |
' sector, x_utm, y_utm, insee_code, date_transmission '.
|
137 |
' utm_secteur, utm_x, utm_y, id_zone_geo, date_transmission '.
|
137 |
'FROM cel_inventory AS i '.
|
138 |
'FROM cel_obs AS co '.
|
138 |
' LEFT JOIN locations AS l '.
|
139 |
' LEFT JOIN cel_zones_geo AS l '.
|
139 |
" ON (l.name = i.location AND l.code = i.id_location) ".
|
140 |
" ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) ".
|
140 |
"WHERE transmission = '1' ".
|
141 |
"WHERE transmission = '1' ".
|
141 |
$this->construireWhereCoordonnees().
|
142 |
$this->construireWhereCoordonnees().
|
142 |
$this->construireWhereUtilisateur().
|
143 |
$this->construireWhereUtilisateur().
|
143 |
$this->construireWhereNumTaxon().
|
144 |
$this->construireWhereNumTaxon().
|
144 |
$this->construireWhereNomTaxon().
|
145 |
$this->construireWhereNomTaxon().
|
Line 156... |
Line 157... |
156 |
}
|
157 |
}
|
Line 157... |
Line 158... |
157 |
|
158 |
|
158 |
// Post-traitement
|
159 |
// Post-traitement
|
159 |
$observations = $this->traiterObservations($resultats, $total);
|
160 |
$observations = $this->traiterObservations($resultats, $total);
|
160 |
$observations = $this->ajouterImagesAuxObs($observations);
|
- |
|
161 |
$observations = $this->ajouterAuteursAuxObs($observations);
|
161 |
$observations = $this->ajouterImagesAuxObs($observations);
|
162 |
$observations = $this->supprimerIdDesObs($observations);
|
162 |
$observations = $this->supprimerIdDesObs($observations);
|
163 |
return $observations;
|
163 |
return $observations;
|
Line 164... |
Line 164... |
164 |
}
|
164 |
}
|
165 |
|
165 |
|
166 |
private function traiterObservations($donnees, $total) {
|
166 |
private function traiterObservations($donnees, $total) {
|
167 |
$observations = array('commune' => '', 'observations' => array(), 'observateurs' => array());
|
167 |
$observations = array('commune' => '', 'observations' => array());
|
168 |
$observations['total'] = (isset($total)) ? $total : 0;
|
168 |
$observations['total'] = (isset($total)) ? $total : 0;
|
169 |
if (is_array($donnees) && count($donnees) > 0) {
|
169 |
if (is_array($donnees) && count($donnees) > 0) {
|
170 |
foreach ($donnees as $donnee) {
|
170 |
foreach ($donnees as $donnee) {
|
171 |
$observation = array();
|
171 |
$observation = array();
|
172 |
$observation['idObs'] = $donnee->id;
|
172 |
$observation['idObs'] = $donnee->id_observation;
|
173 |
$observation['nn'] = $this->etreNull($donnee->num_nom_sel) ? null : $donnee->num_nom_sel;
|
173 |
$observation['nn'] = $this->etreNull($donnee->nom_sel_nn) ? null : $donnee->nom_sel_nn;
|
174 |
$observation['nomSci'] = $this->nettoyerTexte($donnee->nom_sel);
|
174 |
$observation['nomSci'] = $this->nettoyerTexte($donnee->nom_sel);
|
175 |
$observation['date'] = $this->formaterDate($donnee->date_observation, '%d/%m/%Y');
|
175 |
$observation['date'] = $this->formaterDate($donnee->date_observation, '%d/%m/%Y');
|
- |
|
176 |
$observation['datePubli'] = $this->formaterDate($donnee->date_transmission);
|
176 |
$observation['datePubli'] = $this->formaterDate($donnee->date_transmission);
|
177 |
$observation['lieu'] = $this->traiterLieu($donnee);
|
177 |
$observation['lieu'] = $this->traiterLieu($donnee);
|
178 |
$observation['observateur'] = $donnee->courriel_utilisateur;
|
Line 178... |
Line 179... |
178 |
$observation['observateur'] = $donnee->identifiant;
|
179 |
$observation['observateurId'] = $donnee->ce_utilisateur;
|
179 |
$observation['urlEflore'] = $this->getUrlEflore($donnee->num_nom_sel);
|
180 |
$observation['urlEflore'] = $this->getUrlEflore($donnee->nom_sel_nn);
|
180 |
|
- |
|
181 |
if (isset($donnee->location)) {
|
- |
|
182 |
$observations['commune'] = $this->nettoyerTexte($donnee->location);
|
- |
|
183 |
}
|
- |
|
184 |
$observations['observations'][$donnee->id] = $observation;
|
- |
|
185 |
|
181 |
|
- |
|
182 |
if (isset($donnee->zone_geo)) {
|
186 |
if (! array_key_exists($donnee->identifiant, $observations['observateurs'])) {
|
183 |
$observations['commune'] = $this->nettoyerTexte($donnee->zone_geo);
|
187 |
$observations['observateurs'][$donnee->identifiant] = $donnee->identifiant;
|
184 |
}
|
188 |
}
|
185 |
$observations['observations'][$donnee->id_observation] = $observation;
|
189 |
}
|
186 |
}
|
Line 240... |
Line 237... |
240 |
}
|
237 |
}
|
Line 241... |
Line 238... |
241 |
|
238 |
|
242 |
private function ajouterImagesAuxObs($observations) {
|
239 |
private function ajouterImagesAuxObs($observations) {
|
243 |
$images = $this->chargerImages(array_keys($observations['observations']));
|
240 |
$images = $this->chargerImages(array_keys($observations['observations']));
|
244 |
foreach ($observations['observations'] as $id => $infos) {
|
241 |
foreach ($observations['observations'] as $id => $infos) {
|
245 |
$infos['images'] = $images[$id];
|
242 |
if(isset($images[$id])) {
|
246 |
$observations['observations'][$id] = $infos;
|
243 |
$infos['images'] = $images[$id];
|
247 |
}
|
- |
|
248 |
return $observations;
|
- |
|
249 |
}
|
- |
|
250 |
|
- |
|
251 |
private function ajouterAuteursAuxObs($observations) {
|
- |
|
252 |
$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
|
- |
|
253 |
unset($observations['observateurs']);
|
- |
|
254 |
foreach ($observations['observations'] as $id => $infos) {
|
- |
|
255 |
$courriel = $infos['observateur'];
|
- |
|
256 |
$infos['observateur'] = $observateurs[$courriel]['intitule'];
|
- |
|
257 |
$infos['observateurId'] = $observateurs[$courriel]['id'];
|
244 |
}
|
258 |
$observations['observations'][$id] = $infos;
|
245 |
$observations['observations'][$id] = $infos;
|
259 |
}
|
246 |
}
|
260 |
return $observations;
|
247 |
return $observations;
|
Line 274... |
Line 261... |
274 |
* Liste des taxons présents sur la carte
|
261 |
* Liste des taxons présents sur la carte
|
275 |
*/
|
262 |
*/
|
276 |
public function getTaxons($params) {
|
263 |
public function getTaxons($params) {
|
277 |
$json = null;
|
264 |
$json = null;
|
Line 278... |
Line 265... |
278 |
|
265 |
|
279 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, num_nom_ret, num_taxon, famille '.
|
266 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, nom_ret_nn, nt, famille '.
|
280 |
'FROM cel_inventory AS i '.
|
267 |
'FROM cel_obs AS co '.
|
281 |
' LEFT JOIN locations AS l '.
|
268 |
' LEFT JOIN cel_zones_geo AS l '.
|
282 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
269 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
283 |
"WHERE transmission = '1' ".
|
270 |
"WHERE transmission = '1' ".
|
284 |
" AND nom_ret != '' ".
|
271 |
" AND nom_ret != '' ".
|
285 |
$this->construireWhereDept().
|
272 |
$this->construireWhereDept().
|
286 |
$this->construireWhereCommune().
|
273 |
$this->construireWhereCommune().
|
Line 292... |
Line 279... |
292 |
$this->construireWhereProjet().
|
279 |
$this->construireWhereProjet().
|
293 |
$this->construireWhereTag();
|
280 |
$this->construireWhereTag();
|
294 |
'ORDER BY nom_ret ASC '.
|
281 |
'ORDER BY nom_ret ASC '.
|
295 |
"LIMIT {$this->start},{$this->limit} ";
|
282 |
"LIMIT {$this->start},{$this->limit} ";
|
296 |
//$this->debug[] = $requete;
|
283 |
//$this->debug[] = $requete;
|
- |
|
284 |
//die($requete);
|
297 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
285 |
$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
|
Line 298... |
Line 286... |
298 |
|
286 |
|
299 |
$requete = 'SELECT FOUND_ROWS()';
|
287 |
$requete = 'SELECT FOUND_ROWS()';
|
Line 307... |
Line 295... |
307 |
|
295 |
|
308 |
private function traiterTaxons($donnees) {
|
296 |
private function traiterTaxons($donnees) {
|
309 |
$taxons = array();
|
297 |
$taxons = array();
|
310 |
if (is_array($donnees) && count($donnees) > 0) {
|
298 |
if (is_array($donnees) && count($donnees) > 0) {
|
311 |
foreach ($donnees as $donnee) {
|
299 |
foreach ($donnees as $donnee) {
|
312 |
if (!isset($taxons[$donnee->num_taxon]) && ! $this->etreNull($donnee->nom_ret)) {
|
300 |
if (!isset($taxons[$donnee->nt]) && ! $this->etreNull($donnee->nom_ret)) {
|
313 |
$taxon = array();
|
301 |
$taxon = array();
|
314 |
$taxon['nn'] = $donnee->num_nom_ret;
|
302 |
$taxon['nn'] = $donnee->nom_ret_nn;
|
315 |
$taxon['nt'] = $donnee->num_taxon;
|
303 |
$taxon['nt'] = $donnee->nt;
|
316 |
$taxon['nom'] = $this->nettoyerTexte($donnee->nom_ret);
|
304 |
$taxon['nom'] = $this->nettoyerTexte($donnee->nom_ret);
|
317 |
$taxon['famille'] = $this->nettoyerTexte($donnee->famille);
|
305 |
$taxon['famille'] = $this->nettoyerTexte($donnee->famille);
|
318 |
$taxons[$donnee->num_taxon] = $taxon;
|
306 |
$taxons[$donnee->nt] = $taxon;
|
319 |
}
|
307 |
}
|
320 |
}
|
308 |
}
|
321 |
}
|
309 |
}
|
322 |
$taxons = array_values($taxons);
|
310 |
$taxons = array_values($taxons);
|
Line 328... |
Line 316... |
328 |
// Récupération des coordonnées depuis l'id station
|
316 |
// Récupération des coordonnées depuis l'id station
|
329 |
extract($this->decomposerParametreStation());
|
317 |
extract($this->decomposerParametreStation());
|
330 |
if (isset($type)) {
|
318 |
if (isset($type)) {
|
331 |
if ($type == 'UTM') {
|
319 |
if ($type == 'UTM') {
|
332 |
$secteur = $this->proteger($secteur);
|
320 |
$secteur = $this->proteger($secteur);
|
333 |
$x_utm = $this->proteger($x_utm);
|
321 |
$utm_x = $this->proteger($utm_x);
|
334 |
$y_utm = $this->proteger($y_utm);
|
322 |
$utm_y = $this->proteger($utm_y);
|
Line 335... |
Line 323... |
335 |
|
323 |
|
336 |
$sql = " AND (sector = $secteur AND x_utm = $x_utm AND y_utm = $y_utm ) ";
|
324 |
$sql = " AND (utm_secteur = $secteur AND utm_x = $utm_x AND utm_y = $utm_y ) ";
|
337 |
} else if ($type == 'LngLat') {
|
325 |
} else if ($type == 'LngLat') {
|
338 |
$coord_x = $this->proteger($coord_x);
|
326 |
$latitude = $this->proteger($latitude);
|
Line 339... |
Line 327... |
339 |
$coord_y = $this->proteger($coord_y);
|
327 |
$longitude = $this->proteger($longitude);
|
340 |
|
328 |
|
341 |
$sql = " AND (coord_x = $coord_x AND coord_y = $coord_y ) ";
|
329 |
$sql = " AND (latitude = $latitude AND longitude = $longitude ) ";
|
342 |
}
|
330 |
}
|
343 |
}
|
331 |
}
|
Line 353... |
Line 341... |
353 |
case '*' :
|
341 |
case '*' :
|
354 |
$sql = $this->obtenirConditionPourCommentaires($commentaire);
|
342 |
$sql = $this->obtenirConditionPourCommentaires($commentaire);
|
355 |
$sql = " AND (commentaire LIKE $commentaire OR ($sql)) ";
|
343 |
$sql = " AND (commentaire LIKE $commentaire OR ($sql)) ";
|
356 |
break;
|
344 |
break;
|
357 |
case 'observation' :
|
345 |
case 'observation' :
|
358 |
$sql = " AND commentaire LIKE $commentaire ";
|
346 |
$sql = " AND co.commentaire LIKE $commentaire ";
|
359 |
break;
|
347 |
break;
|
360 |
case 'photo' :
|
348 |
case 'photo' :
|
361 |
$sql = ' AND '.$this->obtenirConditionPourCommentaires($commentaire).' ';
|
349 |
$sql = ' AND '.$this->obtenirConditionPourCommentaires($commentaire).' ';
|
362 |
break;
|
350 |
break;
|
363 |
case 'photo.meta' :
|
351 |
case 'photo.meta' :
|
Line 365... |
Line 353... |
365 |
break;
|
353 |
break;
|
366 |
case 'photo.utilisateur' :
|
354 |
case 'photo.utilisateur' :
|
367 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireUtilisateur($commentaire).' ';
|
355 |
$sql = ' AND '.$this->obtenirConditionPourCommentaireUtilisateur($commentaire).' ';
|
368 |
break;
|
356 |
break;
|
369 |
default:
|
357 |
default:
|
370 |
$sql = " AND commentaire LIKE $commentaire ";
|
358 |
$sql = " AND co.commentaire LIKE $commentaire ";
|
371 |
}
|
359 |
}
|
372 |
}
|
360 |
}
|
373 |
return $sql;
|
361 |
return $sql;
|
374 |
}
|
362 |
}
|
Line 503... |
Line 491... |
503 |
* Récupération des identifiant d'utilisateur et des ordres des observations correspondant à une date.
|
491 |
* Récupération des identifiant d'utilisateur et des ordres des observations correspondant à une date.
|
504 |
* Retour sous forme de tableau : array[identifiant] = array(ordre, ordre...);
|
492 |
* Retour sous forme de tableau : array[identifiant] = array(ordre, ordre...);
|
505 |
*/
|
493 |
*/
|
506 |
private function obtenirObsLieesImg($type, $param) {
|
494 |
private function obtenirObsLieesImg($type, $param) {
|
507 |
// Construction de la requête
|
495 |
// Construction de la requête
|
508 |
$requete = 'SELECT DISTINCT coi_ce_observation AS ordre, coi_ce_utilisateur AS utilisateur '.
|
496 |
$requete = 'SELECT DISTINCT id_observation AS id_obs, ce_utilisateur AS utilisateur '.
|
509 |
'FROM cel_images '.
|
497 |
'FROM cel_images ci'.
|
510 |
' LEFT JOIN cel_obs_images '.
|
498 |
' LEFT JOIN cel_obs_images coi '.
|
511 |
' ON (ci_id_image = coi_ce_image) '.
|
499 |
' ON (coi.id_image = ci.id_image) '.
|
512 |
' LEFT JOIN cel_inventory AS i '.
|
500 |
' LEFT JOIN cel_obs AS co '.
|
513 |
' ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
|
501 |
' ON coi.id_observation = co.id_observation '.
|
514 |
' LEFT JOIN locations AS l '.
|
502 |
' LEFT JOIN locations AS l '.
|
515 |
' ON (l.name = i.location AND l.code = i.id_location) '.
|
503 |
' ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
|
516 |
"WHERE transmission = '1' ".
|
504 |
"WHERE transmission = '1' ".
|
517 |
($type == 'date.photo' ? " AND (ci_meta_date_time LIKE ".str_replace('-', ':', $param)." OR ci_meta_date LIKE $param) " : '').
|
505 |
($type == 'date.photo' ? " AND (date_prise_de_vue LIKE ".str_replace('-', ':', $param).") " : '').
|
518 |
($type == 'date.ajout' ? " AND ci_meta_date_ajout LIKE $param " : '').
|
506 |
($type == 'date.ajout' ? " AND date_creation LIKE $param " : '').
|
519 |
($type == 'date.liaison' ? " AND coi_date_liaison LIKE $param " : '').
|
507 |
($type == 'date.liaison' ? " AND date_liaison LIKE $param " : '').
|
- |
|
508 |
// TODO: recherche sur le xml
|
520 |
($type == 'commentaire.meta' ? " AND ci_meta_comment LIKE $param " : '').
|
509 |
//($type == 'commentaire.meta' ? " AND ci.commentaire LIKE $param " : '').
|
521 |
($type == 'commentaire.utilisateur' ? " AND ci_meta_user_comment LIKE $param " : '').
|
510 |
($type == 'commentaire.utilisateur' ? " AND ci.commentaire LIKE $param " : '').
|
522 |
($type == 'commentaire.*' ? " AND (ci_meta_comment LIKE $param OR ci_meta_user_comment LIKE $param) " : '').
|
511 |
($type == 'commentaire.*' ? " AND (ci.commentaire LIKE $param) " : '').
|
523 |
$this->construireWhereCoordonnees().
|
512 |
$this->construireWhereCoordonnees().
|
524 |
$this->construireWhereDept().
|
513 |
$this->construireWhereDept().
|
525 |
$this->construireWhereCommune().
|
514 |
$this->construireWhereCommune().
|
526 |
$this->construireWhereUtilisateur().
|
515 |
$this->construireWhereUtilisateur().
|
527 |
$this->construireWhereNumTaxon().
|
516 |
$this->construireWhereNumTaxon().
|
Line 536... |
Line 525... |
536 |
$observations = null;
|
525 |
$observations = null;
|
537 |
if ($resultats != false) {
|
526 |
if ($resultats != false) {
|
538 |
$observations = array();
|
527 |
$observations = array();
|
539 |
foreach ($resultats as $occurence) {
|
528 |
foreach ($resultats as $occurence) {
|
540 |
$utilisateur = $occurence['utilisateur'];
|
529 |
$utilisateur = $occurence['utilisateur'];
|
541 |
$ordre = $occurence['ordre'];
|
530 |
$id_obs = $occurence['id_obs'];
|
542 |
if (!array_key_exists($utilisateur, $observations)) {
|
531 |
if (!array_key_exists($utilisateur, $observations)) {
|
543 |
$observations[$utilisateur] = array();
|
532 |
$observations[$utilisateur] = array();
|
544 |
}
|
533 |
}
|
545 |
if (!array_key_exists($ordre, $observations[$utilisateur])) {
|
534 |
if (!array_key_exists($id_obs, $observations[$utilisateur])) {
|
546 |
$observations[$utilisateur][$ordre] = $ordre;
|
535 |
$observations[$utilisateur][$id_obs] = $id_obs;
|
547 |
}
|
536 |
}
|
548 |
}
|
537 |
}
|
549 |
}
|
538 |
}
|
550 |
return $observations;
|
539 |
return $observations;
|
551 |
}
|
540 |
}
|
Line 552... |
Line 541... |
552 |
|
541 |
|
553 |
private function assemblerObsEnConditionSql($observations, $operateur = 'AND') {
|
542 |
private function assemblerObsEnConditionSql($observations, $operateur = 'AND') {
|
554 |
$sql = '';
|
543 |
$sql = '';
|
555 |
if ($observations != null) {
|
544 |
if ($observations != null) {
|
556 |
// Pré-construction du where de la requête
|
545 |
// Pré-construction du where de la requête
|
557 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
546 |
$tpl_where = "(id_observation IN (%s))";
|
558 |
foreach ($observations as $utilisateur => $ordres) {
|
547 |
foreach ($observations as $utilisateur => $ids_obs) {
|
559 |
$morceaux_requete[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
548 |
$morceaux_requete[] = sprintf($tpl_where, implode(',', $ids_obs));
|
560 |
}
|
549 |
}
|
561 |
if (count($morceaux_requete) > 0) {
|
550 |
if (count($morceaux_requete) > 0) {
|
562 |
$sql = implode(" \nOR ", $morceaux_requete);
|
551 |
$sql = implode(" \nOR ", $morceaux_requete);
|
563 |
}
|
552 |
}
|
564 |
} else {
|
553 |
} else {
|
565 |
// Nous voulons que la requête ne retourne rien
|
554 |
// Nous voulons que la requête ne retourne rien
|
566 |
$sql = "identifiant = '' AND ordre = ''";
|
555 |
$sql = "id_observation = ''";
|
567 |
}
|
556 |
}
|
568 |
$sql = " $operateur ($sql) ";
|
557 |
$sql = " $operateur ($sql) ";
|
569 |
return $sql;
|
558 |
return $sql;
|
Line 570... |
Line 559... |
570 |
}
|
559 |
}
|
571 |
|
560 |
|
572 |
private function construireWhereDept() {
|
561 |
private function construireWhereDept() {
|
573 |
$sql = '';
|
562 |
$sql = '';
|
574 |
// Récupération des coordonnées depuis l'id station
|
563 |
// Récupération des coordonnées depuis l'id station
|
575 |
extract($this->parametres);
|
564 |
extract($this->parametres);
|
- |
|
565 |
if (isset($dept) && !$this->etreNull($dept)) {
|
- |
|
566 |
$valeurs_a_proteger = explode(',',trim($dept));
|
- |
|
567 |
foreach ($valeurs_a_proteger as $valeur) {
|
- |
|
568 |
$valeurs_protegees[] = '(ce_zone_geo LIKE '.$this->bdd->quote('INSEE-C:'.$valeur.'%').') ';
|
576 |
if (isset($dept) && !$this->etreNull($dept)) {
|
569 |
}
|
577 |
$dept = $this->traiterValeursMultiples($dept);
|
570 |
$valeurs = implode(' OR ', $valeurs_protegees);
|
578 |
$sql = " AND code IN ($dept) ";
|
571 |
$sql = " AND ($valeurs) ";
|
579 |
}
|
572 |
}
|
Line 580... |
Line 573... |
580 |
return $sql;
|
573 |
return $sql;
|
581 |
}
|
574 |
}
|
582 |
|
575 |
|
583 |
private function construireWhereCommune() {
|
576 |
private function construireWhereCommune() {
|
584 |
$sql = '';
|
577 |
$sql = '';
|
585 |
// Récupération des coordonnées depuis l'id station
|
578 |
// Récupération des coordonnées depuis l'id station
|
586 |
extract($this->parametres);
|
579 |
extract($this->parametres);
|
587 |
if (isset($commune) && !$this->etreNull($commune)) {
|
580 |
if (isset($commune) && !$this->etreNull($commune)) {
|
588 |
$commune = $this->proteger($commune);
|
581 |
$commune = $this->proteger($commune);
|
589 |
$sql = " AND location LIKE $commune ";
|
582 |
$sql = " AND zone_geo LIKE $commune ";
|
Line 596... |
Line 589... |
596 |
$sql = '';
|
589 |
$sql = '';
|
597 |
// Récupération des coordonnées depuis l'id station
|
590 |
// Récupération des coordonnées depuis l'id station
|
598 |
extract($this->parametres);
|
591 |
extract($this->parametres);
|
599 |
if (isset($utilisateur) && !$this->etreNull($utilisateur)) {
|
592 |
if (isset($utilisateur) && !$this->etreNull($utilisateur)) {
|
600 |
$utilisateur = $this->proteger($utilisateur);
|
593 |
$utilisateur = $this->proteger($utilisateur);
|
601 |
$sql = " AND identifiant = $utilisateur ";
|
594 |
$sql = " AND courriel_utilisateur = $utilisateur ";
|
602 |
}
|
595 |
}
|
603 |
return $sql;
|
596 |
return $sql;
|
604 |
}
|
597 |
}
|
Line 605... |
Line 598... |
605 |
|
598 |
|
606 |
private function construireWhereNumTaxon() {
|
599 |
private function construireWhereNumTaxon() {
|
607 |
$sql = '';
|
600 |
$sql = '';
|
608 |
// Récupération des coordonnées depuis l'id station
|
601 |
// Récupération des coordonnées depuis l'id station
|
609 |
extract($this->parametres);
|
602 |
extract($this->parametres);
|
610 |
if (isset($num_taxon) && !$this->etreNull($num_taxon)) {
|
603 |
if (isset($num_taxon) && !$this->etreNull($num_taxon)) {
|
611 |
$num_taxon = $this->proteger($num_taxon);
|
604 |
$num_taxon = $this->proteger($num_taxon);
|
612 |
$sql = " AND num_taxon = $num_taxon ";
|
605 |
$sql = " AND nt = $num_taxon ";
|
613 |
}
|
606 |
}
|
614 |
return $sql;
|
607 |
return $sql;
|
Line 615... |
Line 608... |
615 |
}
|
608 |
}
|
Line 629... |
Line 622... |
629 |
* Traitement de $projet pour construction du filtre dans la requête
|
622 |
* Traitement de $projet pour construction du filtre dans la requête
|
630 |
*/
|
623 |
*/
|
631 |
private function getSqlWhereProjet($projet) {
|
624 |
private function getSqlWhereProjet($projet) {
|
632 |
$sql = null;
|
625 |
$sql = null;
|
633 |
if (isset($projet) && !$this->etreNull($projet)) {
|
626 |
if (isset($projet) && !$this->etreNull($projet)) {
|
634 |
$mot_cle_encode = $this->bdd->quote($this->encoderMotCle($projet));
|
627 |
$sql = 'co.mots_cles_texte LIKE '.$this->proteger($projet);
|
635 |
|
- |
|
636 |
// Construction de la requête
|
- |
|
637 |
$requete = 'SELECT * '.
|
- |
|
638 |
'FROM cel_mots_cles_obs '.
|
- |
|
639 |
"WHERE cmc_id_mot_cle_general = $mot_cle_encode ";
|
- |
|
640 |
$elements_projet = $this->executerRequete($requete);
|
- |
|
641 |
|
- |
|
642 |
$requete_projet = array();
|
- |
|
643 |
if ($elements_projet != false && count($elements_projet) > 0) {
|
- |
|
644 |
// Pré-construction du where de la requête
|
- |
|
645 |
$tpl_where = '(mots_cles LIKE "%%%s%%" AND identifiant = %s )';
|
- |
|
646 |
|
- |
|
647 |
foreach ($elements_projet as $occurence) {
|
- |
|
648 |
$requete_projet[] = sprintf($tpl_where, $occurence['cmc_id_mot_cle_utilisateur'], $this->bdd->quote($occurence['cmc_id_proprietaire']));
|
- |
|
649 |
}
|
- |
|
650 |
} else {
|
- |
|
651 |
$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
|
- |
|
652 |
}
|
- |
|
653 |
if (count($requete_projet) > 0) {
|
- |
|
654 |
$sql = implode(" \nOR ", $requete_projet);
|
- |
|
655 |
}
|
- |
|
656 |
}
|
628 |
}
|
657 |
return $sql;
|
629 |
return $sql;
|
658 |
}
|
630 |
}
|
Line 659... |
Line 631... |
659 |
|
631 |
|
660 |
private function construireWhereTag() {
|
632 |
private function construireWhereTag() {
|
661 |
$sql = '';
|
- |
|
662 |
// Récupération des coordonnées depuis l'id station
|
633 |
$sql = '';
|
663 |
extract($this->parametres);
|
634 |
extract($this->parametres);
|
664 |
$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
|
635 |
$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
|
665 |
if (!$this->etreNull($tag_sql)) {
|
636 |
if (!$this->etreNull($tag_sql)) {
|
666 |
$sql = " AND ($tag_sql) ";
|
637 |
$sql = " AND ($tag_sql) ";
|
Line 674... |
Line 645... |
674 |
private function getSqlWhereObsAvecImagesTaguees($tag) {
|
645 |
private function getSqlWhereObsAvecImagesTaguees($tag) {
|
675 |
$sql = null;
|
646 |
$sql = null;
|
676 |
if (isset($tag) && !$this->etreNull($tag)) {
|
647 |
if (isset($tag) && !$this->etreNull($tag)) {
|
677 |
$tag_sql = $this->getSqlWhereMotsCles($tag);
|
648 |
$tag_sql = $this->getSqlWhereMotsCles($tag);
|
678 |
// Construction de la requête
|
649 |
// Construction de la requête
|
679 |
$requete = 'SELECT DISTINCT coi_ce_observation AS ordre, coi_ce_utilisateur AS utilisateur '.
|
650 |
$requete = 'SELECT DISTINCT coi.id_observation AS id_obs, coi.ce_utilisateur AS utilisateur '.
|
680 |
'FROM cel_images '.
|
651 |
'FROM cel_images '.
|
681 |
' LEFT JOIN cel_obs_images '.
|
652 |
' LEFT JOIN cel_obs_images coi'.
|
682 |
' ON (ci_id_image = coi_ce_image) '.
|
653 |
' ON (ci_id_image = coi_ce_image) '.
|
683 |
' LEFT JOIN cel_inventory AS i '.
|
654 |
' LEFT JOIN cel_obs AS i '.
|
684 |
' ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
|
655 |
' ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
|
685 |
' LEFT JOIN locations AS l '.
|
656 |
' LEFT JOIN locations AS l '.
|
686 |
" ON (l.name = i.location AND l.code = i.id_location) ".
|
657 |
" ON (l.name = i.location AND l.code = i.id_location) ".
|
687 |
"WHERE transmission = '1' ".
|
658 |
"WHERE transmission = '1' ".
|
688 |
$this->construireWhereCoordonnees().
|
659 |
$this->construireWhereCoordonnees().
|
Line 700... |
Line 671... |
700 |
if ($elements_tag != false && count($elements_tag) > 0) {
|
671 |
if ($elements_tag != false && count($elements_tag) > 0) {
|
Line 701... |
Line 672... |
701 |
|
672 |
|
702 |
$filtres = array();
|
673 |
$filtres = array();
|
703 |
foreach ($elements_tag as $occurence) {
|
674 |
foreach ($elements_tag as $occurence) {
|
704 |
$utilisateur = $occurence['utilisateur'];
|
675 |
$utilisateur = $occurence['utilisateur'];
|
705 |
$ordre = $occurence['ordre'];
|
676 |
$id_obs = $occurence['id_obs'];
|
706 |
if (!array_key_exists($utilisateur, $filtres)) {
|
677 |
if (!array_key_exists($utilisateur, $filtres)) {
|
707 |
$filtres[$utilisateur] = array();
|
678 |
$filtres[$utilisateur] = array();
|
708 |
}
|
679 |
}
|
709 |
if (!array_key_exists($ordre, $filtres[$utilisateur])) {
|
680 |
if (!array_key_exists($id_obs, $filtres[$utilisateur])) {
|
710 |
$filtres[$utilisateur][$ordre] = $ordre;
|
681 |
$filtres[$utilisateur][$id_obs] = $id_obs;
|
711 |
}
|
682 |
}
|
Line 712... |
Line 683... |
712 |
}
|
683 |
}
|
713 |
|
684 |
|
714 |
// Pré-construction du where de la requête
|
685 |
// Pré-construction du where de la requête
|
715 |
$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
|
686 |
$tpl_where = "(id_observation IN (%s))";
|
716 |
foreach ($filtres as $utilisateur => $ordres) {
|
687 |
foreach ($filtres as $utilisateur => $id_obs) {
|
Line 717... |
Line 688... |
717 |
$requete_tag[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
|
688 |
$requete_tag[] = sprintf($tpl_where, implode(',', $id_obs));
|
718 |
}
|
689 |
}
|
719 |
|
690 |
|
Line 731... |
Line 702... |
731 |
* Traitement de $tag pour construction du filtre dans la requête
|
702 |
* Traitement de $tag pour construction du filtre dans la requête
|
732 |
*/
|
703 |
*/
|
733 |
private function getSqlWhereMotsCles($tag) {
|
704 |
private function getSqlWhereMotsCles($tag) {
|
734 |
$sql = null;
|
705 |
$sql = null;
|
735 |
$mots_cles = $this->decomposerParametreTag($tag);
|
706 |
$mots_cles = $this->decomposerParametreTag($tag);
|
736 |
|
- |
|
737 |
// Construction de la requête
|
- |
|
738 |
$requete = 'SELECT cmc_id_proprietaire AS utilisateur, cmc_id_mot_cle_general AS mot_cle_general, '.
|
- |
|
739 |
' cmc_id_mot_cle_utilisateur AS mot_cle_utilisateur '.
|
- |
|
740 |
'FROM cel_mots_cles_images '.
|
- |
|
741 |
'WHERE '.$this->getSqlWhereMotsClesImages($mots_cles['motsClesEncodesProteges']);
|
- |
|
742 |
$elements_projet = $this->executerRequete($requete);
|
707 |
$requete_projet = $this->getSqlWhereMotsClesImages($tag);
|
743 |
//$this->debug[] = $requete;
|
- |
|
744 |
|
- |
|
745 |
$requete_projet = array();
|
- |
|
746 |
if ($elements_projet != false && count($elements_projet) > 0) {
|
- |
|
747 |
// Pré-construction du where de la requête
|
- |
|
748 |
if ($mots_cles['type'] == 'OR') {
|
- |
|
749 |
$tpl_where = '(ci_meta_mots_cles LIKE "%%%s,%%" AND ci_ce_utilisateur = %s )';
|
- |
|
750 |
foreach ($elements_projet as $occurence) {
|
- |
|
751 |
$requete_projet[] = sprintf($tpl_where, $occurence['mot_cle_utilisateur'], $this->bdd->quote($occurence['utilisateur']));
|
- |
|
752 |
}
|
- |
|
753 |
} else {
|
- |
|
754 |
$tpl_where_mc = "ci_meta_mots_cles LIKE '%%%s,%%'";
|
- |
|
755 |
$tpl_where = '((%s) AND ci_ce_utilisateur = %s)';
|
- |
|
756 |
$utilisateur_mc = array();
|
- |
|
757 |
foreach ($elements_projet as $occurence) {
|
- |
|
758 |
if (!isset($utilisateur_mc[$occurence['utilisateur']][$occurence['mot_cle_general']])) {
|
- |
|
759 |
$utilisateur_mc[$occurence['utilisateur']][$occurence['mot_cle_general']] = $occurence['mot_cle_utilisateur'];
|
- |
|
760 |
}
|
- |
|
761 |
}
|
- |
|
762 |
|
- |
|
763 |
foreach ($utilisateur_mc as $utilisateur => $mots_cles_utilisateur) {
|
- |
|
764 |
if (count($mots_cles_utilisateur) == count($mots_cles['motsCles'])) {
|
- |
|
765 |
$where_mots_cles_utilisateur = array();
|
- |
|
766 |
foreach ($mots_cles_utilisateur as $mot_cle) {
|
- |
|
767 |
$where_mots_cles_utilisateur[] = sprintf($tpl_where_mc, $mot_cle);
|
- |
|
768 |
}
|
- |
|
769 |
$where_mots_cles_utilisateur = implode(' AND ', $where_mots_cles_utilisateur);
|
- |
|
770 |
$utilisateur = $this->bdd->quote($utilisateur);
|
- |
|
771 |
$requete_projet[] = sprintf($tpl_where, $where_mots_cles_utilisateur, $utilisateur);
|
- |
|
772 |
}
|
- |
|
773 |
}
|
- |
|
774 |
}
|
- |
|
775 |
} else {
|
- |
|
776 |
$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
|
- |
|
777 |
}
|
- |
|
778 |
|
- |
|
779 |
$sql = implode(" \nOR ", $requete_projet);
|
708 |
$sql = implode(" \nOR ", $requete_projet);
|
780 |
//$this->debug[] = $sql;
|
709 |
//$this->debug[] = $sql;
|
781 |
return $sql;
|
710 |
return $sql;
|
782 |
}
|
711 |
}
|
Line 785... |
Line 714... |
785 |
* Traitement de $tag pour construction du filtre dans la requête
|
714 |
* Traitement de $tag pour construction du filtre dans la requête
|
786 |
*/
|
715 |
*/
|
787 |
private function getSqlWhereMotsClesImages($mots_cles_encodes) {
|
716 |
private function getSqlWhereMotsClesImages($mots_cles_encodes) {
|
788 |
$where_mots_cles_images = array();
|
717 |
$where_mots_cles_images = array();
|
789 |
foreach ($mots_cles_encodes as $mot_cle_encode) {
|
718 |
foreach ($mots_cles_encodes as $mot_cle_encode) {
|
790 |
$where_mots_cles_images[] = "cmc_id_mot_cle_general = $mot_cle_encode";
|
719 |
$where_mots_cles_images[] = "ci.mots_cles_texte = $mot_cle_encode";
|
791 |
}
|
720 |
}
|
792 |
$where_mots_cles_images = implode(' OR ', $where_mots_cles_images);
|
721 |
$where_mots_cles_images = implode(' OR ', $where_mots_cles_images);
|
793 |
return $where_mots_cles_images;
|
722 |
return $where_mots_cles_images;
|
794 |
}
|
723 |
}
|
Line 804... |
Line 733... |
804 |
} else {
|
733 |
} else {
|
805 |
$mots_cles['motsCles'][] = $tags;
|
734 |
$mots_cles['motsCles'][] = $tags;
|
806 |
}
|
735 |
}
|
Line 807... |
Line 736... |
807 |
|
736 |
|
808 |
foreach ($mots_cles['motsCles'] as $mot) {
|
737 |
foreach ($mots_cles['motsCles'] as $mot) {
|
809 |
$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote($this->encoderMotCle($mot));
|
738 |
$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote($mot);
|
810 |
}
|
739 |
}
|
811 |
$this->debug[] = $mots_cles;
|
740 |
$this->debug[] = $mots_cles;
|
812 |
return $mots_cles;
|
741 |
return $mots_cles;
|
Line 818... |
Line 747... |
818 |
$station = $this->parametres['station'];
|
747 |
$station = $this->parametres['station'];
|
819 |
$this->debug[] = $station;
|
748 |
$this->debug[] = $station;
|
820 |
list($type, $coord) = explode(':', $station);
|
749 |
list($type, $coord) = explode(':', $station);
|
Line 821... |
Line 750... |
821 |
|
750 |
|
822 |
if ($type == 'UTM') {
|
751 |
if ($type == 'UTM') {
|
823 |
list($x_utm, $y_utm, $secteur) = explode('-', $coord);
|
752 |
list($utm_x, $utm_y, $secteur) = explode('-', $coord);
|
824 |
$station_infos = array('x_utm' => $x_utm, 'y_utm' => $y_utm, 'secteur' => $secteur);
|
753 |
$station_infos = array('utm_x' => $utm_x, 'utm_y' => $utm_y, 'secteur' => $secteur);
|
825 |
} else if ($type == 'LngLat') {
|
754 |
} else if ($type == 'LngLat') {
|
826 |
list($coord_y, $coord_x) = explode('-', $coord);
|
755 |
list($longitude, $latitude) = explode('-', $coord);
|
827 |
$station_infos = array('coord_y' => $coord_y, 'coord_x' => $coord_x);
|
756 |
$station_infos = array('longitude' => $longitude, 'latitude' => $latitude);
|
828 |
}
|
757 |
}
|
829 |
$station_infos['type'] = $type;
|
758 |
$station_infos['type'] = $type;
|
830 |
}
|
759 |
}
|
831 |
return $station_infos;
|
760 |
return $station_infos;
|