ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBlockSetting.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 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 {
33  static $setting = array();
34  static $pd_preloaded = false;
35 
40  public static function _lookup($a_type, $a_setting, $a_user = 0, $a_block_id = 0)
41  {
42  global $ilDB;
43 
44  $key = $a_type.":".$a_setting.":".$a_user.":".$a_block_id;
45  if (isset(self::$setting[$key]))
46  {
47  return self::$setting[$key];
48  }
49 
50  $set = $ilDB->query(sprintf("SELECT value FROM il_block_setting WHERE type = %s ".
51  "AND user_id = %s AND setting = %s AND block_id = %s",
52  $ilDB->quote($a_type, "text"),
53  $ilDB->quote($a_user, "integer"),
54  $ilDB->quote($a_setting, "text"),
55  $ilDB->quote($a_block_id, "integer")));
56  if ($rec = $ilDB->fetchAssoc($set))
57  {
58  self::$setting[$key] = $rec["value"];
59  return $rec["value"];
60  }
61  else
62  {
63  self::$setting[$key] = false;
64  return false;
65  }
66  }
67 
75  {
76  global $ilDB, $ilUser;
77 
78  if (!self::$pd_preloaded)
79  {
80  $blocks = array("pdbookm", "pdcal", "pdfeedb", "pditems",
81  "pdmail", "pdnews", "pdnotes", "pdsysmess", "pdtag", "pdusers");
82  $settings = array("detail", "nr", "side");
83  $user_id = $ilUser->getId();
84 
85  foreach ($blocks as $b)
86  {
87  foreach ($settings as $s)
88  {
89  $key = $b.":".$s.":".$user_id.":0";
90  if ($s == "detail")
91  {
92  self::$setting[$key] = 2;
93  }
94  else
95  {
96  self::$setting[$key] = false;
97  }
98  }
99  }
100 
101  $set = $ilDB->query($q = "SELECT type, setting, value FROM il_block_setting WHERE ".
102  " user_id = ".$ilDB->quote($user_id, "integer").
103  " AND ".$ilDB->in("type", $blocks, false, "text").
104  " AND ".$ilDB->in("setting", $settings, false, "text")
105  );
106  while ($rec = $ilDB->fetchAssoc($set))
107  {
108  $key = $rec["type"].":".$rec["setting"].":".$user_id.":0";
109  self::$setting[$key] = $rec["value"];
110  }
111 
112  self::$pd_preloaded = true;
113  }
114 
115  }
116 
121  public static function _write($a_type, $a_setting, $a_value, $a_user = 0, $a_block_id = 0)
122  {
123  global $ilDB;
124 
125  $ilDB->manipulate(sprintf("DELETE FROM il_block_setting WHERE type = %s AND user_id = %s AND block_id = %s AND setting = %s",
126  $ilDB->quote($a_type, "text"),
127  $ilDB->quote($a_user, "integer"),
128  $ilDB->quote((int) $a_block_id, "integer"),
129  $ilDB->quote($a_setting, "text")));
130  $ilDB->manipulate(sprintf("INSERT INTO il_block_setting (type, user_id, setting, block_id, value) VALUES (%s,%s,%s,%s,%s)",
131  $ilDB->quote($a_type, "text"),
132  $ilDB->quote($a_user, "integer"),
133  $ilDB->quote($a_setting, "text"),
134  $ilDB->quote((int) $a_block_id, "integer"),
135  $ilDB->quote($a_value, "text")));
136  }
137 
142  public static function _lookupDetailLevel($a_type, $a_user = 0, $a_block_id = 0)
143  {
144  $detail = ilBlockSetting::_lookup($a_type, "detail", $a_user, $a_block_id);
145 
146  if ($detail === false) // return a level of 2 (standard value)
147  { // if record does not exist
148  return 2;
149  }
150  else
151  {
152  return $detail;
153  }
154  }
155 
160  public static function _writeDetailLevel($a_type, $a_value, $a_user = 0, $a_block_id = 0)
161  {
162  ilBlockSetting::_write($a_type, "detail", $a_value, $a_user, $a_block_id);
163  }
164 
169  public static function _lookupNr($a_type, $a_user = 0, $a_block_id = 0)
170  {
171  $nr = ilBlockSetting::_lookup($a_type, "nr", $a_user, $a_block_id);
172 
173  return $nr;
174  }
175 
180  public static function _writeNumber($a_type, $a_value, $a_user = 0, $a_block_id = 0)
181  {
182  ilBlockSetting::_write($a_type, "nr", $a_value, $a_user, $a_block_id);
183  }
184 
189  public static function _lookupSide($a_type, $a_user = 0, $a_block_id = 0)
190  {
191  $side = ilBlockSetting::_lookup($a_type, "side", $a_user, $a_block_id);
192 
193  return $side;
194  }
195 
200  public static function _writeSide($a_type, $a_value, $a_user = 0, $a_block_id = 0)
201  {
202  ilBlockSetting::_write($a_type, "side", $a_value, $a_user, $a_block_id);
203  }
204 
209  public static function _deleteSettingsOfUser($a_user)
210  {
211  global $ilDB;
212 
213  if ($a_user > 0)
214  {
215  $ilDB->manipulate("DELETE FROM il_block_setting WHERE user_id = ".
216  $ilDB->quote($a_user, "integer"));
217  }
218  }
219 
224  public static function _deleteSettingsOfBlock($a_block_id, $a_block_type)
225  {
226  global $ilDB;
227 
228  if ($a_block_id > 0)
229  {
230  $ilDB->manipulate("DELETE FROM il_block_setting WHERE block_id = ".
231  $ilDB->quote($a_block_id, "integer").
232  " AND type = ".$ilDB->quote($a_block_type, "text"));
233  }
234  }
235 
236 }
237 ?>