ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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, $ilSetting;
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 if ($ilSetting->get('block_default_setting_'.$a_type.'_'.$a_setting, false))
62 {
63 self::$setting[$key] = $ilSetting->get('block_default_setting_'.$a_type.'_'.$a_setting, false);
64 return $ilSetting->get('block_default_setting_'.$a_type.'_'.$a_setting, false);
65 }
66 else
67 {
68 self::$setting[$key] = false;
69 return false;
70 }
71 }
72
82 public static function _setDefaultSetting($a_type, $a_setting, $a_value)
83 {
84 global $ilSetting;
85 $ilSetting->set('block_default_setting_'.$a_type.'_'.$a_setting, $a_value);
86 }
87
96 public static function _unsetDefaultSetting($a_type, $a_setting)
97 {
98 global $ilSetting;
99 $ilSetting->delete('block_default_setting_'.$a_type.'_'.$a_setting);
100 }
101
109 {
110 global $ilDB, $ilUser;
111
112 if (!self::$pd_preloaded)
113 {
114 $blocks = array("pdbookm", "pdcal", "pdfeedb", "pditems",
115 "pdmail", "pdnews", "pdnotes", "pdsysmess", "pdtag", "pdusers");
116 $settings = array("detail", "nr", "side");
117 $user_id = $ilUser->getId();
118
119 foreach ($blocks as $b)
120 {
121 foreach ($settings as $s)
122 {
123 $key = $b.":".$s.":".$user_id.":0";
124 if ($s == "detail")
125 {
126 self::$setting[$key] = 2;
127 }
128 else
129 {
130 self::$setting[$key] = false;
131 }
132 }
133 }
134
135 $set = $ilDB->query($q = "SELECT type, setting, value FROM il_block_setting WHERE ".
136 " user_id = ".$ilDB->quote($user_id, "integer").
137 " AND ".$ilDB->in("type", $blocks, false, "text").
138 " AND ".$ilDB->in("setting", $settings, false, "text")
139 );
140 while ($rec = $ilDB->fetchAssoc($set))
141 {
142 $key = $rec["type"].":".$rec["setting"].":".$user_id.":0";
143 self::$setting[$key] = $rec["value"];
144 }
145
146 self::$pd_preloaded = true;
147 }
148
149 }
150
155 public static function _write($a_type, $a_setting, $a_value, $a_user = 0, $a_block_id = 0)
156 {
157 global $ilDB;
158
159 $ilDB->manipulate(sprintf("DELETE FROM il_block_setting WHERE type = %s AND user_id = %s AND block_id = %s AND setting = %s",
160 $ilDB->quote($a_type, "text"),
161 $ilDB->quote($a_user, "integer"),
162 $ilDB->quote((int) $a_block_id, "integer"),
163 $ilDB->quote($a_setting, "text")));
164 $ilDB->manipulate(sprintf("INSERT INTO il_block_setting (type, user_id, setting, block_id, value) VALUES (%s,%s,%s,%s,%s)",
165 $ilDB->quote($a_type, "text"),
166 $ilDB->quote($a_user, "integer"),
167 $ilDB->quote($a_setting, "text"),
168 $ilDB->quote((int) $a_block_id, "integer"),
169 $ilDB->quote($a_value, "text")));
170 }
171
176 public static function _lookupDetailLevel($a_type, $a_user = 0, $a_block_id = 0)
177 {
178 $detail = ilBlockSetting::_lookup($a_type, "detail", $a_user, $a_block_id);
179
180 if ($detail === false) // return a level of 2 (standard value)
181 { // if record does not exist
182 return 2;
183 }
184 else
185 {
186 return $detail;
187 }
188 }
189
194 public static function _writeDetailLevel($a_type, $a_value, $a_user = 0, $a_block_id = 0)
195 {
196 ilBlockSetting::_write($a_type, "detail", $a_value, $a_user, $a_block_id);
197 }
198
203 public static function _lookupNr($a_type, $a_user = 0, $a_block_id = 0)
204 {
205 $nr = ilBlockSetting::_lookup($a_type, "nr", $a_user, $a_block_id);
206
207 return $nr;
208 }
209
214 public static function _writeNumber($a_type, $a_value, $a_user = 0, $a_block_id = 0)
215 {
216 ilBlockSetting::_write($a_type, "nr", $a_value, $a_user, $a_block_id);
217 }
218
223 public static function _lookupSide($a_type, $a_user = 0, $a_block_id = 0)
224 {
225 $side = ilBlockSetting::_lookup($a_type, "side", $a_user, $a_block_id);
226
227 return $side;
228 }
229
234 public static function _writeSide($a_type, $a_value, $a_user = 0, $a_block_id = 0)
235 {
236 ilBlockSetting::_write($a_type, "side", $a_value, $a_user, $a_block_id);
237 }
238
243 public static function _deleteSettingsOfUser($a_user)
244 {
245 global $ilDB;
246
247 if ($a_user > 0)
248 {
249 $ilDB->manipulate("DELETE FROM il_block_setting WHERE user_id = ".
250 $ilDB->quote($a_user, "integer"));
251 }
252 }
253
258 public static function _deleteSettingsOfBlock($a_block_id, $a_block_type)
259 {
260 global $ilDB;
261
262 if ($a_block_id > 0)
263 {
264 $ilDB->manipulate("DELETE FROM il_block_setting WHERE block_id = ".
265 $ilDB->quote($a_block_id, "integer").
266 " AND type = ".$ilDB->quote($a_block_type, "text"));
267 }
268 }
269
270}
271?>
Block Setting class.
static _lookupNr($a_type, $a_user=0, $a_block_id=0)
Lookup number.
static _writeDetailLevel($a_type, $a_value, $a_user=0, $a_block_id=0)
Write detail level to database.
preloadPDBlockSettings()
Preload pd info.
static _unsetDefaultSetting($a_type, $a_setting)
Unsets a default setting for a block.
static _lookupSide($a_type, $a_user=0, $a_block_id=0)
Lookup side.
static _writeNumber($a_type, $a_value, $a_user=0, $a_block_id=0)
Write number to database.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
static _deleteSettingsOfUser($a_user)
Delete block settings of user.
static _setDefaultSetting($a_type, $a_setting, $a_value)
Sets a default setting for a block.
static _writeSide($a_type, $a_value, $a_user=0, $a_block_id=0)
Write side to database.
static _lookupDetailLevel($a_type, $a_user=0, $a_block_id=0)
Lookup detail level.
static _deleteSettingsOfBlock($a_block_id, $a_block_type)
Delete block settings of block.
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
global $ilSetting
Definition: privfeed.php:40
global $ilDB
global $ilUser
Definition: imgupload.php:15