forked from LeedRSS/Leed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.class.php
95 lines (70 loc) · 1.92 KB
/
Configuration.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/*
@nom: Configuration
@auteur: Idleman ([email protected])
@description: Classe de gestion des préférences, fonctionne sur un simple système clé=>valeur avec un cache session pour eviter les requête inutiles
*/
class Configuration extends MysqlEntity{
protected $id,$key,$value,$confTab;
protected $TABLE_NAME = 'configuration';
protected $CLASS_NAME = 'Configuration';
protected $object_fields =
array(
'id'=>'key',
'key'=>'longstring',
'value'=>'longstring'
);
function __construct(){
parent::__construct();
}
public function getAll(){
if(!isset($_SESSION['configuration'])){
$configurationManager = new Configuration();
$configs = $configurationManager->populate();
$confTab = array();
foreach($configs as $config){
$this->confTab[$config->getKey()] = $config->getValue();
}
$_SESSION['configuration'] = serialize($this->confTab);
}else{
$this->confTab = unserialize($_SESSION['configuration']);
}
}
public function get($key){
return (isset($this->confTab[$key])?$this->confTab[$key]:'');
}
public function put($key,$value){
$configurationManager = new Configuration();
if (isset($this->confTab[$key])){
$configurationManager->change(array('value'=>$value),array('key'=>$key));
} else {
$configurationManager->add($key,$value);
}
$this->confTab[$key] = $value;
unset($_SESSION['configuration']);
}
public function add($key,$value){
$config = new Configuration();
$config->setKey($key);
$config->setValue($value);
$config->save();
$this->confTab[$key] = $value;
unset($_SESSION['configuration']);
}
function getId(){
return $this->id;
}
function getKey(){
return $this->key;
}
function setKey($key){
$this->key = $key;
}
function getValue(){
return $this->value;
}
function setValue($value){
$this->value = $value;
}
}
?>