-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGSetting.php
101 lines (90 loc) · 2.21 KB
/
GSetting.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
96
97
98
99
100
101
<?php
class Gatuf_GSetting extends Gatuf_Model {
public $_model = __CLASS__;
public $datacache = null;
public $f = null;
protected $_application = null;
public function init() {
$this->_a['table'] = 'gsettings';
$this->_a['model'] = __CLASS__;
$this->primary_key = 'id';
$this->_a['cols'] = array(
'id' =>
array(
'type' => 'Gatuf_DB_Field_Sequence',
'blank' => true,
),
'application' =>
array(
'type' => 'Gatuf_DB_Field_Varchar',
'size' => 150,
'blank' => false,
),
'vkey' =>
array(
'type' => 'Gatuf_DB_Field_Varchar',
'size' => 50,
'blank' => false,
),
'value' =>
array(
'type' => 'Gatuf_DB_Field_Text',
'blank' => false,
),
);
$this->_a['idx'] = array(
'project_vkey_idx' =>
array(
'col' => 'application, vkey',
'type' => 'unique',
),
'application_idx' =>
array(
'col' => 'application',
'type' => 'index',
),
);
/* FIXME: Ver si esto se va a usar o no
$this->f = new IDF_Config_DataProxy () */
}
public function setApp($application) {
$this->datacache = null;
$this->_application = $application;
}
public function initCache() {
$this->datacache = new ArrayObject();
$sql = new Gatuf_SQL('application=%s', $this->_application);
foreach ($this->getList(array('filter' => $sql->gen())) as $val) {
$this->datacache[$val->vkey] = $val->value;
}
}
public function setVal($key, $value) {
if (!is_null($this->getVal($key, null))
and $value == $this->getVal($key)) {
return;
}
$this->delVal($key, false);
$conf = new Gatuf_GSetting();
$conf->application = $this->_application;
$conf->vkey = $key;
$conf->value = $value;
$conf->create();
$this->initCache();
}
public function getVal($key, $default = '') {
if ($this->datacache === null) {
$this->initCache();
}
return (isset($this->datacache[$key])) ? $this->datacache[$key] : $default;
}
public function delVal($key, $initcache = true) {
$gconf = new Gatuf_GSetting();
$sql = new Gatuf_SQL('vkey=%s AND application=%s', array($key, $this->_application));
foreach ($gconf->getList(array('filter' => $sql->gen())) as $c) {
$c->delete();
}
if ($initcache) {
$this->initCache();
}
}
}