701 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Gère le sous-service Legende de Cartes.
|
|
|
5 |
*
|
|
|
6 |
* @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01Cartes
|
|
|
7 |
*
|
|
|
8 |
* @package eFlore/services
|
|
|
9 |
* @author Jean-Pascal MILCENT <jpm@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-2012 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 LegendeCartes {
|
|
|
17 |
|
|
|
18 |
private $parametres = array();
|
|
|
19 |
private $ressources = array();
|
|
|
20 |
|
|
|
21 |
const MIME_JSON = 'application/json';
|
|
|
22 |
const PRESENCE_CHOROLOGIE = '15';
|
|
|
23 |
|
|
|
24 |
private $formatsSupportes = array(self::MIME_JSON);
|
|
|
25 |
private $tableOntologie = '';
|
1299 |
delphine |
26 |
private $ontologies = [];
|
701 |
aurelien |
27 |
private $legende = array();
|
|
|
28 |
|
|
|
29 |
public function __construct(Conteneur $conteneur) {
|
|
|
30 |
$this->Bdd = $conteneur->getBdd();
|
|
|
31 |
$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public function consulter($ressources, $parametres) {
|
|
|
35 |
//$tpsDebut = microtime(true);
|
|
|
36 |
$this->parametres = $parametres;
|
|
|
37 |
$this->ressources = $ressources;
|
|
|
38 |
|
|
|
39 |
$this->definirValeurParDefautDesParametres();
|
|
|
40 |
$this->verifierParametres();
|
|
|
41 |
|
|
|
42 |
$resultat = $this->obtenirResultat();
|
|
|
43 |
|
|
|
44 |
return $resultat;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
private function definirValeurParDefautDesParametres() {
|
|
|
48 |
if (isset($this->parametres['retour']) == false) {
|
|
|
49 |
$this->parametres['retour'] = self::MIME_JSON;
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
private function verifierParametres() {
|
|
|
54 |
$erreurs = array();
|
|
|
55 |
|
|
|
56 |
if (isset($this->parametres['retour']) == false) {
|
|
|
57 |
$erreurs[] = "Le paramètre type de retour 'retour' est obligatoire.";
|
|
|
58 |
}
|
|
|
59 |
if ($this->verifierValeurParametreRetour() == false) {
|
|
|
60 |
$erreurs[] = "Le type de retour '{$this->parametres['retour']}' n'est pas supporté.";
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
if (count($erreurs) > 0) {
|
|
|
64 |
$message = implode('<br />', $erreurs);
|
|
|
65 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
|
|
66 |
throw new Exception($message, $code);
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
private function verifierValeurParametreRetour() {
|
|
|
71 |
return in_array($this->parametres['retour'], $this->formatsSupportes);
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
private function obtenirResultat() {
|
|
|
75 |
$this->chargerOntologies();
|
|
|
76 |
$this->chargerLegende();
|
|
|
77 |
|
|
|
78 |
$resultat = new ResultatService();
|
|
|
79 |
$resultat->corps = $this->legende;
|
|
|
80 |
$resultat->mime = $this->parametres['retour'];
|
|
|
81 |
|
|
|
82 |
return $resultat;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
private function chargerOntologies() {
|
|
|
86 |
$requete = "SELECT * FROM {$this->tableOntologie} ";
|
|
|
87 |
$resultats = $this->Bdd->recupererTous($requete);
|
|
|
88 |
|
|
|
89 |
if (!is_array($resultats) || count($resultats) <= 0) {
|
|
|
90 |
$message = "Les données d'ontologies n'ont pu être chargées pour la ressource demandée";
|
|
|
91 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
92 |
throw new Exception($message, $code);
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
foreach ($resultats as $ontologie) {
|
951 |
raphael |
96 |
$this->ontologies[$ontologie['id']] = Commun::extraireComplementsOntologies($ontologie);
|
701 |
aurelien |
97 |
}
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
private function chargerLegende() {
|
|
|
101 |
foreach ($this->ontologies as $ontologie) {
|
|
|
102 |
if ($ontologie['classe_id'] == self::PRESENCE_CHOROLOGIE) {
|
|
|
103 |
$this->legende[] = array(
|
|
|
104 |
'code' => $ontologie['code'],
|
|
|
105 |
'couleur' => $ontologie['legende'],
|
|
|
106 |
'nom' => $ontologie['nom'],
|
|
|
107 |
'description' => $ontologie['description']);
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
?>
|