Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 727 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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