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