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