| 716 |
gduche |
1 |
<?php
|
|
|
2 |
/**
|
| 723 |
gduche |
3 |
* Le conteneur encapsule les classe Masque, Navigation et GestionBdd
|
|
|
4 |
* Il gère leur instanciation, ainsi que la récupération des paramètres depuis l'url ou
|
|
|
5 |
* les fichiers de configuration
|
| 716 |
gduche |
6 |
*
|
| 723 |
gduche |
7 |
* @category php 5.2
|
|
|
8 |
* @package del
|
|
|
9 |
* @author Grégoire Duché <gregoire@tela-botanica.org>
|
|
|
10 |
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
|
|
|
11 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
12 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
|
|
13 |
* @version $Id: Bdd.php 403 2012-02-22 14:35:20Z gduche $
|
|
|
14 |
*/
|
| 716 |
gduche |
15 |
class Conteneur {
|
|
|
16 |
|
| 723 |
gduche |
17 |
protected $parametres;
|
|
|
18 |
protected $navigation;
|
|
|
19 |
protected $masque;
|
|
|
20 |
protected $gestionBdd;
|
| 935 |
gduche |
21 |
protected $sansLimite = false;
|
| 723 |
gduche |
22 |
|
|
|
23 |
//TODO : initialiser tous les objets dans le conteneur
|
|
|
24 |
//TODO : créer un tableau de partage
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Constructeur de la classe
|
|
|
28 |
* @param Array $parametres (optionnel) les paramètres additionnels à ajouter à ceux des fichiers de config
|
|
|
29 |
* */
|
| 716 |
gduche |
30 |
public function __construct(array $parametres = null) {
|
|
|
31 |
$this->parametres = is_null($parametres) ? array() : $parametres;
|
|
|
32 |
}
|
|
|
33 |
|
| 723 |
gduche |
34 |
/**
|
|
|
35 |
* Charger la configuration depuis le fichier
|
|
|
36 |
* @param String $chemin le chemin relatif depuis le dossier configurations du fichier
|
|
|
37 |
* */
|
| 716 |
gduche |
38 |
public function chargerConfiguration($chemin) {
|
|
|
39 |
$cheminConfigurations = Config::get('chemin_configurations');
|
| 723 |
gduche |
40 |
if ($cheminConfigurations == null || $cheminConfigurations == '') {
|
|
|
41 |
$message = 'Le chemin vers le répertoire Configurations n\'est pas renseigné';
|
|
|
42 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
|
|
43 |
throw new Exception($message, $code);
|
|
|
44 |
}
|
| 716 |
gduche |
45 |
Config::charger($cheminConfigurations.DS.$chemin);
|
|
|
46 |
|
| 723 |
gduche |
47 |
if ($this->masque = $this->creerMasque()) {
|
|
|
48 |
$this->masque->chargerMasque();
|
|
|
49 |
} else {
|
|
|
50 |
$message = 'Erreur lors de la création du Masque';
|
|
|
51 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
|
|
52 |
throw new Exception($message, $code);
|
| 716 |
gduche |
53 |
}
|
|
|
54 |
|
| 723 |
gduche |
55 |
if ($this->navigation = $this->creerNavigation()) {
|
|
|
56 |
$this->navigation->chargerUrl();
|
| 716 |
gduche |
57 |
} else {
|
| 723 |
gduche |
58 |
$message = 'Erreur lors de la création de la Navigation';
|
|
|
59 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
|
|
60 |
throw new Exception($message, $code);
|
| 716 |
gduche |
61 |
}
|
| 723 |
gduche |
62 |
|
|
|
63 |
$this->creerGestionBdd($this->navigation, Config::get('schemaBdd'));
|
| 716 |
gduche |
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
| 723 |
gduche |
67 |
* Créer l'objet Masque en fonction des configurations
|
|
|
68 |
* */
|
|
|
69 |
private function creerMasque() {
|
|
|
70 |
$this->masque = new Masque(Config::get('masques_possibles'), $this->parametres);
|
|
|
71 |
return $this->masque;
|
| 716 |
gduche |
72 |
|
|
|
73 |
}
|
|
|
74 |
|
| 723 |
gduche |
75 |
/**
|
|
|
76 |
* Créer l'objet navigation avec les paramètres
|
|
|
77 |
* */
|
|
|
78 |
private function creerNavigation() {
|
|
|
79 |
return ($this->navigation = new Navigation($this->parametres));
|
| 716 |
gduche |
80 |
}
|
|
|
81 |
|
| 723 |
gduche |
82 |
/**
|
|
|
83 |
* Créer l'objet Gestion BDD
|
|
|
84 |
* */
|
|
|
85 |
private function creerGestionBdd($navigation, $schemaBdd) {
|
|
|
86 |
$this->gestionBdd = new GestionBdd($navigation, $schemaBdd);
|
| 716 |
gduche |
87 |
}
|
| 723 |
gduche |
88 |
|
| 716 |
gduche |
89 |
/**
|
| 723 |
gduche |
90 |
* Récupérer l'objet GestionBdd
|
|
|
91 |
* */
|
|
|
92 |
public function getGestionBdd() {
|
|
|
93 |
return $this->gestionBdd;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Récupérer l'objet Navigation
|
|
|
98 |
* */
|
|
|
99 |
public function getNavigation() {
|
|
|
100 |
return $this->navigation;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
| 935 |
gduche |
104 |
* Changer la valeur de sans limite pour ne pas l'afficher dans l'entete
|
|
|
105 |
* */
|
|
|
106 |
public function setSansLimite() {
|
|
|
107 |
$this->sansLimite = true;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
| 716 |
gduche |
111 |
* Créer l'entête en fonction des paramètres donnés
|
|
|
112 |
* */
|
|
|
113 |
public function getEntete() {
|
|
|
114 |
$entete = array();
|
| 723 |
gduche |
115 |
$entete['masque'] = $this->masque->getChaineMasque();
|
| 935 |
gduche |
116 |
|
| 936 |
gduche |
117 |
$entete['total'] = $this->navigation->getTotal();
|
| 1148 |
aurelien |
118 |
if ($this->sansLimite == false) {
|
| 935 |
gduche |
119 |
$entete['depart'] = $this->navigation->getDepart();
|
|
|
120 |
$entete['limite'] = $this->navigation->getLimite();
|
|
|
121 |
|
| 936 |
gduche |
122 |
$lienPrecedent = $this->navigation->recupererHrefPrecedent();
|
| 716 |
gduche |
123 |
|
| 936 |
gduche |
124 |
if ($lienPrecedent != null) {
|
|
|
125 |
$entete['href.precedent'] = $lienPrecedent;
|
|
|
126 |
}
|
| 716 |
gduche |
127 |
|
| 936 |
gduche |
128 |
$lienSuivant = $this->navigation->recupererHrefSuivant();
|
|
|
129 |
if ($lienSuivant) {
|
|
|
130 |
$entete['href.suivant'] = $lienSuivant;
|
|
|
131 |
}
|
| 716 |
gduche |
132 |
}
|
| 936 |
gduche |
133 |
|
| 716 |
gduche |
134 |
return $entete;
|
|
|
135 |
}
|
|
|
136 |
|
| 1249 |
aurelien |
137 |
public function getRestClient() {
|
|
|
138 |
if (!isset($this->restClient)) {
|
|
|
139 |
$this->restClient = new RestClient();
|
|
|
140 |
}
|
|
|
141 |
return $this->restClient;
|
|
|
142 |
}
|
|
|
143 |
|
| 716 |
gduche |
144 |
/**
|
| 723 |
gduche |
145 |
* Récupérer l'objet Masque
|
|
|
146 |
* */
|
|
|
147 |
public function getMasque() {
|
|
|
148 |
return $this->masque;
|
| 716 |
gduche |
149 |
}
|
|
|
150 |
|
|
|
151 |
/**
|
| 723 |
gduche |
152 |
* Obtenir un paramètre depuis le tableau de paramètres ou depuis le fichier de config
|
|
|
153 |
* @param String $cle le nom du paramètre
|
|
|
154 |
* @return la valeur du paramètre
|
| 716 |
gduche |
155 |
* */
|
|
|
156 |
public function getParametre($cle) {
|
|
|
157 |
$valeur = isset($this->parametres[$cle]) ? $this->parametres[$cle] : Config::get($cle);
|
|
|
158 |
return $valeur;
|
|
|
159 |
}
|
| 723 |
gduche |
160 |
|
|
|
161 |
/**
|
|
|
162 |
* Enregistrer la valeur d'un paramètre
|
|
|
163 |
* */
|
| 716 |
gduche |
164 |
public function setParametre($cle, $valeur) {
|
|
|
165 |
$this->parametres[$cle] = $valeur;
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
?>
|