ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilSetting Class Reference

ILIAS Setting Class. More...

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

Public Member Functions

 __construct (string $a_module="common", bool $a_disabled_cache=false)
 
 getModule ()
 
 read ()
 
 get (string $a_keyword, ?string $a_default_value=null)
 get setting More...
 
 deleteAll ()
 
 deleteLike (string $a_like)
 
 delete (string $a_keyword)
 
 getAll ()
 
 set (string $a_key, string $a_val)
 
 setScormDebug (string $a_key, string $a_val)
 

Static Public Member Functions

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

Data Fields

array $setting = array()
 
string $module = ""
 

Protected Attributes

ilDBInterface $db
 
bool $cache_disabled = false
 

Static Private Attributes

static array $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 string $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
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

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

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

References $DIC, $ilDB, and read().

50  {
51  global $DIC;
52 
53  $this->db = $DIC->database();
54  $ilDB = $DIC->database();
55 
56  $this->cache_disabled = $a_disabled_cache;
57  $this->module = $a_module;
58  // check whether ini file object exists
59  if (!is_object($ilDB)) {
60  die("Fatal Error: ilSettings object instantiated without DB initialisation.");
61  }
62  $this->read();
63  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ _changeValueType()

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

change the type of the value column in the database

Parameters
string$a_new_type'text' or 'clob'
Returns
bool
Exceptions
ilDatabaseException

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

References $DIC, $ilDB, and null.

220  : bool {
221  global $DIC;
222 
223  $ilDB = $DIC->database();
224 
225  $old_type = self::_getValueType();
226 
227  if ($a_new_type === $old_type) {
228  return false;
229  }
230  if ($a_new_type === 'clob') {
231  $ilDB->addTableColumn(
232  'settings',
233  'value2',
234  array( "type" => "clob",
235  "notnull" => false,
236  "default" => null)
237  );
238 
239  $ilDB->query("UPDATE settings SET value2 = value");
240  $ilDB->dropTableColumn('settings', 'value');
241  $ilDB->renameTableColumn('settings', 'value2', 'value');
242 
243  return true;
244  }
245  if ($a_new_type === 'text') {
246  $ilDB->addTableColumn(
247  'settings',
248  'value2',
249  array( "type" => "text",
250  "length" => 4000,
251  "notnull" => false,
252  "default" => null)
253  );
254 
255  $ilDB->query("UPDATE settings SET value2 = value");
256  $ilDB->dropTableColumn('settings', 'value');
257  $ilDB->renameTableColumn('settings', 'value2', 'value');
258 
259  return true;
260  }
261  return false;
262  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22

◆ _getLongerSettings()

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

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

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

References $DIC, and $ilDB.

270  : array {
271  global $DIC;
272 
273  $ilDB = $DIC->database();
274 
275  $settings = array();
276 
277  $query = "SELECT * FROM settings WHERE LENGTH(value) > "
278  . $ilDB->quote($a_limit, 'integer');
279 
280  $result = $ilDB->query($query);
281 
282  while ($row = $ilDB->fetchAssoc($result)) {
283  $settings[] = $row;
284  }
285 
286  return $settings;
287  }
global $DIC
Definition: shib_login.php:22

◆ _getValueType()

static ilSetting::_getValueType ( )
static

Get the type of the value column in the database.

Exceptions
ilDatabaseException

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

200  : string
201  {
202  $analyzer = new ilDBAnalyzer();
203  $info = $analyzer->getFieldInformation('settings');
204 
205  if ($info['value']['type'] === 'clob') {
206  return 'clob';
207  } else {
208  return 'text';
209  }
210  }
This class gives all kind of DB information using the database manager and reverse module...

◆ _lookupValue()

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

Implements ILIAS\Administration\Setting.

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

References $data, $DIC, $ilDB, $res, and null.

Referenced by ilObjectAdditionalPropertiesLegacyRepository\areCustomIconsEnabled(), and ILIAS\BackgroundTasks\Task\Job\Manager\JobManagerImpl\runActiveJobs().

185  : ?string {
186  global $DIC;
187 
188  $ilDB = $DIC->database();
189 
190  $query = "SELECT value FROM settings WHERE module = %s AND keyword = %s";
191  $res = $ilDB->queryF($query, array('text', 'text'), array($a_module, $a_keyword));
192  $data = $ilDB->fetchAssoc($res);
193  return $data['value'] ?? null;
194  }
$res
Definition: ltiservices.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ delete()

ilSetting::delete ( string  $a_keyword)

Implements ILIAS\Administration\Setting.

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

References $db, and $ilDB.

Referenced by ilCertificateScormTemplateDeleteAction\delete(), and ilObjNotificationAdminGUI\saveOSDSettings().

129  : void
130  {
131  $ilDB = $this->db;
132 
133  $ilDB->manipulate("DELETE FROM settings WHERE keyword = " .
134  $ilDB->quote($a_keyword, "text") . " AND module = " .
135  $ilDB->quote($this->module, "text"));
136 
137  unset($this->setting[$a_keyword]);
138  }
ilDBInterface $db
+ Here is the caller graph for this function:

◆ deleteAll()

ilSetting::deleteAll ( )

Implements ILIAS\Administration\Setting.

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

References $db, and $ilDB.

106  : void
107  {
108  $ilDB = $this->db;
109 
110  $query = "DELETE FROM settings WHERE module = " . $ilDB->quote($this->module, "text");
111  $ilDB->manipulate($query);
112 
113  $this->setting = array();
114  }
ilDBInterface $db

◆ deleteLike()

ilSetting::deleteLike ( string  $a_like)

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

References $db, $ilDB, and $res.

116  : void
117  {
118  $ilDB = $this->db;
119 
120  $query = "SELECT keyword FROM settings" .
121  " WHERE module = " . $ilDB->quote($this->module, "text") .
122  " AND " . $ilDB->like("keyword", "text", $a_like);
123  $res = $ilDB->query($query);
124  while ($row = $ilDB->fetchAssoc($res)) {
125  $this->delete($row["keyword"]);
126  }
127  }
$res
Definition: ltiservices.php:66
ilDBInterface $db

◆ get()

◆ getAll()

ilSetting::getAll ( )

Implements ILIAS\Administration\Setting.

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

References $setting.

Referenced by ilObjAuthSettingsGUI\apacheAuthSettingsObject().

140  : array
141  {
142  return $this->setting;
143  }
+ Here is the caller graph for this function:

◆ getModule()

ilSetting::getModule ( )

Implements ILIAS\Administration\Setting.

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

References $module.

65  : string
66  {
67  return $this->module;
68  }
string $module

◆ read()

ilSetting::read ( )

Implements ILIAS\Administration\Setting.

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

References $db, $ilDB, $module, $res, and $setting.

Referenced by __construct().

70  : void
71  {
72  $ilDB = $this->db;
73 
74  // get the settings from the cache if they exist.
75  // The setting array of the class is a reference to the cache.
76  // So changing settings in one instance will change them in all.
77  // This is the same behaviour as if the are read from the DB.
78  if (!$this->cache_disabled) {
79  if (isset(self::$settings_cache[$this->module])) {
80  $this->setting = &self::$settings_cache[$this->module];
81  return;
82  } else {
83  $this->setting = array();
84  self::$settings_cache[$this->module] = &$this->setting;
85  }
86  }
87 
88  $query = "SELECT * FROM settings WHERE module=" . $ilDB->quote($this->module, "text");
89  $res = $ilDB->query($query);
90 
91  while ($row = $ilDB->fetchAssoc($res)) {
92  $this->setting[$row["keyword"]] = $row["value"];
93  }
94  }
$res
Definition: ltiservices.php:66
ilDBInterface $db
string $module
+ Here is the caller graph for this function:

◆ set()

ilSetting::set ( string  $a_key,
string  $a_val 
)

Implements ILIAS\Administration\Setting.

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

References $db, $DIC, and $ilDB.

Referenced by ilMailCronNotification\activationWasToggled(), ilForumCronNotification\activationWasToggled(), ilMembershipCronNotifications\activationWasToggled(), ilObjAuthSettingsGUI\saveApacheSettingsObject(), ilObjNotificationAdminGUI\saveOSDSettings(), ilObjLearningHistorySettingsGUI\saveSettings(), ilObjNotesSettingsGUI\saveSettings(), ilObjCommentsSettingsGUI\saveSettings(), ilCleanCOPageHistoryCronjob\setCronDays(), ilCleanCOPageHistoryCronjob\setKeepEntries(), ilObjAdvancedEditing\setRichTextEditor(), and ilObjAdvancedEditing\setUsedHTMLTags().

145  : void
146  {
147  $ilDB = $this->db;
148 
149  $this->delete($a_key);
150 
151  if (!isset(self::$value_type)) {
152  self::$value_type = self::_getValueType();
153  }
154 
155  if (self::$value_type === 'text' && strlen($a_val) >= 4000) {
156  global $DIC;
157  $DIC->ui()->mainTemplate()->setOnScreenMessage('failure', $DIC->language()->txt('setting_value_truncated'), true);
158  $a_val = substr($a_val, 0, 4000);
159  }
160 
161  $ilDB->insert("settings", array(
162  "module" => array("text", $this->module),
163  "keyword" => array("text", $a_key),
164  "value" => array(self::$value_type, $a_val)));
165 
166  $this->setting[$a_key] = $a_val;
167  }
ilDBInterface $db
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ setScormDebug()

ilSetting::setScormDebug ( string  $a_key,
string  $a_val 
)
Todo:
this must not be part of a general settings class
Deprecated:

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

References $db, and $ilDB.

173  : void
174  {
175  $ilDB = $this->db;
176  if ($a_val !== "1") {
177  $ilDB->query("UPDATE sahs_lm SET debug = 'n'");
178  }
179  $this->set($a_key, $a_val);
180  }
ilDBInterface $db

Field Documentation

◆ $cache_disabled

bool ilSetting::$cache_disabled = false
protected

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

◆ $db

ilDBInterface ilSetting::$db
protected

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

Referenced by delete(), deleteAll(), deleteLike(), read(), set(), and setScormDebug().

◆ $module

string ilSetting::$module = ""

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

Referenced by getModule(), and read().

◆ $setting

array ilSetting::$setting = array()

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

Referenced by getAll(), and read().

◆ $settings_cache

array 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 35 of file class.ilSetting.php.

◆ $value_type

string 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 42 of file class.ilSetting.php.


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