578 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe implémentant l'API d'eFlore concernant les statuts de protection
|
|
|
5 |
*
|
|
|
6 |
* @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01Status
|
|
|
7 |
*
|
|
|
8 |
* @package eFlore/services
|
|
|
9 |
* @author Aurélien PERONNET <aurelien@tela-botanica.org>
|
|
|
10 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
11 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
12 |
* @version 1.0
|
|
|
13 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
|
|
14 |
*/
|
|
|
15 |
// TODO : Config et Outils sont des classes statiques qui doivent poser des pb pour les tests...
|
|
|
16 |
class Statuts extends Commun {
|
|
|
17 |
|
|
|
18 |
protected $parametres = array();
|
|
|
19 |
protected $ressources = array();
|
|
|
20 |
private $bdd;
|
|
|
21 |
|
|
|
22 |
public function __construct($config = null) {
|
|
|
23 |
$this->config = $config;
|
|
|
24 |
$this->bdd = $this->getBdd();
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
public function consulter($ressources, $parametres) {
|
|
|
28 |
|
|
|
29 |
$this->parametres = $parametres;
|
|
|
30 |
$this->ressources = $ressources;
|
|
|
31 |
|
|
|
32 |
$this->verifierParametres();
|
|
|
33 |
|
|
|
34 |
$resultat = new ResultatService();
|
|
|
35 |
$resultat->corps = $this->obtenirStatuts();
|
|
|
36 |
|
|
|
37 |
return $resultat;
|
|
|
38 |
}
|
|
|
39 |
//+---------------------------FONCTION D'ANALYSE DES PARAMETRES---------------------------------------------------------+
|
|
|
40 |
|
|
|
41 |
private function verifierParametres() {
|
|
|
42 |
$erreurs = array();
|
|
|
43 |
|
|
|
44 |
if (empty($this->parametres['masque.nn'])) {
|
|
|
45 |
$erreurs[] = 'renseignez une valeur pour masque.nn';
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
if(!is_numeric($this->parametres['masque.nn'])) {
|
|
|
49 |
$erreurs[] = 'la valeur pour masque.nn doit être un entier';
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
if (count($erreurs) > 0) {
|
|
|
53 |
$message = implode('<br />', $erreurs);
|
|
|
54 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
|
|
55 |
throw new Exception($message, $code);
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
//+---------------------------FONCTIONS DE REQUETE---------------------------------------------------------+
|
|
|
60 |
|
|
|
61 |
private function obtenirLois(Array $id_lois) {
|
|
|
62 |
$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois);
|
|
|
63 |
$requete = "SELECT * FROM sptb_lois_v2012 ".
|
|
|
64 |
"WHERE id IN (".implode(',',$id_lois).") ";
|
|
|
65 |
return $this->bdd->recupererTous($requete);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
private function obtenirStatuts() {
|
|
|
69 |
$requete = "SELECT * FROM sptb_especes_v2012 ".
|
|
|
70 |
"WHERE ".
|
|
|
71 |
"num_nom = ".$this->bdd->proteger($this->parametres['masque.nn'])."";
|
|
|
72 |
|
|
|
73 |
$statuts = $this->bdd->recuperer($requete);
|
|
|
74 |
$statuts = $this->formaterStatutsTaxon($statuts);
|
|
|
75 |
return $statuts;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
//+---------------------------FONCTIONS DE FORMATAGE---------------------------------------------------------+
|
|
|
79 |
private function formaterStatutsTaxon($statuts_taxon) {
|
|
|
80 |
$statuts_formates = array();
|
|
|
81 |
unset($statuts_taxon['num_nom']);
|
|
|
82 |
unset($statuts_taxon['nom_sci']);
|
|
|
83 |
$lois_statuts = array();
|
|
|
84 |
foreach ($statuts_taxon as $champ => $statut) {
|
|
|
85 |
if($statut == "1") {
|
|
|
86 |
$lois_statuts[] = $champ;
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
$statuts_formates = (!empty($lois_statuts)) ? $this->obtenirLois($lois_statuts) : array();
|
|
|
91 |
|
|
|
92 |
return $statuts_formates;
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
?>
|