| 163 |
jpm |
1 |
<?php
|
| 165 |
jpm |
2 |
// TODO : il est peut être nécessaire de mieux distinguer les attributs parametres et parametresOrigine
|
| 215 |
jpm |
3 |
// TODO : déplacer les méthodes getMasquePourBdd et getPourBdd dans les DAO
|
| 163 |
jpm |
4 |
class Parametres implements Iterator {
|
| 165 |
jpm |
5 |
|
| 163 |
jpm |
6 |
private $parametres = array();
|
| 165 |
jpm |
7 |
private $parametresOrigine = array();
|
| 215 |
jpm |
8 |
private $parametresTypeEntier = array('navigation.limite', 'navigation.depart');
|
| 163 |
jpm |
9 |
private $bdd = null;
|
|
|
10 |
|
|
|
11 |
public function __construct(Array $parametres, Bdd $bdd) {
|
| 165 |
jpm |
12 |
$this->parametresOrigine = $parametres;
|
|
|
13 |
$this->parametres = $this->parametresOrigine;
|
| 163 |
jpm |
14 |
$this->bdd = $bdd;
|
|
|
15 |
$this->definirValeursParDefaut();
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
public function current () {
|
| 165 |
jpm |
19 |
return current($this->parametresOrigine);
|
| 163 |
jpm |
20 |
}
|
|
|
21 |
|
|
|
22 |
public function key() {
|
| 165 |
jpm |
23 |
return key($this->parametresOrigine);
|
| 163 |
jpm |
24 |
}
|
|
|
25 |
|
|
|
26 |
public function next() {
|
| 165 |
jpm |
27 |
return next($this->parametresOrigine);
|
| 163 |
jpm |
28 |
}
|
|
|
29 |
|
|
|
30 |
public function rewind() {
|
| 165 |
jpm |
31 |
return reset($this->parametresOrigine);
|
| 163 |
jpm |
32 |
}
|
|
|
33 |
|
|
|
34 |
public function valid() {
|
| 165 |
jpm |
35 |
return current($this->parametresOrigine) == false ? false : true;
|
| 163 |
jpm |
36 |
}
|
|
|
37 |
|
|
|
38 |
public function get($parametreCode) {
|
|
|
39 |
$valeur = '';
|
|
|
40 |
if ($this->exister($parametreCode)) {
|
|
|
41 |
$valeur = $this->parametres[$parametreCode];
|
|
|
42 |
}
|
| 215 |
jpm |
43 |
return $this->etreParametreDeTypeEntier($parametreCode) ? (int) $valeur : $valeur;
|
| 163 |
jpm |
44 |
}
|
|
|
45 |
|
| 215 |
jpm |
46 |
private function etreParametreDeTypeEntier($parametreCode) {
|
|
|
47 |
$entier = in_array($parametreCode, $this->parametresTypeEntier) ? true : false;
|
|
|
48 |
return $entier;
|
|
|
49 |
}
|
|
|
50 |
|
| 207 |
jpm |
51 |
public function getListe($parametreCode) {
|
|
|
52 |
$valeurs = array();
|
|
|
53 |
if ($this->exister($parametreCode)) {
|
|
|
54 |
$valeurs = explode(',', $this->parametres[$parametreCode]);
|
|
|
55 |
$valeurs = array_map('trim', $valeurs);
|
|
|
56 |
}
|
|
|
57 |
return $valeurs;
|
|
|
58 |
}
|
|
|
59 |
|
| 163 |
jpm |
60 |
public function exister($parametreCode) {
|
|
|
61 |
$existe = false;
|
|
|
62 |
if (array_key_exists($parametreCode, $this->parametres) && $this->parametres[$parametreCode] != '') {
|
|
|
63 |
$existe = true;
|
|
|
64 |
}
|
|
|
65 |
return $existe;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
public function getPourBdd($parametreCode) {
|
|
|
69 |
$valeur = false;
|
|
|
70 |
if ($this->exister($parametreCode)) {
|
|
|
71 |
$valeur = $this->get($parametreCode);
|
|
|
72 |
$valeur = $this->proteger($valeur);
|
|
|
73 |
}
|
|
|
74 |
return $valeur;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
private function proteger($valeur) {
|
|
|
78 |
$valeur = $this->bdd->proteger($valeur);
|
|
|
79 |
return $valeur;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public function getMasquePourBdd($type = '') {
|
|
|
83 |
$masque = false;
|
|
|
84 |
$parametreMasque = 'masque'.($type != '' ? '.'.$type : $type);
|
|
|
85 |
if ($this->exister($parametreMasque)) {
|
|
|
86 |
$masque = $this->get($parametreMasque);
|
|
|
87 |
$recherche = $this->get('recherche');
|
|
|
88 |
if ($recherche == 'etendue') {
|
|
|
89 |
$masque = str_replace(' ', '% ', $masque);
|
|
|
90 |
$masque .= '%';
|
|
|
91 |
}
|
|
|
92 |
$masque = $this->proteger($masque);
|
|
|
93 |
}
|
|
|
94 |
return $masque;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
private function definirValeursParDefaut() {
|
|
|
98 |
if ($this->exister('recherche') == false) {
|
|
|
99 |
$this->parametres['recherche'] = 'stricte';
|
|
|
100 |
}
|
|
|
101 |
if ($this->exister('ns.format') == false) {
|
|
|
102 |
$this->parametres['ns.format'] = 'txt';
|
|
|
103 |
}
|
|
|
104 |
if ($this->exister('retour') == false) {
|
|
|
105 |
$this->parametres['retour'] = 'application/json';
|
|
|
106 |
}
|
|
|
107 |
if ($this->exister('retour.format') == false) {
|
|
|
108 |
$this->parametres['retour.format'] = 'max';
|
|
|
109 |
}
|
|
|
110 |
if ($this->exister('retour.langue') == false) {
|
|
|
111 |
$this->parametres['retour.langue'] = 'fr';
|
|
|
112 |
}
|
|
|
113 |
if ($this->exister('version.projet') == false) {
|
|
|
114 |
$this->parametres['version.projet'] = '+';
|
|
|
115 |
}
|
|
|
116 |
if ($this->exister('navigation.depart') == false) {
|
| 211 |
jpm |
117 |
$this->parametres['navigation.depart'] = (int) 0;
|
| 163 |
jpm |
118 |
}
|
|
|
119 |
if ($this->exister('navigation.limite') == false) {
|
| 211 |
jpm |
120 |
$this->parametres['navigation.limite'] = (int) 100;
|
| 163 |
jpm |
121 |
}
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
?>
|