716 |
gduche |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
*
|
|
|
4 |
* */
|
|
|
5 |
class Conteneur {
|
|
|
6 |
protected $parametres = array();
|
|
|
7 |
protected $partages = array();
|
|
|
8 |
protected $masque = array();
|
|
|
9 |
protected $urlNavigation;
|
|
|
10 |
protected $total;
|
|
|
11 |
|
|
|
12 |
public function __construct(array $parametres = null) {
|
|
|
13 |
$this->parametres = is_null($parametres) ? array() : $parametres;
|
|
|
14 |
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
public function chargerConfiguration($chemin) {
|
|
|
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() {
|
|
|
33 |
$masques = Config::get('masques_possibles');
|
|
|
34 |
$masquesPossibles = explode(',', $masques);
|
|
|
35 |
|
|
|
36 |
foreach ($this->parametres as $id => $parametre) {
|
|
|
37 |
if (strpos($id, 'masque.') === 0) {
|
|
|
38 |
if (in_array(str_replace('masque.', '', $id), $masquesPossibles)) {
|
|
|
39 |
$this->masque[$id] = $parametre;
|
|
|
40 |
}
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
|
|
|
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 |
}
|
|
|
50 |
|
|
|
51 |
public function getUrl($depart = null, $limite = null) {
|
|
|
52 |
if ($depart == null && $limite == null) {
|
|
|
53 |
return $this->urlNavigation;
|
|
|
54 |
} else {
|
|
|
55 |
return $this->obtenirUrlNavigation($depart, $limite);
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Récupérer l'url de navigation en concaténant d'éventuels paramètres
|
|
|
61 |
* @param $depart l'entier de départ de la recherche
|
|
|
62 |
* @param $limite le nombre de résultats à retourner
|
|
|
63 |
* @param $parametresAdditionnels le tableau contenant les parametres => valeurs additionnels
|
|
|
64 |
* */
|
|
|
65 |
private function obtenirUrlNavigation($depart, $limite) {
|
|
|
66 |
|
|
|
67 |
$parametres = $this->parametres;
|
|
|
68 |
$parametres['navigation.depart'] = $depart;
|
|
|
69 |
$parametres['navigation.limite'] = $limite;
|
|
|
70 |
|
|
|
71 |
$this->UrlNavigation->setRequete($parametres);
|
|
|
72 |
$url = $this->UrlNavigation->getURL();
|
|
|
73 |
return $url;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public function getTotal() {
|
|
|
77 |
return $this->total;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public function setTotal($total) {
|
|
|
81 |
$this->total = $total;
|
|
|
82 |
}
|
|
|
83 |
/**
|
|
|
84 |
* Créer l'entête en fonction des paramètres donnés
|
|
|
85 |
* */
|
|
|
86 |
public function getEntete() {
|
|
|
87 |
$entete = array();
|
|
|
88 |
$entete['masque'] = $this->getChaineMasque();
|
|
|
89 |
$entete['depart'] = $this->getDepart();
|
|
|
90 |
$entete['limite'] = $this->getLimite();
|
|
|
91 |
$entete['total'] = $this->getTotal();
|
|
|
92 |
$lienPrecedent = $this->recupererHrefPrecedent();
|
|
|
93 |
|
|
|
94 |
if ($lienPrecedent != null) {
|
|
|
95 |
$entete['entete.precedent'] = $lienPrecedent;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
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 |
* */
|
|
|
108 |
private function recupererHrefPrecedent() {
|
|
|
109 |
$departActuel = $this->getDepart();
|
|
|
110 |
$limite = $this->getLimite();
|
|
|
111 |
$departPrecedent = $departActuel - $limite;
|
|
|
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;
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
|
|
|
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();
|
|
|
158 |
$parametre = $this->getParametre($cle);
|
|
|
159 |
if (empty($parametre) === false) {
|
|
|
160 |
$tableauPartiel = explode(',', $parametre);
|
|
|
161 |
$tableauPartiel = array_map('trim', $tableauPartiel);
|
|
|
162 |
foreach ($tableauPartiel as $champ) {
|
|
|
163 |
if (strpos($champ, '=') === false) {
|
|
|
164 |
$tableau[] = trim($champ);
|
|
|
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') {
|
|
|
279 |
$service->setListeUrl($this->getParametre('listeUrl'));
|
|
|
280 |
}
|
|
|
281 |
} else if ($ressources->getServiceNom() == 'ontologies') {
|
|
|
282 |
$service = new $classeGenerique($this->getRessourcesUrl(), $this->getParametresUrl(), $this->getOntologiesDao(), $this->getOntologiesFormateur());
|
|
|
283 |
if ($classe == 'OntologiesListe') {
|
|
|
284 |
$service->setListeUrl($this->getParametre('listeUrlOntologies'));
|
|
|
285 |
}
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
return $service;
|
|
|
289 |
}
|
|
|
290 |
}
|
|
|
291 |
?>
|