ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
32 class ilSetting
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  {
89  $ilDB = $this->db;
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  {
144  $ilDB = $this->db;
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  {
162  $ilDB = $this->db;
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  {
183  $ilDB = $this->db;
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  {
215  global $DIC;
216 
217  $lng = $DIC["lng"];
218  $ilDB = $this->db;
219 
220  $this->delete($a_key);
221 
222  if (!isset(self::$value_type)) {
223  self::$value_type = self::_getValueType();
224  }
225 
226  if (self::$value_type == 'text' and strlen($a_val) >= 4000) {
227  ilUtil::sendFailure($lng->txt('setting_value_truncated'), true);
228  $a_val = substr($a_val, 0, 4000);
229  }
230 
231  $ilDB->insert("settings", array(
232  "module" => array("text", $this->module),
233  "keyword" => array("text", $a_key),
234  "value" => array(self::$value_type, $a_val)));
235 
236  $this->setting[$a_key] = $a_val;
237 
238  return true;
239  }
240 
241  public function setScormDebug($a_key, $a_val)
242  {
243  $ilDB = $this->db;
244  if ($a_val != "1") {
245  $ilDB->query("UPDATE sahs_lm SET debug = 'n'");
246  }
247  $setreturn = ilSetting::set($a_key, $a_val);
248  return $setreturn;
249  }
250 
251  public static function _lookupValue($a_module, $a_keyword)
252  {
253  global $DIC;
254 
255  $ilDB = $DIC->database();
256 
257  $query = "SELECT value FROM settings WHERE module = %s AND keyword = %s";
258  $res = $ilDB->queryF($query, array('text', 'text'), array($a_module, $a_keyword));
259  $data = $ilDB->fetchAssoc($res);
260  return $data['value'];
261  }
262 
269  public static function _getValueType()
270  {
271  include_once('./Services/Database/classes/class.ilDBAnalyzer.php');
272  $analyzer = new ilDBAnalyzer();
273  $info = $analyzer->getFieldInformation('settings');
274 
275  if ($info['value']['type'] == 'clob') {
276  return 'clob';
277  } else {
278  return 'text';
279  }
280  }
281 
282 
289  public static function _changeValueType($a_new_type = 'text')
290  {
291  global $DIC;
292 
293  $ilDB = $DIC->database();
294 
295  $old_type = self::_getValueType();
296 
297  if ($a_new_type == $old_type) {
298  return false;
299  } elseif ($a_new_type == 'clob') {
300  $ilDB->addTableColumn(
301  'settings',
302  'value2',
303  array( "type" => "clob",
304  "notnull" => false,
305  "default" => null)
306  );
307 
308  $ilDB->query("UPDATE settings SET value2 = value");
309  $ilDB->dropTableColumn('settings', 'value');
310  $ilDB->renameTableColumn('settings', 'value2', 'value');
311 
312  return true;
313  } elseif ($a_new_type == 'text') {
314  $ilDB->addTableColumn(
315  'settings',
316  'value2',
317  array( "type" => "text",
318  "length" => 4000,
319  "notnull" => false,
320  "default" => null)
321  );
322 
323  $ilDB->query("UPDATE settings SET value2 = value");
324  $ilDB->dropTableColumn('settings', 'value');
325  $ilDB->renameTableColumn('settings', 'value2', 'value');
326 
327  return true;
328  } else {
329  return false;
330  }
331  }
332 
333 
340  public static function _getLongerSettings($a_limit = '4000')
341  {
342  global $DIC;
343 
344  $ilDB = $DIC->database();
345 
346  $settings = array();
347 
348  $query = "SELECT * FROM settings WHERE LENGTH(value) > "
349  . $ilDB->quote($a_limit, 'integer');
350 
351  $result = $ilDB->query($query);
352 
353  while ($row = $ilDB->fetchAssoc($result)) {
354  $settings[] = $row;
355  }
356 
357  return $settings;
358  }
359 }
set($a_key, $a_val)
write one value to db-table settings public
setScormDebug($a_key, $a_val)
const ILIAS_VERSION
$result
static _getLongerSettings($a_limit='4000')
get a list of setting records with values loger than a limit
static _changeValueType($a_new_type='text')
change the type of the value column in the database
static _getValueType()
Get the type of the value column in the database.
__construct($a_module="common", $a_disabled_cache=false)
Initialize settings.
global $DIC
Definition: saml.php:7
getAll()
read all values from settingstable public
static $settings_cache
cache for the read settings ilSetting is instantiated more than once per request for some modules The...
static _lookupValue($a_module, $a_keyword)
foreach($_POST as $key=> $value) $res
$query
read()
Read settings data.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
deleteAll()
Delete all settings of a current module.
global $lng
Definition: privfeed.php:17
global $ilDB
This class gives all kind of DB information using the MDB2 manager and reverse module.
$info
Definition: index.php:5
getModule()
Get currernt module.
static $value_type
the type of settings value field in database This is determined in the set method to get a correct DB...
deleteLike($a_like)
Delete all settings corresponding to a like string.