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