ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCache.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 
31 class ilCache
32 {
33  private $module = "";
34 
38  function __construct($a_module = "common")
39  {
40  global $ilDB;
41 
42  $this->module = $a_module;
43  }
44 
53  public function getValue($a_keyword)
54  {
55  global $ilDB;
56  $query = sprintf("SELECT * FROM data_cache WHERE module = %s AND keyword = %s",
57  $ilDB->quote($this->module),
58  $ilDB->quote($a_keyword)
59  );
60  $res = $ilDB->query($query);
61 
62  if ($res->numRows() == 1)
63  {
64  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
65  return $row["value"];
66  }
67  else
68  {
69  return NULL;
70  }
71  }
72 
82  public function getValueForModule($a_module, $a_keyword)
83  {
84  global $ilDB;
85  $query = sprintf("SELECT * FROM data_cache WHERE module = %s AND keyword = %s",
86  $ilDB->quote($a_module),
87  $ilDB->quote($a_keyword)
88  );
89  $res = $ilDB->query($query);
90 
91  if ($res->numRows() == 1)
92  {
93  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
94  return $row["value"];
95  }
96  else
97  {
98  return NULL;
99  }
100  }
101 
109  public function deleteAll($a_module = "")
110  {
111  global $ilDB;
112 
113  $module = (strlen($a_module) ? $a_module : $this->module);
114  $query = sprintf("DELETE FROM data_cache WHERE module = %s",
115  $ilDB->quote($module)
116  );
117  $ilDB->query($query);
118  }
119 
125  public function deleteValue($a_keyword)
126  {
127  global $ilDB;
128 
129  $query = sprintf("DELETE FROM data_cache WHERE keyword = %s AND module = %s",
130  $ilDB->quote($a_keyword),
131  $ilDB->quote($this->module)
132  );
133  $ilDB->query($query);
134  }
135 
143  public function setValue($a_key, $a_val)
144  {
145  global $ilDB, $ilLog;
146 
147  $sql = sprintf("DELETE FROM data_cache WHERE keyword = %s AND module = %s",
148  $ilDB->quote($a_key),
149  $ilDB->quote($this->module)
150  );
151  $ilDB->query($sql);
152 
153  $sql = sprintf("INSERT INTO data_cache (module, keyword, value) VALUES (%s, %s, %s)",
154  $ilDB->quote($this->module),
155  $ilDB->quote($a_key),
156  $ilDB->quote($a_val)
157  );
158  $ilDB->query($sql);
159  }
160 
161 }
162 ?>