-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.class.php
More file actions
50 lines (37 loc) · 1.07 KB
/
settings.class.php
File metadata and controls
50 lines (37 loc) · 1.07 KB
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
<?php
require_once('rlib/rTable.class.php');
class siteSettings extends rTableClass{
private $cache = array();
function __construct($table = 'site_settings', $db){
parent::__construct($db, $table);
}
function getValue($id, $default = false, $autoCreate = true){
if(isset($this->cache[$id])) return $this->cache[$id];
$s = parent::get($id);
if(!$s){
if($autoCreate){
$this->add($id, $id, 'text');
$this->set($id, $default);
}
$this->cache[$id] = $default;
return $default;
}
$this->cache[$id] = $s['value'];
return $s['value'];
}
function set($id, $val){
$this->db->query('INSERT INTO ?# SET value = ?, id = ? ON DUPLICATE KEY UPDATE value = VALUES(value)', $this->table, $val, $id);
$this->cache[$id] = $val;
}
function add($id, $name = NULL, $type = NULL){
parent::add(array(
'id' => $id,
'type' => $type,
'name' => $name
));
}
function loadAll(){
$cache = $this->db->selectCol('SELECT id AS ARRAY_KEY, value FROM ?#', $this->table);
return $cache;
}
}