-
Notifications
You must be signed in to change notification settings - Fork 5
/
ConfigurationDAO.php
executable file
·106 lines (96 loc) · 3.27 KB
/
ConfigurationDAO.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
102
103
104
105
106
<?php defined('SKYBLUE') or die('Bad file request');
/**
* @version 2.0 2010-07-09 19:39:00 $
* @package SkyBlueCanvas
* @copyright Copyright (C) 2005 - 2010 Scott Edwin Lewis. All rights reserved.
* @license GNU/GPL, see COPYING.txt
* SkyBlueCanvas is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYING.txt for copyright notices and details.
*/
/**
* @author Scott Lewis
* @date July 09, 2010
*/
class ConfigurationDAO extends SqliteDAO {
function __construct() {
parent::__construct(array(
'type' => 'configuration',
'bean_class' => 'Configuration'
));
}
function getConfigBean() {
$Bean = new Configuration();
if ($Statement = $this->query("SELECT * FROM {$this->getBeanClass()}")) {
if ($result = $Statement->fetchAll(PDO::FETCH_ASSOC)) {
foreach ($result as $field) {
$key = Filter::get($field, 'name');
$key = ucwords(strtolower($key));
$method = "set{$key}";
if (is_callable(array($Bean, $method))) {
$Bean->$method(Filter::get($field, 'value'));
}
}
$Bean->setName("configuration");
$Bean->setId(1);
$Bean->setType("configuration");
$Bean->setObjtype("configuration");
}
}
return $Bean;
}
function getAllowedFields() {
return array(
'site_name',
'site_slogan',
'site_url',
'site_editor',
'site_lang',
'sef_urls',
'use_cache',
'contact_name',
'contact_title',
'contact_address',
'contact_address_2',
'contact_city',
'contact_state',
'contact_zip',
'contact_email',
'contact_phone',
'contact_fax',
'ui_theme',
'objtype',
'name',
'active_skin'
);
}
function update($Bean) {
$queries = array();
$props = Filter::getRaw($Bean, '_properties');
foreach ($props as $prop) {
if (strcasecmp($prop, 'id') === 0) continue;
$method = "get" . ucwords(strtolower($prop));
if (in_array($prop, $this->getAllowedFields()) && is_callable(array($Bean, $method))) {
array_push($queries, "UPDATE {$this->getBeanClass()} set value='{$Bean->$method()}' WHERE name='{$prop}';\n");
}
}
$result = false;
$effected_rows = 0;
$count = count($queries);
for ($i=0; $i<$count; $i++) {
if ($this->exec($queries[$i])) {
$effected_rows++;
}
}
return ($effected_rows == ($count-1));
}
function getItem($id) {
return $this->getConfigBean();
}
function index($refresh=false) {
return array($this->getConfigBean());
}
function insert($Bean) { return false; }
}