Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
class LegendeCartes {
const TYPE_MIME = 'application/json';
const ID_CLASSE = '10';
private $tableOntologies = '';
private $ontologies = array();
private $legende = array();
public function __construct() {
$this->tableOntologies = Config::get('bdd_table_ontologies');
}
public function obtenirLegende() {
$this->chargerOntologies();
$this->chargerLegende();
$resultat = new ResultatService();
$resultat->corps = $this->legende;
$resultat->mime = self::TYPE_MIME;
return $resultat;
}
private function chargerOntologies() {
$bdd = new Bdd();
$requete = "SELECT * FROM {$this->tableOntologies}";
$resultats = $bdd->recupererTous($requete);
if (!is_array($resultats) || count($resultats) <= 0) {
$message = "Les données d'ontologies n'ont pu être chargées pour la ressource demandée";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
foreach ($resultats as $ontologie) {
$this->ontologies[$ontologie['id']] = $this->extraireComplementsOntologies($ontologie);
}
}
private function extraireComplementsOntologies($ontologie) {
if (strlen(trim($ontologie['complements'])) > 0) {
list($cle, $valeur) = explode('=', trim($ontologie['complements']));
$ontologie[trim($cle)] = trim($valeur);
}
return $ontologie;
}
private function chargerLegende() {
foreach ($this->ontologies as $ontologie) {
if ($ontologie['classe_id'] == self::ID_CLASSE && isset($ontologie['legende'])) {
$this->legende[] = array(
'code' => $ontologie['code'],
'couleur' => $ontologie['legende'],
'nom' => $ontologie['nom'],
'description' => $ontologie['description']
);
}
}
}
}
?>