ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCloudPluginConfig.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once('./Modules/Cloud/exceptions/class.ilCloudPluginConfigException.php');
5
18{
22 protected $table_name = "";
23
27 protected $cache = array();
28
33 {
34 $this->table_name = $table_name;
35 }
36
40 public function setTableName($table_name)
41 {
42 $this->table_name = $table_name;
43 }
44
48 public function getTableName()
49 {
50 return $this->table_name;
51 }
52
58 function __call($method, $params)
59 {
60 $index = substr($method,3);
61 if (substr($method, 0, 3) == 'get')
62 {
63 if (!isset($this->cache[$index]))
64 {
65 $this->cache[$index] = $this->getValue(self::_fromCamelCase(substr($method, 3)));
66 }
67 if ($this->cache[$index] == null)
68 {
69 $this->cache[$index] = false;
70 }
71
72 return $this->cache[$index];
73 } else if (substr($method, 0, 3) == 'set')
74 {
75 $this->cache[$index] = $params[0];
76 $this->setValue(self::_fromCamelCase(substr($method, 3)), $params[0]);
77 return true;
78 } else
79 {
81 }
82
83 }
84
89 public function setValue($key, $value)
90 {
91 global $ilDB;
92
93 if(!$ilDB->tableExists($this->table_name))
94 {
96 }
97
98 if (!is_string($this->getValue($key)))
99 {
100 $ilDB->insert($this->table_name, array("config_key" => array("text", $key), "config_value" => array("text", $value)));
101 }
102
103 else
104 {
105 $ilDB->update($this->table_name, array("config_key" => array("text", $key), "config_value" => array("text", $value)), array("config_key" => array("text", $key)));
106 }
107 }
108
113 public function getValue($key)
114 {
115 global $ilDB;
116
117
118 if (!$this->tableExists($this->table_name))
119 {
121 }
122
123 $result = $ilDB->query("SELECT config_value FROM ". $this->table_name ." WHERE config_key = " . $ilDB->quote($key, "text"));
124
125 if ($result->numRows() == 0)
126 {
127 return false;
128 }
129 $record = $ilDB->fetchAssoc($result);
130 return (string)$record['config_value'];
131 }
132
133
134
138 public function initDB()
139 {
140 global $ilDB;
141
142 if (!$ilDB->tableExists($this->getTableName()))
143 {
144 $fields = array(
145 'config_key' => array(
146 'type' => 'text',
147 'length' => 128,
148 'notnull' => true),
149 'config_value' => array(
150 'type' => 'clob',
151 'notnull' => false),);
152 $ilDB->createTable($this->getTableName(), $fields);
153 $ilDB->addPrimaryKey($this->getTableName(), array("config_key"));
154 }
155
156 return true;
157 }
158
159
160 //
161 // Helper
162 //
163
164
169 public static function _fromCamelCase($str)
170 {
171 $str[0] = strtolower($str[0]);
172 $func = create_function('$c', 'return "_" . strtolower($c[1]);');
173 return preg_replace_callback('/([A-Z])/', $func, $str);
174 }
175
181 public static function _toCamelCase($str, $capitalise_first_char = false)
182 {
183 if ($capitalise_first_char)
184 {
185 $str[0] = strtoupper($str[0]);
186 }
187 $func = create_function('$c', 'return strtoupper($c[1]);');
188 return preg_replace_callback('/-([a-z])/', $func, $str);
189 }
190
191 public function tableExists()
192 {
193 global $ilDB;
194 $result = $ilDB->query("show tables like '".$this->getTableName()."'");
195
196 if ($result->numRows() == 0)
197 {
198 return false;
199 }
200 else return true;
201 }
202}
203
204?>
$result
Class ilCloudPluginConfigException.
Class ilCloudPluginConfig.
static _toCamelCase($str, $capitalise_first_char=false)
$params
Definition: example_049.php:96
global $ilDB