727 |
alex |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class LegendeCartes {
|
|
|
4 |
|
|
|
5 |
const TYPE_MIME = 'application/json';
|
|
|
6 |
const ID_CLASSE = '10';
|
|
|
7 |
|
|
|
8 |
private $tableOntologies = '';
|
|
|
9 |
private $ontologies = array();
|
|
|
10 |
private $legende = array();
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
public function __construct() {
|
|
|
14 |
$this->tableOntologies = Config::get('bdd_table_ontologies');
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
public function obtenirLegende() {
|
|
|
18 |
$this->chargerOntologies();
|
|
|
19 |
$this->chargerLegende();
|
|
|
20 |
|
|
|
21 |
$resultat = new ResultatService();
|
|
|
22 |
$resultat->corps = $this->legende;
|
|
|
23 |
$resultat->mime = self::TYPE_MIME;
|
|
|
24 |
return $resultat;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
private function chargerOntologies() {
|
|
|
28 |
$bdd = new Bdd();
|
|
|
29 |
$requete = "SELECT * FROM {$this->tableOntologies}";
|
|
|
30 |
$resultats = $bdd->recupererTous($requete);
|
|
|
31 |
if (!is_array($resultats) || count($resultats) <= 0) {
|
|
|
32 |
$message = "Les données d'ontologies n'ont pu être chargées pour la ressource demandée";
|
|
|
33 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
34 |
throw new Exception($message, $code);
|
|
|
35 |
}
|
|
|
36 |
foreach ($resultats as $ontologie) {
|
|
|
37 |
$this->ontologies[$ontologie['id']] = $this->extraireComplementsOntologies($ontologie);
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
private function extraireComplementsOntologies($ontologie) {
|
|
|
42 |
if (strlen(trim($ontologie['complements'])) > 0) {
|
|
|
43 |
list($cle, $valeur) = explode('=', trim($ontologie['complements']));
|
|
|
44 |
$ontologie[trim($cle)] = trim($valeur);
|
|
|
45 |
}
|
|
|
46 |
return $ontologie;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
private function chargerLegende() {
|
|
|
50 |
foreach ($this->ontologies as $ontologie) {
|
|
|
51 |
if ($ontologie['classe_id'] == self::ID_CLASSE && isset($ontologie['legende'])) {
|
|
|
52 |
$this->legende[] = array(
|
|
|
53 |
'code' => $ontologie['code'],
|
|
|
54 |
'couleur' => $ontologie['legende'],
|
|
|
55 |
'nom' => $ontologie['nom'],
|
|
|
56 |
'description' => $ontologie['description']
|
|
|
57 |
);
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
?>
|