ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public static $setting = array();
34  public static $pd_preloaded = false;
35 
40  public static function _lookup($a_type, $a_setting, $a_user = 0, $a_block_id = 0)
41  {
42  global $DIC;
43 
44  $ilDB = $DIC->database();
45  $ilSetting = $DIC->settings();
46 
47  $key = $a_type . ":" . $a_setting . ":" . $a_user . ":" . $a_block_id;
48  if (isset(self::$setting[$key])) {
49  return self::$setting[$key];
50  }
51 
52  $set = $ilDB->query(sprintf(
53  "SELECT value FROM il_block_setting WHERE type = %s " .
54  "AND user_id = %s AND setting = %s AND block_id = %s",
55  $ilDB->quote($a_type, "text"),
56  $ilDB->quote($a_user, "integer"),
57  $ilDB->quote($a_setting, "text"),
58  $ilDB->quote($a_block_id, "integer")
59  ));
60  if ($rec = $ilDB->fetchAssoc($set)) {
61  self::$setting[$key] = $rec["value"];
62  return $rec["value"];
63  } elseif ($ilSetting->get('block_default_setting_' . $a_type . '_' . $a_setting, false)) {
64  self::$setting[$key] = $ilSetting->get('block_default_setting_' . $a_type . '_' . $a_setting, false);
65  return $ilSetting->get('block_default_setting_' . $a_type . '_' . $a_setting, false);
66  } else {
67  self::$setting[$key] = false;
68  return false;
69  }
70  }
71 
81  public static function _setDefaultSetting($a_type, $a_setting, $a_value)
82  {
83  global $DIC;
84 
85  $ilSetting = $DIC->settings();
86  $ilSetting->set('block_default_setting_' . $a_type . '_' . $a_setting, $a_value);
87  }
88 
97  public static function _unsetDefaultSetting($a_type, $a_setting)
98  {
99  global $DIC;
100 
101  $ilSetting = $DIC->settings();
102  $ilSetting->delete('block_default_setting_' . $a_type . '_' . $a_setting);
103  }
104 
111  public static function preloadPDBlockSettings()
112  {
113  global $DIC;
114 
115  $ilDB = $DIC->database();
116  $ilUser = $DIC->user();
117 
118  if (!self::$pd_preloaded) {
119  $blocks = array("pdbookm", "pdcal", "pdfeedb", "pditems",
120  "pdmail", "pdnews", "pdnotes", "pdsysmess", "pdtag");
121  $settings = array("detail", "nr", "side");
122  $user_id = $ilUser->getId();
123 
124  foreach ($blocks as $b) {
125  foreach ($settings as $s) {
126  $key = $b . ":" . $s . ":" . $user_id . ":0";
127  if ($s == "detail") {
128  self::$setting[$key] = 2;
129  } else {
130  self::$setting[$key] = false;
131  }
132  }
133  }
134 
135  $set = $ilDB->query(
136  $q = "SELECT type, setting, value FROM il_block_setting WHERE " .
137  " user_id = " . $ilDB->quote($user_id, "integer") .
138  " AND " . $ilDB->in("type", $blocks, false, "text") .
139  " AND " . $ilDB->in("setting", $settings, false, "text")
140  );
141  while ($rec = $ilDB->fetchAssoc($set)) {
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 
154  public static function _write($a_type, $a_setting, $a_value, $a_user = 0, $a_block_id = 0)
155  {
156  global $DIC;
157 
158  $ilDB = $DIC->database();
159 
160  $ilDB->manipulate(sprintf(
161  "DELETE FROM il_block_setting WHERE type = %s AND user_id = %s AND block_id = %s AND setting = %s",
162  $ilDB->quote($a_type, "text"),
163  $ilDB->quote($a_user, "integer"),
164  $ilDB->quote((int) $a_block_id, "integer"),
165  $ilDB->quote($a_setting, "text")
166  ));
167  $ilDB->manipulate(sprintf(
168  "INSERT INTO il_block_setting (type, user_id, setting, block_id, value) VALUES (%s,%s,%s,%s,%s)",
169  $ilDB->quote($a_type, "text"),
170  $ilDB->quote($a_user, "integer"),
171  $ilDB->quote($a_setting, "text"),
172  $ilDB->quote((int) $a_block_id, "integer"),
173  $ilDB->quote($a_value, "text")
174  ));
175  }
176 
181  public static function _lookupDetailLevel($a_type, $a_user = 0, $a_block_id = 0)
182  {
183  $detail = ilBlockSetting::_lookup($a_type, "detail", $a_user, $a_block_id);
184 
185  if ($detail === false) { // return a level of 2 (standard value)
186  // if record does not exist
187  return 2;
188  } else {
189  return $detail;
190  }
191  }
192 
197  public static function _writeDetailLevel($a_type, $a_value, $a_user = 0, $a_block_id = 0)
198  {
199  ilBlockSetting::_write($a_type, "detail", $a_value, $a_user, $a_block_id);
200  }
201 
206  public static function _lookupNr($a_type, $a_user = 0, $a_block_id = 0)
207  {
208  $nr = ilBlockSetting::_lookup($a_type, "nr", $a_user, $a_block_id);
209 
210  return $nr;
211  }
212 
217  public static function _writeNumber($a_type, $a_value, $a_user = 0, $a_block_id = 0)
218  {
219  ilBlockSetting::_write($a_type, "nr", $a_value, $a_user, $a_block_id);
220  }
221 
226  public static function _lookupSide($a_type, $a_user = 0, $a_block_id = 0)
227  {
228  $side = ilBlockSetting::_lookup($a_type, "side", $a_user, $a_block_id);
229 
230  return $side;
231  }
232 
237  public static function _writeSide($a_type, $a_value, $a_user = 0, $a_block_id = 0)
238  {
239  ilBlockSetting::_write($a_type, "side", $a_value, $a_user, $a_block_id);
240  }
241 
246  public static function _deleteSettingsOfUser($a_user)
247  {
248  global $DIC;
249 
250  $ilDB = $DIC->database();
251 
252  if ($a_user > 0) {
253  $ilDB->manipulate("DELETE FROM il_block_setting WHERE user_id = " .
254  $ilDB->quote($a_user, "integer"));
255  }
256  }
257 
262  public static function _deleteSettingsOfBlock($a_block_id, $a_block_type)
263  {
264  global $DIC;
265 
266  $ilDB = $DIC->database();
267 
268  if ($a_block_id > 0) {
269  $ilDB->manipulate("DELETE FROM il_block_setting WHERE block_id = " .
270  $ilDB->quote($a_block_id, "integer") .
271  " AND type = " . $ilDB->quote($a_block_type, "text"));
272  }
273  }
274 
282  public static function cloneSettingsOfBlock(string $block_type, int $block_id, int $new_block_id)
283  {
284  global $DIC;
285 
286  $db = $DIC->database();
287 
288  $set = $db->queryF(
289  "SELECT * FROM il_block_setting " .
290  " WHERE block_id = %s AND type = %s AND user_id = %s",
291  array("integer", "text", "integer"),
292  array($block_id, $block_type, 0)
293  );
294  while ($rec = $db->fetchAssoc($set)) {
295  self::_write($block_type, $rec["setting"], $rec["value"], 0, $new_block_id);
296  }
297  }
298 }
static _setDefaultSetting($a_type, $a_setting, $a_value)
Sets a default setting for a block.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
static _writeDetailLevel($a_type, $a_value, $a_user=0, $a_block_id=0)
Write detail level to database.
static _deleteSettingsOfUser($a_user)
Delete block settings of user.
global $DIC
Definition: saml.php:7
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.
$s
Definition: pwgen.php:45
$a_type
Definition: workflow.php:92
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
static _deleteSettingsOfBlock($a_block_id, $a_block_type)
Delete block settings of block.
$ilUser
Definition: imgupload.php:18
static cloneSettingsOfBlock(string $block_type, int $block_id, int $new_block_id)
Clone block settings.
static _lookupSide($a_type, $a_user=0, $a_block_id=0)
Lookup side.
static _lookupNr($a_type, $a_user=0, $a_block_id=0)
Lookup number.
global $ilSetting
Definition: privfeed.php:17
static preloadPDBlockSettings()
Preload pd info.
global $ilDB
static _unsetDefaultSetting($a_type, $a_setting)
Unsets a default setting for a block.
static _writeNumber($a_type, $a_value, $a_user=0, $a_block_id=0)
Write number to database.
Block Setting class.
$key
Definition: croninfo.php:18