Subversion Repositories eFlore/Applications.del

Rev

Rev 716 | Rev 905 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 716 Rev 723
Line 1... Line 1...
1
<?php
1
<?php
2
/**
2
/**
-
 
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
3
 * 
6
 * 
-
 
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 $
4
 * */
14
 */
5
class Conteneur {
15
class Conteneur {
6
	protected $parametres = array();
-
 
7
	protected $partages = array();
-
 
8
	protected $masque = array();
-
 
9
	protected $urlNavigation;
-
 
10
	protected $total;
-
 
Line -... Line 16...
-
 
16
	
-
 
17
	protected $parametres;
-
 
18
	protected $navigation;
-
 
19
	protected $masque;
-
 
20
	protected $gestionBdd;
-
 
21
	
-
 
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
11
	
29
	 * */
12
	public function __construct(array $parametres = null) {
30
	public function __construct(array $parametres = null) {
13
		$this->parametres = is_null($parametres) ? array() : $parametres;
-
 
14
				
31
		$this->parametres = is_null($parametres) ? array() : $parametres;
Line -... Line 32...
-
 
32
	}
-
 
33
	
-
 
34
	/**
-
 
35
	 * Charger la configuration depuis le fichier
15
	}
36
	 * @param String $chemin le chemin relatif depuis le dossier configurations du fichier 
16
	
37
	 * */
-
 
38
	public function chargerConfiguration($chemin) {
-
 
39
		$cheminConfigurations = Config::get('chemin_configurations');
-
 
40
		if ($cheminConfigurations == null || $cheminConfigurations == '') {
-
 
41
			$message = 'Le chemin vers le répertoire Configurations n\'est pas renseigné';
-
 
42
			$code = RestServeur::HTTP_CODE_ERREUR;
17
	public function chargerConfiguration($chemin) {
43
			throw new Exception($message, $code);
18
		$cheminConfigurations = Config::get('chemin_configurations');
-
 
19
		Config::charger($cheminConfigurations.DS.$chemin);
-
 
20
		$this->chargerMasque();
-
 
21
		$this->chargerUrl();
-
 
22
	}
-
 
23
	
-
 
24
	public function getDepart() {
-
 
25
		return isset($this->parametres['navigation.depart']) ? $this->parametres['navigation.depart'] : 0;
-
 
26
	}
-
 
27
	
-
 
28
	public function getLimite() {
-
 
29
		return isset($this->parametres['navigation.limite']) ? $this->parametres['navigation.limite'] : 10;
-
 
30
	}
-
 
31
	
-
 
32
	private function chargerMasque() {
-
 
Line 33... Line 44...
33
		$masques = Config::get('masques_possibles');
44
		}
34
		$masquesPossibles = explode(',', $masques);
45
		Config::charger($cheminConfigurations.DS.$chemin);
-
 
46
		
35
		
47
		if ($this->masque = $this->creerMasque()) {
36
		foreach ($this->parametres as $id => $parametre) {
48
			$this->masque->chargerMasque();
37
			if (strpos($id, 'masque.') === 0) {
49
		} else {
38
				if (in_array(str_replace('masque.', '', $id), $masquesPossibles)) {
-
 
39
					$this->masque[$id] = $parametre;
50
			$message = 'Erreur lors de la création du Masque';
Line 40... Line -...
40
				} 
-
 
41
			}
-
 
42
		}
-
 
43
		
51
			$code = RestServeur::HTTP_CODE_ERREUR;
44
	}
-
 
45
	
-
 
46
	private function chargerUrl() {
-
 
47
		$this->UrlNavigation = new Url(Config::get('url_service'));
-
 
48
		$this->UrlNavigation->setOption(Url::OPTION_ENCODER_VALEURS, true);
-
 
49
	}
52
			throw new Exception($message, $code);
50
	
53
		}
-
 
54
		
-
 
55
		if ($this->navigation = $this->creerNavigation()) {
51
	public function getUrl($depart = null, $limite = null) {
56
			$this->navigation->chargerUrl();
52
		if ($depart == null && $limite == null) {
57
		} else {
-
 
58
			$message = 'Erreur lors de la création de la Navigation';
-
 
59
			$code = RestServeur::HTTP_CODE_ERREUR;
53
			return $this->urlNavigation;
60
			throw new Exception($message, $code);
Line 54... Line 61...
54
		} else {
61
		}
55
			return $this->obtenirUrlNavigation($depart, $limite);
62
		
56
		}
-
 
57
	}
-
 
58
	
-
 
59
	/**
63
		$this->creerGestionBdd($this->navigation, Config::get('schemaBdd'));
60
	* Récupérer l'url de navigation en concaténant d'éventuels paramètres
64
	}
61
	* @param $depart l'entier de départ de la recherche
-
 
62
	* @param $limite le nombre de résultats à retourner
65
	
63
	* @param $parametresAdditionnels le tableau contenant les parametres => valeurs additionnels
-
 
64
	* */
66
	/**
Line 65... Line -...
65
	private function obtenirUrlNavigation($depart, $limite) {
-
 
66
	
-
 
67
		$parametres = $this->parametres;
-
 
68
		$parametres['navigation.depart'] = $depart;
67
	 * Créer l'objet Masque en fonction des configurations
Line -... Line 68...
-
 
68
	 * */
-
 
69
	private function creerMasque() {
-
 
70
		$this->masque = new Masque(Config::get('masques_possibles'), $this->parametres);
69
		$parametres['navigation.limite'] = $limite;
71
		return $this->masque;
-
 
72
		
-
 
73
	}
-
 
74
	
-
 
75
	/**
70
		
76
	 * Créer l'objet navigation avec les paramètres
-
 
77
	 * */
-
 
78
	private function creerNavigation() {
-
 
79
		return ($this->navigation = new Navigation($this->parametres));
71
		$this->UrlNavigation->setRequete($parametres);
80
	}
Line -... Line 81...
-
 
81
	
-
 
82
	/**
-
 
83
	 * Créer l'objet Gestion BDD
-
 
84
	 * */
-
 
85
	private function creerGestionBdd($navigation, $schemaBdd) {
-
 
86
		$this->gestionBdd = new GestionBdd($navigation, $schemaBdd);
-
 
87
	}
-
 
88
	
-
 
89
	/**
-
 
90
	 * Récupérer l'objet GestionBdd
72
		$url = $this->UrlNavigation->getURL();
91
	 * */
73
		return $url;
92
	public function getGestionBdd() {
74
	}
93
		return $this->gestionBdd;
-
 
94
	}
75
	
95
 
76
	public function getTotal() {
96
	/**
77
		return $this->total;
97
	 * Récupérer l'objet Navigation
78
	}
98
	 * */
79
	
99
	public function getNavigation() {
80
	public function setTotal($total) {
100
		return $this->navigation;
81
		$this->total = $total;
101
	}
82
	}
102
	
83
	/**
103
	/**
84
	* Créer l'entête en fonction des paramètres donnés
104
	* Créer l'entête en fonction des paramètres donnés
Line 85... Line 105...
85
	* */
105
	* */
86
	public function getEntete() {
106
	public function getEntete() {
87
		$entete = array();
107
		$entete = array();
Line 88... Line 108...
88
		$entete['masque'] = $this->getChaineMasque();
108
		$entete['masque'] = $this->masque->getChaineMasque();
89
		$entete['depart'] = $this->getDepart();
109
		$entete['depart'] = $this->navigation->getDepart();
90
		$entete['limite'] = $this->getLimite();
110
		$entete['limite'] = $this->navigation->getLimite();
91
		$entete['total'] = $this->getTotal();
111
		$entete['total'] = $this->navigation->getTotal();
92
		$lienPrecedent = $this->recupererHrefPrecedent();
112
		$lienPrecedent = $this->navigation->recupererHrefPrecedent();
93
	
113
	
Line 94... Line 114...
94
		if ($lienPrecedent != null) {
114
		if ($lienPrecedent != null) {
95
			$entete['entete.precedent'] = $lienPrecedent;
115
			$entete['entete.precedent'] = $lienPrecedent;
96
		}
116
		}
97
	
117
	
98
		$lienSuivant = $this->recupererHrefSuivant();
-
 
99
		if ($lienSuivant) {
-
 
100
			$entete['entete.suivant'] = $lienSuivant;
-
 
101
		}
-
 
102
		return $entete;
-
 
103
	}
-
 
104
	
-
 
105
	/**
-
 
106
	* Récupérer le lien pour afficher les images précédentes en fonction des paramètres
-
 
107
	* */
118
		$lienSuivant = $this->navigation->recupererHrefSuivant();
108
	private function recupererHrefPrecedent() {
119
		if ($lienSuivant) {
Line 109... Line 120...
109
		$departActuel = $this->getDepart();
120
			$entete['entete.suivant'] = $lienSuivant;
110
		$limite = $this->getLimite();
121
		}
-
 
122
		return $entete;
-
 
123
	}
111
		$departPrecedent = $departActuel - $limite;
124
	
112
	
-
 
113
		$url = null;
-
 
114
	
-
 
115
		if ($departActuel > 0) {
-
 
116
			$url = $this->getUrl($departPrecedent, $limite);
-
 
117
		}
-
 
118
		return $url;
-
 
119
	}
-
 
120
	
-
 
121
	/**
-
 
122
	 * Récupérer le lien pour afficher les images suivantes en fonction des paramètres
-
 
123
	 * */
-
 
124
	private function recupererHrefSuivant() {
-
 
125
		
-
 
126
		$departActuel = $this->getDepart();
-
 
127
		$limite = $this->getLimite();
-
 
128
		$departSuivant = $departActuel + $limite;
-
 
129
		$url = null;
-
 
130
		if ($departSuivant < $this->total) {
-
 
131
			$url = $this->getUrl($departSuivant, $limite);
-
 
132
		}
-
 
133
		return $url;
-
 
134
	}
-
 
135
	
-
 
136
	public function getMasque($id = null) {
-
 
137
		if (isset($id)) {
-
 
138
			return $this->masque['masque.'.$id];
-
 
139
		} else {
-
 
140
			return $this->masque;
125
	/**
141
		}	
126
	 * Récupérer l'objet Masque 
142
	}
127
	 * */
143
	
128
	public function getMasque() {
144
	public function getChaineMasque() {
-
 
145
		$chaine = array();
-
 
146
		foreach ($this->masque as $id => $valeur) {
-
 
147
			$chaine[] = $id.'='.$valeur;
-
 
148
		}
-
 
149
		return implode('&', $chaine);
-
 
150
	}
-
 
151
	
-
 
152
	public function getParametre($cle) {
-
 
153
		$valeur = isset($this->parametres[$cle]) ? $this->parametres[$cle] : Config::get($cle);
-
 
154
		return $valeur;
-
 
155
	}
-
 
156
	public function getParametreTableau($cle) {
-
 
157
		$tableau = array();
129
		return $this->masque;
158
		$parametre = $this->getParametre($cle);
130
	}
159
		if (empty($parametre) === false) {
131
	
160
			$tableauPartiel = explode(',', $parametre);
132
	/**
161
			$tableauPartiel = array_map('trim', $tableauPartiel);
-
 
162
			foreach ($tableauPartiel as $champ) {
133
	 * Obtenir un paramètre depuis le tableau de paramètres ou depuis le fichier de config
163
				if (strpos($champ, '=') === false) {
134
	 * @param String $cle le nom du paramètre
164
					$tableau[] = trim($champ);
135
	 * @return la valeur du paramètre
165
				} else {
-
 
166
					list($cle, $val) = explode('=', $champ);
-
 
167
					$tableau[trim($cle)] = trim($val);
-
 
168
				}
-
 
169
			}
-
 
170
		}
-
 
171
		return $tableau;
-
 
172
	}
-
 
173
 
-
 
174
	public function setParametre($cle, $valeur) {
-
 
175
		$this->parametres[$cle] = $valeur;
-
 
176
	}
-
 
177
 
-
 
178
	public function getParametresUrl() {
-
 
179
		if (!isset($this->partages['Parametres'])){
-
 
180
			$this->partages['Parametres'] = new Parametres($this->parametres['parametres'], $this->getBdd());
-
 
181
		}
-
 
182
		return $this->partages['Parametres'];
-
 
183
	}
-
 
184
 
-
 
185
	public function getParametresUrlVerificateur() {
-
 
186
		if (!isset($this->partages['ParametresVerificateur'])){
-
 
187
			$parametres = $this->getParametresUrl();
-
 
188
			$parametresAPI = $this->getParametreTableau('parametresAPI');
-
 
189
			$this->partages['ParametresVerificateur'] = new ParametresVerificateur($parametres, $parametresAPI);
-
 
190
		}
-
 
191
		return $this->partages['ParametresVerificateur'];
-
 
192
	}
-
 
193
 
-
 
194
	public function getRessourcesUrl() {
-
 
195
		if (!isset($this->partages['Ressources'])){
-
 
196
			$this->partages['Ressources'] = new Ressources($this->parametres['ressources']);
-
 
197
		}
-
 
198
		return $this->partages['Ressources'];
-
 
199
	}
-
 
200
 
-
 
201
	public function getRessourcesUrlVerificateur() {
-
 
202
		if (!isset($this->partages['RessourcesVerificateur'])){
-
 
203
			$ressources = $this->getRessourcesUrl();
-
 
204
			$projetsDispo = $this->getParametreTableau('projetsDispo');
-
 
205
			$servicesDispo = $this->getParametreTableau('servicesDispo');
-
 
206
			$this->partages['RessourcesVerificateur'] = new RessourcesVerificateur($ressources, $projetsDispo, $servicesDispo);
-
 
207
		}
-
 
208
		return $this->partages['RessourcesVerificateur'];
-
 
209
	}
-
 
210
 
-
 
211
	public function getVersionVerificateur() {
-
 
212
		if (!isset($this->partages['VersionVerificateur'])){
-
 
213
			$ressources = $this->getRessourcesUrl();
-
 
214
			$parametres = $this->getParametresUrl();
-
 
215
			$versions = $this->getVersions();
-
 
216
			$this->partages['VersionVerificateur'] = new VersionVerificateur($ressources, $parametres, $versions);
-
 
217
		}
-
 
218
		return $this->partages['VersionVerificateur'];
-
 
219
	}
-
 
220
 
-
 
221
	public function getBdd() {
-
 
222
		if (!isset($this->partages['Bdd'])){
-
 
223
			$this->partages['Bdd'] = new Bdd();
-
 
224
		}
-
 
225
		return $this->partages['Bdd'];
-
 
226
	}
-
 
227
 
-
 
228
	public function getCacheSimple($options = array()) {
-
 
229
		$cache = new CacheSimple($options);
-
 
230
		return $cache;
-
 
231
	}
-
 
232
 
-
 
233
	public function getVersions() {
-
 
234
		if (!isset($this->partages['Versions'])){
-
 
235
			$parametres = $this->getParametresUrl();
-
 
236
			$ressources = $this->getRessourcesUrl();
-
 
237
			$bdd = $this->getBdd();
-
 
238
			$versions = new Versions($parametres, $ressources, $bdd);
-
 
239
			$this->partages['Versions'] = $versions;
-
 
240
		}
-
 
241
		return $this->partages['Versions'];
-
 
242
	}
-
 
243
 
-
 
244
	public function getProjet() {
-
 
245
		if (!isset($this->partages['Projet'])){
-
 
246
			$ressources = $this->getRessourcesUrl();
-
 
247
			$projet = new Projet($ressources);
-
 
248
			$projet->setCheminBase($this->getParametre('cheminBase'));
-
 
249
			$projet->setCheminConfig($this->getParametre('chemin_configurations'));
-
 
250
			$projet->setCheminBiblio($this->getParametre('chemin_bibliotheque'));
-
 
251
			$projet->initialiser();
-
 
252
			$projet->setParamsVerif($this->getParametresUrlVerificateur());
-
 
253
			$projet->setRessourcesVerif($this->getRessourcesUrlVerificateur());
-
 
254
			$projet->setVersionVerif($this->getVersionVerificateur());
-
 
255
			$projet->setServiceGenerique($this->getServiceGenerique());
-
 
256
			$this->partages['Projet'] = $projet;
-
 
257
		}
-
 
258
		return $this->partages['Projet'];
-
 
259
	}
-
 
260
 
-
 
261
	/**
-
 
262
	* Créer la chaine de limite de requête en fonction des paramètres donnés
-
 
263
	* */
-
 
264
	public function getLimitSql() {
-
 
265
		return ' LIMIT '.$this->getDepart().', '.$this->getLimite();
-
 
266
	}
-
 
267
	
-
 
268
	public function getSchemaBdd() {
-
 
269
		return $this->getParametre('schemaBdd');
-
 
270
	}
-
 
271
	
-
 
272
	public function getServiceGenerique() {
-
 
273
		$ressources = $this->getRessourcesUrl();
-
 
274
		$classe = $ressources->getServiceClasse();
-
 
275
		$classeGenerique = $classe.'Generique';
-
 
276
		if ($ressources->getServiceNom() == 'noms' || $ressources->getServiceNom() == 'taxons') {
-
 
277
			$service = new $classeGenerique($this->getRessourcesUrl(), $this->getParametresUrl(), $this->getNomDao(), $this->getNomFormateur());
-
 
278
			if ($classe == 'NomsListe') {
136
	 * */
279
				$service->setListeUrl($this->getParametre('listeUrl'));
137
	public function getParametre($cle) {
280
			}
138
		$valeur = isset($this->parametres[$cle]) ? $this->parametres[$cle] : Config::get($cle);