Line 60... |
Line 60... |
60 |
*/
|
60 |
*/
|
61 |
protected $format_reponse = 'observations';
|
61 |
protected $format_reponse = 'observations';
|
Line 62... |
Line 62... |
62 |
|
62 |
|
63 |
// +-------------------------------------------------------------------------------------------------------------------+
|
63 |
// +-------------------------------------------------------------------------------------------------------------------+
|
- |
|
64 |
public function consulter($ressources, $parametres) {
|
64 |
public function consulter($ressources, $parametres) {
|
65 |
$this->parametres = $parametres;
|
65 |
$this->traiterVersionProjet($ressources);
|
66 |
$this->traiterVersionProjet($ressources);
|
66 |
$this->traiterRessources($ressources);
|
67 |
$this->traiterRessources($ressources);
|
Line 67... |
Line 68... |
67 |
$resultat_formate = '';
|
68 |
$resultat_formate = '';
|
Line 108... |
Line 109... |
108 |
}
|
109 |
}
|
Line 109... |
Line 110... |
109 |
|
110 |
|
110 |
public function assemblerLaRequete() {
|
111 |
public function assemblerLaRequete() {
|
111 |
$requete = "SELECT ".$this->formerRequeteChamp().
|
112 |
$requete = "SELECT ".$this->formerRequeteChamp().
|
112 |
" FROM ".$this->table.$this->formerRequeteCondition().
|
113 |
" FROM ".$this->table.$this->formerRequeteCondition().
|
113 |
' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
114 |
' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];//echo $requete;
|
114 |
return $requete;
|
115 |
return $requete;
|
Line 115... |
Line 116... |
115 |
}
|
116 |
}
|
116 |
|
117 |
|
Line 303... |
Line 304... |
303 |
public function ajouterLimiteDepart($id) {
|
304 |
public function ajouterLimiteDepart($id) {
|
304 |
$d = explode(":", $id);
|
305 |
$d = explode(":", $id);
|
305 |
$this->limite_requete['depart'] = 0;
|
306 |
$this->limite_requete['depart'] = 0;
|
306 |
$this->limite_requete['dept'] = $d[1];
|
307 |
$this->limite_requete['dept'] = $d[1];
|
307 |
$requete_condition = (is_numeric($d[0])) ? '`num_nom` = '.$d[0] : '`nom_sci` like "'.urldecode($d[0]).'%"';
|
308 |
$requete_condition = (is_numeric($d[0])) ? '`num_nom` = '.$d[0] : '`nom_sci` like "'.urldecode($d[0]).'%"';
|
308 |
$requete = "SELECT id FROM $this->table WHERE ".$requete_condition; //echo $requete;
|
309 |
$requete = "SELECT id FROM $this->table WHERE ".$requete_condition;
|
309 |
$res = $this->getBdd()->recuperer($requete);
|
310 |
$res = $this->getBdd()->recuperer($requete);
|
310 |
if ($res == '') { //cas ou la requete comporte des erreurs
|
311 |
if ($res == '') { //cas ou la requete comporte des erreurs
|
311 |
$r = 'La requête SQL formée comporte une erreur !!';
|
312 |
$r = 'La requête SQL formée comporte une erreur !!';
|
312 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
|
313 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
|
313 |
Debug::printr($requete);
|
314 |
Debug::printr($requete);
|
Line 335... |
Line 336... |
335 |
|
336 |
|
336 |
public function formaterObservations($resultat) {
|
337 |
public function formaterObservations($resultat) {
|
337 |
$num = 0; // compte le nombre d'observations pour retourner le nombre d'obs indiqué
|
338 |
$num = 0; // compte le nombre d'observations pour retourner le nombre d'obs indiqué
|
338 |
$depart = false; //le depart du resultat est noté ss forme #ligne:#departement $depart indique le departement est correct
|
339 |
$depart = false; //le depart du resultat est noté ss forme #ligne:#departement $depart indique le departement est correct
|
- |
|
340 |
//on remplit la table $table_retour_json['resultat']
|
339 |
//on remplit la table $table_retour_json['resultat']
|
341 |
//$this->table_retour = array();
|
340 |
foreach ($resultat as $tab) {
|
342 |
foreach ($resultat as $tab) {
|
341 |
foreach ($tab as $key => $valeur) {
|
343 |
foreach ($tab as $key => $valeur) {
|
342 |
switch ($key) {
|
344 |
switch ($key) {
|
343 |
case 'id' : break;
|
345 |
case 'id' : break;
|
Line 348... |
Line 350... |
348 |
case 'freq_rel' : break;
|
350 |
case 'freq_rel' : break;
|
349 |
case 'rare_nat' : break;
|
351 |
case 'rare_nat' : break;
|
350 |
case 'num_nom' : ($valeur == 'nc')? $num_nom = urlencode($tab['nom_sci']) : $num_nom = $valeur ; break;
|
352 |
case 'num_nom' : ($valeur == 'nc')? $num_nom = urlencode($tab['nom_sci']) : $num_nom = $valeur ; break;
|
351 |
case 'nom_sci' : $this->table_retour['determination.nom_sci'] = $valeur; break;
|
353 |
case 'nom_sci' : $this->table_retour['determination.nom_sci'] = $valeur; break;
|
352 |
default : // pour les depts
|
354 |
default : // pour les depts
|
353 |
if ($depart == true && $valeur != '') {
|
355 |
if (isset($this->parametres['masque.station'])) {
|
354 |
if (($this->presenceChorologie != '' && $valeur == $this->presenceChorologie) || ($this->presenceChorologie == '' && $valeur != $this->presenceChorologie)) {
|
356 |
if ($key == $this->parametres['masque.station']) {
|
355 |
$id = $num_nom.":".$key;
|
357 |
$id = $num_nom.":".$key;
|
356 |
if ($this->retour_format == 'max' ) {
|
- |
|
357 |
$this->afficherDonneesMax($key, $valeur);
|
358 |
$this->completerDonnees($key, $valeur, $id);
|
358 |
$this->table_retour['href'] = $this->ajouterHref('observations',$id);
|
- |
|
359 |
} else {
|
- |
|
360 |
$this->table_retour['station.departement.code'] = 'INSEE-D.'.$key;
|
- |
|
361 |
$this->table_retour['valeur.code'] = $valeur;
|
- |
|
362 |
}
|
- |
|
363 |
$resultat_json[$id] = $this->table_retour;
|
359 |
$resultat_json[$id] = $this->table_retour;
|
364 |
$num++;
|
360 |
$num++;
|
365 |
}
|
361 |
}
|
- |
|
362 |
} else {
|
- |
|
363 |
if ($depart == true && $valeur != '') {
|
- |
|
364 |
if (($this->presenceChorologie != '' && $valeur == $this->presenceChorologie) ||
|
- |
|
365 |
($this->presenceChorologie == '' && $valeur != $this->presenceChorologie)) {
|
- |
|
366 |
$id = $num_nom.":".$key;
|
- |
|
367 |
$this->completerDonnees($key, $valeur, $id);
|
- |
|
368 |
$resultat_json[$id] = $this->table_retour;
|
- |
|
369 |
$num++;
|
- |
|
370 |
}
|
- |
|
371 |
}
|
- |
|
372 |
if ($key == $this->limite_requete['dept']) $depart = true;
|
366 |
}
|
373 |
}
|
367 |
if ($key == $this->limite_requete['dept']) $depart = true;
|
- |
|
368 |
break;
|
374 |
break;
|
369 |
}
|
375 |
}
|
370 |
if ($num == $this->limite_requete['limite']) {
|
376 |
if ($num == $this->limite_requete['limite']) {
|
371 |
break;
|
377 |
break;
|
372 |
}
|
378 |
}
|
Line 383... |
Line 389... |
383 |
if ($url['suivant'] != '') { $this->table_entete['href.suivant'] = $url['suivant']; }
|
389 |
if ($url['suivant'] != '') { $this->table_entete['href.suivant'] = $url['suivant']; }
|
384 |
$this->table_entete['total'] = $num;
|
390 |
$this->table_entete['total'] = $num;
|
385 |
$table_retour_json['entete'] = $this->table_entete;
|
391 |
$table_retour_json['entete'] = $this->table_entete;
|
386 |
$table_retour_json['resultat'] = $resultat_json;
|
392 |
$table_retour_json['resultat'] = $resultat_json;
|
387 |
return $table_retour_json;
|
393 |
return $table_retour_json;
|
388 |
}
|
394 |
}
|
- |
|
395 |
|
- |
|
396 |
public function completerDonnees($key, $valeur, $id) {
|
- |
|
397 |
if ($this->retour_format == 'max' ) {
|
- |
|
398 |
$this->afficherDonneesMax($key, $valeur);
|
- |
|
399 |
$this->table_retour['href'] = $this->ajouterHref('observations',$id);
|
- |
|
400 |
} else {
|
- |
|
401 |
$this->table_retour['station.departement.code'] = 'INSEE-D.'.$key;
|
- |
|
402 |
$this->table_retour['valeur.code'] = $valeur;
|
- |
|
403 |
}
|
- |
|
404 |
}
|
Line 389... |
Line 405... |
389 |
|
405 |
|
390 |
public function formaterObservationsId($resultat) {
|
406 |
public function formaterObservationsId($resultat) {
|
391 |
foreach ($resultat as $key => $valeur) {
|
407 |
foreach ($resultat as $key => $valeur) {
|
392 |
switch ($key) {
|
408 |
switch ($key) {
|
Line 412... |
Line 428... |
412 |
|
428 |
|
413 |
public function afficherDonneesMax($key, $valeur, $id = false) {
|
429 |
public function afficherDonneesMax($key, $valeur, $id = false) {
|
414 |
if ($key != 20) { //à part la Corse
|
430 |
if ($key != 20) { //à part la Corse
|
415 |
$url_dep = $this->ajouterHrefAutreProjet('zone-geo','',$key, 'insee-d');
|
431 |
$url_dep = $this->ajouterHrefAutreProjet('zone-geo','',$key, 'insee-d');
|
- |
|
432 |
$dep = $this->consulterHref($url_dep);
|
416 |
$dep = $this->consulterHref($url_dep);
|
433 |
if (isset($dep)) {
|
417 |
$this->table_retour['station.departement'] = $dep->nom;
|
434 |
$this->table_retour['station.departement'] = $dep->nom;
|
418 |
$this->table_retour['station.departement.code'] = 'INSEE-D.'.$key;
|
435 |
$this->table_retour['station.departement.code'] = 'INSEE-D.'.$key;
|
- |
|
436 |
$this->table_retour['station.departement.href'] = $url_dep;
|
- |
|
437 |
} else {
|
- |
|
438 |
$this->table_retour['station.departement.code'] = 'INSEE-D.'.$key;
|
419 |
$this->table_retour['station.departement.href'] = $url_dep;
|
439 |
}
|
420 |
} else {
|
440 |
} else {
|
421 |
$this->table_retour['station.departement.code'] = 'INSEE-D.'.$key;
|
441 |
$this->table_retour['station.departement.code'] = 'INSEE-D.'.$key;
|
422 |
}
|
442 |
}
|
423 |
//double encodage des paramétres contre validation de Apache
|
443 |
//double encodage des paramétres contre validation de Apache
|