ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
34  var $setting = array();
35  var $module = "";
36 
40  function ilSetting($a_module = "common")
41  {
42  global $ilDB;
43 
44  $this->module = $a_module;
45  // check whether ini file object exists
46  if (!is_object($ilDB))
47  {
48  die ("Fatal Error: ilSettings object instantiated without DB initialisation.");
49  }
50 
51  $query = "SELECT * FROM settings WHERE module=" . $ilDB->quote($this->module);
52  $res = $ilDB->query($query);
53 
54  while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
55  {
56  $this->setting[$row["keyword"]] = $row["value"];
57  }
58 
59  }
60 
71  function get($a_keyword, $a_default_value = false)
72  {
73  if ($a_keyword == "ilias_version")
74  {
75  return ILIAS_VERSION;
76  }
77 
78  if (isset($this->setting[$a_keyword]))
79  {
80  return $this->setting[$a_keyword];
81  }
82  else
83  {
84  return $a_default_value;
85  }
86  }
87 
94  public function deleteAll()
95  {
96  global $ilDB;
97 
98  $query = "DELETE FROM settings WHERE module = ".$ilDB->quote($this->module)." ";
99  $ilDB->query($query);
100  $this->settings = array();
101  return true;
102  }
103 
110  function delete($a_keyword)
111  {
112  global $ilDB;
113 
114  $query = "DELETE FROM settings WHERE keyword = ".
115  $ilDB->quote($a_keyword) . " AND module=" . $ilDB->quote($this->module);
116  $ilDB->query($query);
117  unset($this->setting[$a_keyword]);
118 
119  return true;
120  }
121 
122 
123 
129  function getAll()
130  {
131  return $this->setting;
132  }
133 
141  function set($a_key, $a_val)
142  {
143  global $ilDB;
144 
145  $sql = "DELETE FROM settings WHERE keyword=".$ilDB->quote($a_key).
146  " AND module=" . $ilDB->quote($this->module);
147  $ilDB->query($sql);
148 
149  $sql = "INSERT INTO settings (module, keyword, value) VALUES (".
150  $ilDB->quote($this->module) . ",".$ilDB->quote($a_key).",".$ilDB->quote($a_val).")";
151  $ilDB->query($sql);
152 
153  $this->setting[$a_key] = $a_val;
154 
155  return true;
156  }
157 
158 }
159 ?>