727 |
alex |
1 |
<?php
|
|
|
2 |
|
747 |
alex |
3 |
/**
|
|
|
4 |
* Classe qui fournit une legende recuperee dans une table d'ontologies pour la renvoyer au client
|
|
|
5 |
*
|
|
|
6 |
* @package framework-0.4
|
|
|
7 |
* @author Alexandre GALIBERT <alexandre.galibert@tela-botanica.org>
|
|
|
8 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
9 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
10 |
* @version $Id$
|
|
|
11 |
* @copyright 2013 Tela Botanica (accueil@tela-botanica.org)
|
|
|
12 |
*
|
|
|
13 |
*/
|
|
|
14 |
|
727 |
alex |
15 |
class LegendeCartes {
|
|
|
16 |
|
|
|
17 |
const TYPE_MIME = 'application/json';
|
|
|
18 |
const ID_CLASSE = '10';
|
|
|
19 |
|
|
|
20 |
private $tableOntologies = '';
|
|
|
21 |
private $ontologies = array();
|
|
|
22 |
private $legende = array();
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
public function __construct() {
|
|
|
26 |
$this->tableOntologies = Config::get('bdd_table_ontologies');
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
public function obtenirLegende() {
|
|
|
30 |
$this->chargerOntologies();
|
|
|
31 |
$this->chargerLegende();
|
|
|
32 |
|
|
|
33 |
$resultat = new ResultatService();
|
|
|
34 |
$resultat->corps = $this->legende;
|
|
|
35 |
$resultat->mime = self::TYPE_MIME;
|
|
|
36 |
return $resultat;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
private function chargerOntologies() {
|
|
|
40 |
$bdd = new Bdd();
|
|
|
41 |
$requete = "SELECT * FROM {$this->tableOntologies}";
|
|
|
42 |
$resultats = $bdd->recupererTous($requete);
|
|
|
43 |
if (!is_array($resultats) || count($resultats) <= 0) {
|
|
|
44 |
$message = "Les données d'ontologies n'ont pu être chargées pour la ressource demandée";
|
|
|
45 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
46 |
throw new Exception($message, $code);
|
|
|
47 |
}
|
|
|
48 |
foreach ($resultats as $ontologie) {
|
|
|
49 |
$this->ontologies[$ontologie['id']] = $this->extraireComplementsOntologies($ontologie);
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
private function extraireComplementsOntologies($ontologie) {
|
|
|
54 |
if (strlen(trim($ontologie['complements'])) > 0) {
|
|
|
55 |
list($cle, $valeur) = explode('=', trim($ontologie['complements']));
|
|
|
56 |
$ontologie[trim($cle)] = trim($valeur);
|
|
|
57 |
}
|
|
|
58 |
return $ontologie;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
private function chargerLegende() {
|
|
|
62 |
foreach ($this->ontologies as $ontologie) {
|
|
|
63 |
if ($ontologie['classe_id'] == self::ID_CLASSE && isset($ontologie['legende'])) {
|
|
|
64 |
$this->legende[] = array(
|
|
|
65 |
'code' => $ontologie['code'],
|
|
|
66 |
'couleur' => $ontologie['legende'],
|
|
|
67 |
'nom' => $ontologie['nom'],
|
|
|
68 |
'description' => $ontologie['description']
|
|
|
69 |
);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
?>
|