ILIAS  Release_4_0_x_branch Revision 61816
 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  $this->read();
51  }
52 
56  function read()
57  {
58  global $ilDB;
59 
60  $this->setting = array();
61 
62  $query = "SELECT * FROM settings WHERE module=".$ilDB->quote($this->module, "text");
63  $res = $ilDB->query($query);
64 
65  while ($row = $ilDB->fetchAssoc($res))
66  {
67  $this->setting[$row["keyword"]] = $row["value"];
68  }
69  }
70 
81  function get($a_keyword, $a_default_value = false)
82  {
83  if ($a_keyword == "ilias_version")
84  {
85  return ILIAS_VERSION;
86  }
87 
88  if (isset($this->setting[$a_keyword]))
89  {
90  return $this->setting[$a_keyword];
91  }
92  else
93  {
94  return $a_default_value;
95  }
96  }
97 
104  public function deleteAll()
105  {
106  global $ilDB;
107 
108  $query = "DELETE FROM settings WHERE module = ".$ilDB->quote($this->module, "text");
109  $ilDB->manipulate($query);
110 
111  $this->setting = array();
112 
113  return true;
114  }
115 
122  public function deleteLike($a_like)
123  {
124  global $ilDB;
125 
126  $query = "DELETE FROM settings WHERE module = ".$ilDB->quote($this->module, "text").
127  " AND ".$ilDB->like("keyword", "text", $a_like);
128  $ilDB->manipulate($query);
129 
130  $this->read();
131  return true;
132  }
133 
140  function delete($a_keyword)
141  {
142  global $ilDB;
143 
144  $st = $ilDB->manipulate("DELETE FROM settings WHERE keyword = ".
145  $ilDB->quote($a_keyword, "text")." AND module = ".
146  $ilDB->quote($this->module, "text"));
147 
148  unset($this->setting[$a_keyword]);
149 
150  return true;
151  }
152 
153 
154 
160  function getAll()
161  {
162  return $this->setting;
163  }
164 
172  function set($a_key, $a_val)
173  {
174  global $ilDB;
175 
176  $this->delete($a_key);
177 
178  /*$sql = "INSERT INTO settings (module, keyword, value) VALUES (".
179  $ilDB->quote($this->module, "text") .
180  ",".$ilDB->quote($a_key, "text").",".$ilDB->quote((string) $a_val, "clob").")";
181  $ilDB->manipulate($sql);*/
182  $ilDB->insert("settings", array(
183  "module" => array("text", $this->module),
184  "keyword" => array("text", $a_key),
185  "value" => array("clob", $a_val)));
186 
187  $this->setting[$a_key] = $a_val;
188 
189  return true;
190  }
191 
192  public static function _lookupValue($a_module, $a_keyword)
193  {
194  global $ilDB;
195 
196  $query = "SELECT value FROM settings WHERE module = %s AND keyword = %s";
197  $res = $ilDB->queryF($query, array('text', 'text'), array($a_module, $a_keyword));
198  $data = $ilDB->fetchAssoc($res);
199  return $data['value'];
200  }
201 }
202 ?>