ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSetting Class Reference

ILIAS Setting Class. More...

+ Inheritance diagram for ilSetting:
+ Collaboration diagram for ilSetting:

Public Member Functions

 ilSetting ($a_module="common", $a_disabled_cache=false)
 Initialize settings. More...
 
 getModule ()
 Get currernt module. More...
 
 read ()
 Read settings data. More...
 
 get ($a_keyword, $a_default_value=false)
 get setting More...
 
 deleteAll ()
 Delete all settings of a current module. More...
 
 deleteLike ($a_like)
 Delete all settings corresponding to a like string. More...
 
 delete ($a_keyword)
 delete one value from settingstable public More...
 
 getAll ()
 read all values from settingstable public More...
 
 set ($a_key, $a_val)
 write one value to db-table settings public More...
 
 setScormDebug ($a_key, $a_val)
 

Static Public Member Functions

static _lookupValue ($a_module, $a_keyword)
 
static _getValueType ()
 get the type of the value column in the database More...
 
static _changeValueType ($a_new_type='text')
 change the type of the value column in the database More...
 
static _getLongerSettings ($a_limit='4000')
 get a list of setting records with values loger than a limit More...
 

Data Fields

 $setting = array()
 
 $module = ""
 

Static Private Attributes

static $settings_cache = array()
 cache for the read settings ilSetting is instantiated more than once per request for some modules The cache avoids reading them from the DB with each instance More...
 
static $value_type = NULL
 the type of settings value field in database This is determined in the set method to get a correct DB insert Don't set the value type to force a detection at first access More...
 

Detailed Description

ILIAS Setting Class.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@d.nosp@m.atab.nosp@m.ay.de
Version
$Id$

Definition at line 32 of file class.ilSetting.php.

Member Function Documentation

◆ _changeValueType()

static ilSetting::_changeValueType (   $a_new_type = 'text')
static

change the type of the value column in the database

Parameters
string'text' or 'clob'
Returns
bolean type changed or not

Definition at line 292 of file class.ilSetting.php.

References $ilDB.

Referenced by ilSetupGUI\changeSettingsType().

293  {
294  global $ilDB;
295 
296  $old_type = self::_getValueType();
297 
298  if ($a_new_type == $old_type)
299  {
300  return false;
301  }
302  elseif ($a_new_type == 'clob')
303  {
304  $ilDB->addTableColumn('settings','value2',
305  array( "type" => "clob",
306  "notnull" => false,
307  "default" => NULL));
308 
309  $ilDB->query("UPDATE settings SET value2 = value");
310  $ilDB->dropTableColumn('settings','value');
311  $ilDB->renameTableColumn('settings','value2','value');
312 
313  return true;
314  }
315  elseif ($a_new_type == 'text')
316  {
317  $ilDB->addTableColumn('settings','value2',
318  array( "type" => "text",
319  "length" => 4000,
320  "notnull" => false,
321  "default" => NULL));
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  }
329  else
330  {
331  return false;
332  }
333  }
global $ilDB
+ Here is the caller graph for this function:

◆ _getLongerSettings()

static ilSetting::_getLongerSettings (   $a_limit = '4000')
static

get a list of setting records with values loger than a limit

Parameters
intcharacter limit (default: 4000)
Returns
array records with longer values

Definition at line 342 of file class.ilSetting.php.

References $ilDB, $query, $result, and $row.

Referenced by ilSetupGUI\changeSettingsType(), and ilSetupGUI\showLongerSettings().

343  {
344  global $ilDB;
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  {
355  $settings[] = $row;
356  }
357 
358  return $settings;
359  }
$result
global $ilDB
+ Here is the caller graph for this function:

◆ _getValueType()

static ilSetting::_getValueType ( )
static

get the type of the value column in the database

Returns
string 'text' or 'clob'

Definition at line 269 of file class.ilSetting.php.

References ilDBAnalyzer\getFieldInformation().

Referenced by ilSetupGUI\changeSettingsType(), and ilSetupGUI\initSettingsTypeForm().

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  {
277  return 'clob';
278  }
279  else
280  {
281  return 'text';
282  }
283  }
getFieldInformation($a_table, $a_remove_not_allowed_attributes=false)
Get field information of a table.
This class gives all kind of DB information using the MDB2 manager and reverse module.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupValue()

static ilSetting::_lookupValue (   $a_module,
  $a_keyword 
)
static

Definition at line 254 of file class.ilSetting.php.

References $data, $ilDB, $query, and $res.

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  }
global $ilDB

◆ delete()

ilSetting::delete (   $a_keyword)

delete one value from settingstable public

Parameters
stringkeyword
Returns
string value

Definition at line 185 of file class.ilSetting.php.

References $ilDB.

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  }
global $ilDB

◆ deleteAll()

ilSetting::deleteAll ( )

Delete all settings of a current module.

public

Definition at line 145 of file class.ilSetting.php.

References $ilDB, and $query.

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  }
global $ilDB

◆ deleteLike()

ilSetting::deleteLike (   $a_like)

Delete all settings corresponding to a like string.

public

Definition at line 163 of file class.ilSetting.php.

References $ilDB, $query, $res, and $row.

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  }
global $ilDB

◆ get()

ilSetting::get (   $a_keyword,
  $a_default_value = false 
)

get setting

public

Parameters
stringkeyword
stringdefault_value This value is returned, when no setting has been found for the keyword.
Returns
string value

Definition at line 122 of file class.ilSetting.php.

References ILIAS_VERSION.

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  }
const ILIAS_VERSION

◆ getAll()

ilSetting::getAll ( )

read all values from settingstable public

Returns
array keyword/value pairs

Definition at line 205 of file class.ilSetting.php.

References $setting.

206  {
207  return $this->setting;
208  }

◆ getModule()

ilSetting::getModule ( )

Get currernt module.

Definition at line 72 of file class.ilSetting.php.

References $module.

73  {
74  return $this->module;
75  }

◆ ilSetting()

ilSetting::ilSetting (   $a_module = "common",
  $a_disabled_cache = false 
)

Initialize settings.

Definition at line 55 of file class.ilSetting.php.

References $ilDB, and read().

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  }
read()
Read settings data.
global $ilDB
+ Here is the call graph for this function:

◆ read()

ilSetting::read ( )

Read settings data.

Definition at line 80 of file class.ilSetting.php.

References $ilDB, $module, $query, $res, $row, and $setting.

Referenced by ilSetting().

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  }
global $ilDB
+ Here is the caller graph for this function:

◆ set()

ilSetting::set (   $a_key,
  $a_val 
)

write one value to db-table settings public

Parameters
stringkeyword
stringvalue
Returns
boolean true on success

Definition at line 217 of file class.ilSetting.php.

References $ilDB, $lng, and ilUtil\sendFailure().

Referenced by setScormDebug().

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  }
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:40
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setScormDebug()

ilSetting::setScormDebug (   $a_key,
  $a_val 
)

Definition at line 244 of file class.ilSetting.php.

References $ilDB, and set().

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  }
set($a_key, $a_val)
write one value to db-table settings public
global $ilDB
+ Here is the call graph for this function:

Field Documentation

◆ $module

ilSetting::$module = ""

Definition at line 50 of file class.ilSetting.php.

Referenced by getModule(), and read().

◆ $setting

ilSetting::$setting = array()

Definition at line 49 of file class.ilSetting.php.

Referenced by getAll(), and read().

◆ $settings_cache

ilSetting::$settings_cache = array()
staticprivate

cache for the read settings ilSetting is instantiated more than once per request for some modules The cache avoids reading them from the DB with each instance

Definition at line 39 of file class.ilSetting.php.

◆ $value_type

ilSetting::$value_type = NULL
staticprivate

the type of settings value field in database This is determined in the set method to get a correct DB insert Don't set the value type to force a detection at first access

Definition at line 46 of file class.ilSetting.php.


The documentation for this class was generated from the following file: