ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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{
37 protected $db;
38
44 private static $settings_cache = array();
45
51 private static $value_type = null;
52
53
54 public $setting = array();
55 public $module = "";
56
60 public function __construct($a_module = "common", $a_disabled_cache = false)
61 {
62 global $DIC;
63
64 $this->db = $DIC->database();
65 $ilDB = $DIC->database();
66
67 $this->cache_disabled = $a_disabled_cache;
68 $this->module = $a_module;
69 // check whether ini file object exists
70 if (!is_object($ilDB)) {
71 die("Fatal Error: ilSettings object instantiated without DB initialisation.");
72 }
73 $this->read();
74 }
75
79 public function getModule()
80 {
81 return $this->module;
82 }
83
87 public function read()
88 {
90
91 // get the settings from the cache if they exist.
92 // The setting array of the class is a reference to the cache.
93 // So changing settings in one instance will change them in all.
94 // This is the same behaviour as if the are read from the DB.
95 if (!$this->cache_disabled) {
96 if (isset(self::$settings_cache[$this->module])) {
97 $this->setting = &self::$settings_cache[$this->module];
98 return;
99 } else {
100 $this->setting = array();
101 self::$settings_cache[$this->module] = &$this->setting;
102 }
103 }
104
105 $query = "SELECT * FROM settings WHERE module=" . $ilDB->quote($this->module, "text");
106 $res = $ilDB->query($query);
107
108 while ($row = $ilDB->fetchAssoc($res)) {
109 $this->setting[$row["keyword"]] = $row["value"];
110 }
111 }
112
123 public function get($a_keyword, $a_default_value = false)
124 {
125 if ($a_keyword == "ilias_version") {
126 return ILIAS_VERSION;
127 }
128
129 if (isset($this->setting[$a_keyword])) {
130 return $this->setting[$a_keyword];
131 } else {
132 return $a_default_value;
133 }
134 }
135
142 public function deleteAll()
143 {
145
146 $query = "DELETE FROM settings WHERE module = " . $ilDB->quote($this->module, "text");
147 $ilDB->manipulate($query);
148
149 $this->setting = array();
150
151 return true;
152 }
153
160 public function deleteLike($a_like)
161 {
163
164 $query = "SELECT keyword FROM settings" .
165 " WHERE module = " . $ilDB->quote($this->module, "text") .
166 " AND " . $ilDB->like("keyword", "text", $a_like);
167 $res = $ilDB->query($query);
168 while ($row = $ilDB->fetchAssoc($res)) {
169 $this->delete($row["keyword"]);
170 }
171
172 return true;
173 }
174
181 public function delete($a_keyword)
182 {
184
185 $st = $ilDB->manipulate("DELETE FROM settings WHERE keyword = " .
186 $ilDB->quote($a_keyword, "text") . " AND module = " .
187 $ilDB->quote($this->module, "text"));
188
189 unset($this->setting[$a_keyword]);
190
191 return true;
192 }
193
194
195
201 public function getAll()
202 {
203 return $this->setting;
204 }
205
213 public function set($a_key, $a_val)
214 {
216
217 $this->delete($a_key);
218
219 if (!isset(self::$value_type)) {
220 self::$value_type = self::_getValueType();
221 }
222
223 if (self::$value_type == 'text' and strlen($a_val) >= 4000) {
224 global $DIC;
225 $lng = $DIC["lng"];
226 ilUtil::sendFailure($lng->txt('setting_value_truncated'), true);
227 $a_val = substr($a_val, 0, 4000);
228 }
229
230 $ilDB->insert("settings", array(
231 "module" => array("text", $this->module),
232 "keyword" => array("text", $a_key),
233 "value" => array(self::$value_type, $a_val)));
234
235 $this->setting[$a_key] = $a_val;
236
237 return true;
238 }
239
240 public function setScormDebug($a_key, $a_val)
241 {
243 if ($a_val != "1") {
244 $ilDB->query("UPDATE sahs_lm SET debug = 'n'");
245 }
246 $setreturn = ilSetting::set($a_key, $a_val);
247 return $setreturn;
248 }
249
250 public static function _lookupValue($a_module, $a_keyword)
251 {
252 global $DIC;
253
254 $ilDB = $DIC->database();
255
256 $query = "SELECT value FROM settings WHERE module = %s AND keyword = %s";
257 $res = $ilDB->queryF($query, array('text', 'text'), array($a_module, $a_keyword));
258 $data = $ilDB->fetchAssoc($res);
259 return $data['value'];
260 }
261
268 public static function _getValueType()
269 {
270 $analyzer = new ilDBAnalyzer();
271 $info = $analyzer->getFieldInformation('settings');
272
273 if ($info['value']['type'] == 'clob') {
274 return 'clob';
275 } else {
276 return 'text';
277 }
278 }
279
280
287 public static function _changeValueType($a_new_type = 'text')
288 {
289 global $DIC;
290
291 $ilDB = $DIC->database();
292
293 $old_type = self::_getValueType();
294
295 if ($a_new_type == $old_type) {
296 return false;
297 } elseif ($a_new_type == 'clob') {
298 $ilDB->addTableColumn(
299 'settings',
300 'value2',
301 array( "type" => "clob",
302 "notnull" => false,
303 "default" => null)
304 );
305
306 $ilDB->query("UPDATE settings SET value2 = value");
307 $ilDB->dropTableColumn('settings', 'value');
308 $ilDB->renameTableColumn('settings', 'value2', 'value');
309
310 return true;
311 } elseif ($a_new_type == 'text') {
312 $ilDB->addTableColumn(
313 'settings',
314 'value2',
315 array( "type" => "text",
316 "length" => 4000,
317 "notnull" => false,
318 "default" => null)
319 );
320
321 $ilDB->query("UPDATE settings SET value2 = value");
322 $ilDB->dropTableColumn('settings', 'value');
323 $ilDB->renameTableColumn('settings', 'value2', 'value');
324
325 return true;
326 } else {
327 return false;
328 }
329 }
330
331
338 public static function _getLongerSettings($a_limit = '4000')
339 {
340 global $DIC;
341
342 $ilDB = $DIC->database();
343
344 $settings = array();
345
346 $query = "SELECT * FROM settings WHERE LENGTH(value) > "
347 . $ilDB->quote($a_limit, 'integer');
348
349 $result = $ilDB->query($query);
350
351 while ($row = $ilDB->fetchAssoc($result)) {
352 $settings[] = $row;
353 }
354
355 return $settings;
356 }
357}
$result
An exception for terminatinating execution or to throw for unit testing.
This class gives all kind of DB information using the database 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.
const ILIAS_VERSION
$query
$lng
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23
$DIC
Definition: xapitoken.php:46