ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBlockSetting.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 {
31  public static array $setting = array();
32  public static bool $pd_preloaded = false;
33 
37  public static function _lookup(
38  string $a_type,
39  string $a_setting,
40  int $a_user = 0,
41  int $a_block_id = 0
42  ): ?string {
43  global $DIC;
44 
45  $ilDB = $DIC->database();
46  $ilSetting = $DIC->settings();
47 
48  $key = $a_type . ":" . $a_setting . ":" . $a_user . ":" . $a_block_id;
49  if (isset(self::$setting[$key])) {
50  return (string) self::$setting[$key];
51  }
52 
53  $set = $ilDB->query(sprintf(
54  "SELECT value FROM il_block_setting WHERE type = %s " .
55  "AND user_id = %s AND setting = %s AND block_id = %s",
56  $ilDB->quote($a_type, "text"),
57  $ilDB->quote($a_user, "integer"),
58  $ilDB->quote($a_setting, "text"),
59  $ilDB->quote($a_block_id, "integer")
60  ));
61  if ($rec = $ilDB->fetchAssoc($set)) {
62  self::$setting[$key] = $rec["value"];
63  return $rec["value"];
64  } elseif ($ilSetting->get('block_default_setting_' . $a_type . '_' . $a_setting, null)) {
65  self::$setting[$key] = $ilSetting->get('block_default_setting_' . $a_type . '_' . $a_setting, null);
66  return $ilSetting->get('block_default_setting_' . $a_type . '_' . $a_setting, null);
67  } else {
68  self::$setting[$key] = false;
69  return null;
70  }
71  }
72 
76  public static function preloadPDBlockSettings(): void
77  {
78  global $DIC;
79 
80  $ilDB = $DIC->database();
81  $ilUser = $DIC->user();
82 
83  if (!self::$pd_preloaded) {
84  $blocks = array("pdbookm", "pdcal", "pdfeedb", "pditems",
85  "pdmail", "pdnews", "pdnotes", "pdtag");
86  $settings = array("detail", "nr", "side");
87  $user_id = $ilUser->getId();
88 
89  foreach ($blocks as $b) {
90  foreach ($settings as $s) {
91  $key = $b . ":" . $s . ":" . $user_id . ":0";
92  if ($s == "detail") {
93  self::$setting[$key] = 2;
94  } else {
95  self::$setting[$key] = false;
96  }
97  }
98  }
99 
100  $set = $ilDB->query(
101  $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  $key = $rec["type"] . ":" . $rec["setting"] . ":" . $user_id . ":0";
108  self::$setting[$key] = $rec["value"];
109  }
110 
111  self::$pd_preloaded = true;
112  }
113  }
114 
118  public static function _write(
119  string $a_type,
120  string $a_setting,
121  string $a_value,
122  int $a_user = 0,
123  int $a_block_id = 0
124  ): void {
125  global $DIC;
126 
127  $ilDB = $DIC->database();
128 
129  $ilDB->manipulate(sprintf(
130  "DELETE FROM il_block_setting WHERE type = %s AND user_id = %s AND block_id = %s AND setting = %s",
131  $ilDB->quote($a_type, "text"),
132  $ilDB->quote($a_user, "integer"),
133  $ilDB->quote($a_block_id, "integer"),
134  $ilDB->quote($a_setting, "text")
135  ));
136  $ilDB->manipulate(sprintf(
137  "INSERT INTO il_block_setting (type, user_id, setting, block_id, value) VALUES (%s,%s,%s,%s,%s)",
138  $ilDB->quote($a_type, "text"),
139  $ilDB->quote($a_user, "integer"),
140  $ilDB->quote($a_setting, "text"),
141  $ilDB->quote($a_block_id, "integer"),
142  $ilDB->quote($a_value, "text")
143  ));
144  }
145 
149  public static function _lookupDetailLevel(
150  string $a_type,
151  int $a_user = 0,
152  int $a_block_id = 0
153  ): int {
154  $detail = self::_lookup($a_type, "detail", $a_user, $a_block_id);
155 
156  if (is_null($detail)) { // return a level of 2 (standard value) if record does not exist
157  return 2;
158  }
159 
160  return (int) $detail;
161  }
162 
163  public static function _writeDetailLevel(
164  string $a_type,
165  string $a_value,
166  int $a_user = 0,
167  int $a_block_id = 0
168  ): void {
169  ilBlockSetting::_write($a_type, "detail", $a_value, $a_user, $a_block_id);
170  }
171 
172  public static function _writeNumber(
173  string $a_type,
174  string $a_value,
175  int $a_user = 0,
176  int $a_block_id = 0
177  ): void {
178  ilBlockSetting::_write($a_type, "nr", $a_value, $a_user, $a_block_id);
179  }
180 
184  public static function _lookupSide(
185  string $a_type,
186  int $a_user = 0,
187  int $a_block_id = 0
188  ): ?string {
189  return ilBlockSetting::_lookup($a_type, "side", $a_user, $a_block_id);
190  }
191 
192  public static function _writeSide(
193  string $a_type,
194  string $a_value,
195  int $a_user = 0,
196  int $a_block_id = 0
197  ): void {
198  ilBlockSetting::_write($a_type, "side", $a_value, $a_user, $a_block_id);
199  }
200 
201  public static function _deleteSettingsOfUser(
202  int $a_user
203  ): void {
204  global $DIC;
205 
206  $ilDB = $DIC->database();
207 
208  if ($a_user > 0) {
209  $ilDB->manipulate("DELETE FROM il_block_setting WHERE user_id = " .
210  $ilDB->quote($a_user, "integer"));
211  }
212  }
213 
214  public static function _deleteSettingsOfBlock(
215  int $a_block_id,
216  string $a_block_type
217  ): void {
218  global $DIC;
219 
220  $ilDB = $DIC->database();
221 
222  if ($a_block_id > 0) {
223  $ilDB->manipulate("DELETE FROM il_block_setting WHERE block_id = " .
224  $ilDB->quote($a_block_id, "integer") .
225  " AND type = " . $ilDB->quote($a_block_type, "text"));
226  }
227  }
228 
229  public static function cloneSettingsOfBlock(
230  string $block_type,
231  int $block_id,
232  int $new_block_id
233  ): void {
234  global $DIC;
235 
236  $db = $DIC->database();
237 
238  $set = $db->queryF(
239  "SELECT * FROM il_block_setting " .
240  " WHERE block_id = %s AND type = %s AND user_id = %s",
241  array("integer", "text", "integer"),
242  array($block_id, $block_type, 0)
243  );
244  while ($rec = $db->fetchAssoc($set)) {
245  self::_write($block_type, (string) $rec["setting"], (string) $rec["value"], 0, $new_block_id);
246  }
247  }
248 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
static bool $pd_preloaded
static _deleteSettingsOfUser(int $a_user)
static _lookupDetailLevel(string $a_type, int $a_user=0, int $a_block_id=0)
Lookup detail level.
global $DIC
Definition: feed.php:28
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
static _writeNumber(string $a_type, string $a_value, int $a_user=0, int $a_block_id=0)
static _writeDetailLevel(string $a_type, string $a_value, int $a_user=0, int $a_block_id=0)
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
string $key
Consumer key/client ID value.
Definition: System.php:193
static _deleteSettingsOfBlock(int $a_block_id, string $a_block_type)
static cloneSettingsOfBlock(string $block_type, int $block_id, int $new_block_id)
global $ilSetting
Definition: privfeed.php:17
static _writeSide(string $a_type, string $a_value, int $a_user=0, int $a_block_id=0)
static preloadPDBlockSettings()
Preload pd info.
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupSide(string $a_type, int $a_user=0, int $a_block_id=0)
Lookup side.