ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSetting.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
33{
39 private static $settings_cache = array();
40
46 private static $value_type = NULL;
47
48
49 var $setting = array();
50 var $module = "";
51
55 function __construct($a_module = "common", $a_disabled_cache = false)
56 {
57 global $ilDB;
58
59 $this->cache_disabled = $a_disabled_cache;
60 $this->module = $a_module;
61 // check whether ini file object exists
62 if (!is_object($ilDB))
63 {
64 die ("Fatal Error: ilSettings object instantiated without DB initialisation.");
65 }
66 $this->read();
67 }
68
72 public function getModule()
73 {
74 return $this->module;
75 }
76
80 function read()
81 {
82 global $ilDB;
83
84 // get the settings from the cache if they exist.
85 // The setting array of the class is a reference to the cache.
86 // So changing settings in one instance will change them in all.
87 // This is the same behaviour as if the are read from the DB.
88 if (!$this->cache_disabled)
89 {
90 if (isset(self::$settings_cache[$this->module]))
91 {
92 $this->setting =& self::$settings_cache[$this->module];
93 return;
94 }
95 else
96 {
97 $this->setting = array();
98 self::$settings_cache[$this->module] =& $this->setting;
99 }
100 }
101
102 $query = "SELECT * FROM settings WHERE module=".$ilDB->quote($this->module, "text");
103 $res = $ilDB->query($query);
104
105 while ($row = $ilDB->fetchAssoc($res))
106 {
107 $this->setting[$row["keyword"]] = $row["value"];
108 }
109
110 }
111
122 function get($a_keyword, $a_default_value = false)
123 {
124 if ($a_keyword == "ilias_version")
125 {
126 return ILIAS_VERSION;
127 }
128
129 if (isset($this->setting[$a_keyword]))
130 {
131 return $this->setting[$a_keyword];
132 }
133 else
134 {
135 return $a_default_value;
136 }
137 }
138
145 public function deleteAll()
146 {
147 global $ilDB;
148
149 $query = "DELETE FROM settings WHERE module = ".$ilDB->quote($this->module, "text");
150 $ilDB->manipulate($query);
151
152 $this->setting = array();
153
154 return true;
155 }
156
163 public function deleteLike($a_like)
164 {
165 global $ilDB;
166
167 $query = "SELECT keyword FROM settings".
168 " WHERE module = ".$ilDB->quote($this->module, "text").
169 " AND ".$ilDB->like("keyword", "text", $a_like);
170 $res = $ilDB->query($query);
171 while($row = $ilDB->fetchAssoc($res))
172 {
173 $this->delete($row["keyword"]);
174 }
175
176 return true;
177 }
178
185 function delete($a_keyword)
186 {
187 global $ilDB;
188
189 $st = $ilDB->manipulate("DELETE FROM settings WHERE keyword = ".
190 $ilDB->quote($a_keyword, "text")." AND module = ".
191 $ilDB->quote($this->module, "text"));
192
193 unset($this->setting[$a_keyword]);
194
195 return true;
196 }
197
198
199
205 function getAll()
206 {
207 return $this->setting;
208 }
209
217 function set($a_key, $a_val)
218 {
219 global $lng, $ilDB;
220
221 $this->delete($a_key);
222
223 if (!isset(self::$value_type))
224 {
225 self::$value_type = self::_getValueType();
226 }
227
228 if (self::$value_type == 'text' and strlen($a_val) >= 4000)
229 {
230 ilUtil::sendFailure($lng->txt('setting_value_truncated'), true);
231 $a_val = substr($a_val, 0, 4000);
232 }
233
234 $ilDB->insert("settings", array(
235 "module" => array("text", $this->module),
236 "keyword" => array("text", $a_key),
237 "value" => array(self::$value_type, $a_val)));
238
239 $this->setting[$a_key] = $a_val;
240
241 return true;
242 }
243
244 function setScormDebug($a_key, $a_val)
245 {
246 global $ilDB;
247 if ($a_val != "1") {
248 $ilDB->query("UPDATE sahs_lm SET debug = 'n'");
249 }
250 $setreturn = ilSetting::set($a_key, $a_val);
251 return $setreturn;
252 }
253
254 public static function _lookupValue($a_module, $a_keyword)
255 {
256 global $ilDB;
257
258 $query = "SELECT value FROM settings WHERE module = %s AND keyword = %s";
259 $res = $ilDB->queryF($query, array('text', 'text'), array($a_module, $a_keyword));
260 $data = $ilDB->fetchAssoc($res);
261 return $data['value'];
262 }
263
270 public static function _getValueType()
271 {
272 include_once ('./Services/Database/classes/class.ilDBAnalyzer.php');
273 $analyzer = new ilDBAnalyzer();
274 $info = $analyzer->getFieldInformation('settings');
275
276 if ($info['value']['type'] == 'clob')
277 {
278 return 'clob';
279 }
280 else
281 {
282 return 'text';
283 }
284 }
285
286
293 public static function _changeValueType($a_new_type = 'text')
294 {
295 global $ilDB;
296
297 $old_type = self::_getValueType();
298
299 if ($a_new_type == $old_type)
300 {
301 return false;
302 }
303 elseif ($a_new_type == 'clob')
304 {
305 $ilDB->addTableColumn('settings','value2',
306 array( "type" => "clob",
307 "notnull" => false,
308 "default" => NULL));
309
310 $ilDB->query("UPDATE settings SET value2 = value");
311 $ilDB->dropTableColumn('settings','value');
312 $ilDB->renameTableColumn('settings','value2','value');
313
314 return true;
315 }
316 elseif ($a_new_type == 'text')
317 {
318 $ilDB->addTableColumn('settings','value2',
319 array( "type" => "text",
320 "length" => 4000,
321 "notnull" => false,
322 "default" => NULL));
323
324 $ilDB->query("UPDATE settings SET value2 = value");
325 $ilDB->dropTableColumn('settings','value');
326 $ilDB->renameTableColumn('settings','value2','value');
327
328 return true;
329 }
330 else
331 {
332 return false;
333 }
334 }
335
336
343 public static function _getLongerSettings($a_limit = '4000')
344 {
345 global $ilDB;
346
347 $settings = array();
348
349 $query = "SELECT * FROM settings WHERE LENGTH(value) > "
350 . $ilDB->quote($a_limit, 'integer');
351
352 $result = $ilDB->query($query);
353
354 while ($row = $ilDB->fetchAssoc($result))
355 {
356 $settings[] = $row;
357 }
358
359 return $settings;
360 }
361}
362?>
$result
An exception for terminatinating execution or to throw for unit testing.
This class gives all kind of DB information using the MDB2 manager and reverse module.
ILIAS Setting Class.
static _getLongerSettings($a_limit='4000')
get a list of setting records with values loger than a limit
static $value_type
the type of settings value field in database This is determined in the set method to get a correct DB...
static _getValueType()
Get the type of the value column in the database.
deleteLike($a_like)
Delete all settings corresponding to a like string.
setScormDebug($a_key, $a_val)
__construct($a_module="common", $a_disabled_cache=false)
Initialize settings.
set($a_key, $a_val)
write one value to db-table settings @access public
static _lookupValue($a_module, $a_keyword)
read()
Read settings data.
getAll()
read all values from settingstable @access public
static _changeValueType($a_new_type='text')
change the type of the value column in the database
getModule()
Get currernt module.
deleteAll()
Delete all settings of a current module.
static $settings_cache
cache for the read settings ilSetting is instantiated more than once per request for some modules The...
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$info
Definition: example_052.php:80
const ILIAS_VERSION
global $lng
Definition: privfeed.php:17
global $ilDB