ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjRepositorySettings.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 {
28  public const NEW_ITEM_GROUP_TYPE_GROUP = 1;
30 
31  public function __construct(int $a_id, bool $a_call_by_reference = true)
32  {
33  $this->type = "reps";
34  parent::__construct($a_id, $a_call_by_reference);
35  }
36 
37  public function delete(): bool
38  {
39  // DISABLED
40  return false;
41  }
42 
43  public static function addNewItemGroupSeparator(): bool
44  {
45  global $DIC;
46 
47  $ilDB = $DIC->database();
48 
49  // append
50  $pos = $ilDB->query("SELECT max(pos) mpos FROM il_new_item_grp");
51  $pos = $ilDB->fetchAssoc($pos);
52  $pos = (int) $pos["mpos"];
53  $pos += 10;
54 
55  $seq = $ilDB->nextID("il_new_item_grp");
56 
57  $ilDB->manipulate("INSERT INTO il_new_item_grp" .
58  " (id, pos, type) VALUES (" .
59  $ilDB->quote($seq, "integer") .
60  ", " . $ilDB->quote($pos, "integer") .
61  ", " . $ilDB->quote(self::NEW_ITEM_GROUP_TYPE_SEPARATOR, "integer") .
62  ")");
63  return true;
64  }
65 
66  public static function addNewItemGroup(array $a_titles): bool
67  {
68  global $DIC;
69 
70  $ilDB = $DIC->database();
71 
72  // append
73  $pos = $ilDB->query("SELECT max(pos) mpos FROM il_new_item_grp");
74  $pos = $ilDB->fetchAssoc($pos);
75  $pos = (int) $pos["mpos"];
76  $pos += 10;
77 
78  $seq = $ilDB->nextID("il_new_item_grp");
79 
80  $ilDB->manipulate("INSERT INTO il_new_item_grp" .
81  " (id, titles, pos, type) VALUES (" .
82  $ilDB->quote($seq, "integer") .
83  ", " . $ilDB->quote(serialize($a_titles), "text") .
84  ", " . $ilDB->quote($pos, "integer") .
85  ", " . $ilDB->quote(self::NEW_ITEM_GROUP_TYPE_GROUP, "integer") .
86  ")");
87  return true;
88  }
89 
90  public static function updateNewItemGroup(int $a_id, array $a_titles): bool
91  {
92  global $DIC;
93 
94  $ilDB = $DIC->database();
95 
96  $ilDB->manipulate("UPDATE il_new_item_grp" .
97  " SET titles = " . $ilDB->quote(serialize($a_titles), "text") .
98  " WHERE id = " . $ilDB->quote($a_id, "integer"));
99  return true;
100  }
101 
102  public static function deleteNewItemGroup(int $a_id): bool
103  {
104  global $DIC;
105 
106  $ilDB = $DIC->database();
107  $ilSetting = $DIC->settings();
108 
109  // move subitems to unassigned
110  $sub_items = self::getNewItemGroupSubItems();
111  $sub_items = $sub_items[$a_id] ?? null;
112  if ($sub_items) {
113  foreach ($sub_items as $obj_type) {
114  $old_pos = $ilSetting->get("obj_add_new_pos_" . $obj_type);
115  if (strlen($old_pos) === 8) {
116  $new_pos = "9999" . substr($old_pos, 4);
117  $ilSetting->set("obj_add_new_pos_" . $obj_type, $new_pos);
118  $ilSetting->set("obj_add_new_pos_grp_" . $obj_type, '0');
119  }
120  }
121  }
122 
123  $ilDB->manipulate("DELETE FROM il_new_item_grp" .
124  " WHERE id = " . $ilDB->quote($a_id, "integer"));
125  return true;
126  }
127 
128  public static function getNewItemGroups(): array
129  {
130  global $DIC;
131 
132  $ilDB = $DIC->database();
133  $lng = $DIC->language();
134  $ilUser = $DIC->user();
135 
136  $def_lng = $lng->getDefaultLanguage();
137  $usr_lng = $ilUser->getLanguage();
138 
139  $res = [];
140 
141  $set = $ilDB->query("SELECT * FROM il_new_item_grp ORDER BY pos");
142  while ($row = $ilDB->fetchAssoc($set)) {
143  if ((int) $row["type"] === self::NEW_ITEM_GROUP_TYPE_GROUP) {
144  $row["titles"] = unserialize($row["titles"], ["allowed_classes" => false]);
145 
146  $title = $row["titles"][$usr_lng] ?? "";
147  if ($title == "") {
148  $title = $row["titles"][$def_lng] ?? "";
149  }
150  if ($title == "") {
151  $title = array_shift($row["titles"]);
152  }
153  $row["title"] = $title;
154  } else {
155  $row["title"] = $lng->txt("rep_new_item_group_separator");
156  }
157 
158  $res[$row["id"]] = $row;
159  }
160 
161  return $res;
162  }
163 
164  public static function updateNewItemGroupOrder(array $a_order): void
165  {
166  global $DIC;
167 
168  $ilDB = $DIC->database();
169 
170  asort($a_order);
171  $pos = 0;
172  foreach (array_keys($a_order) as $id) {
173  $pos += 10;
174 
175  $ilDB->manipulate("UPDATE il_new_item_grp" .
176  " SET pos = " . $ilDB->quote($pos, "integer") .
177  " WHERE id = " . $ilDB->quote($id, "integer"));
178  }
179  }
180 
181  protected static function getAllObjTypes(): array
182  {
183  global $DIC;
184 
185  $component_repository = $DIC["component.repository"];
186  $objDefinition = $DIC["objDefinition"];
187 
188  $res = [];
189 
190  // parse modules
191  foreach ($component_repository->getComponents() as $mod) {
192  if ($mod->getType() !== ilComponentInfo::TYPE_MODULES) {
193  continue;
194  }
195  $has_repo = false;
196  $rep_types = $objDefinition->getRepositoryObjectTypesForComponent(ilComponentInfo::TYPE_MODULES, $mod->getName());
197  if (count($rep_types) > 0) {
198  foreach ($rep_types as $ridx => $rt) {
199  // we only want to display repository modules
200  if ($rt["repository"]) {
201  $has_repo = true;
202  } else {
203  unset($rep_types[$ridx]);
204  }
205  }
206  }
207  if ($has_repo) {
208  foreach ($rep_types as $rt) {
209  $res[] = $rt["id"];
210  }
211  }
212  }
213 
214  // parse plugins
215  $pl_names = $component_repository->getPluginSlotById("robj")->getActivePlugins();
216  foreach ($pl_names as $plugin) {
217  $res[] = $plugin->getId();
218  }
219 
220  return $res;
221  }
222 
223  public static function getNewItemGroupSubItems(): array
224  {
225  global $DIC;
226 
227  $ilSetting = $DIC->settings();
228 
229  $res = [];
230 
231  foreach (self::getAllObjTypes() as $type) {
232  $pos_grp = $ilSetting->get("obj_add_new_pos_grp_" . $type, '0');
233  $res[$pos_grp][] = $type;
234  }
235 
236  return $res;
237  }
238 
239  public static function getDefaultNewItemGrouping(): array
240  {
241  global $DIC;
242 
243  $lng = $DIC->language();
244 
245  $res = [];
246 
247  $groups = [
248  "organisation" => ["fold", "sess", "cat", "catr", "crs", "crsr", "grp", "grpr", "itgr", "book", "prg", "prgr"],
249  "communication" => ["frm", "chtr"],
250  "breaker1" => null,
251  "content" => ["file", "webr", "feed", "copa", "wiki", "blog", "lm", "htlm", "sahs", 'cmix', 'lti', "lso", "glo", "dcl", "bibl", "mcst", "mep"],
252  "breaker2" => null,
253  "assessment" => ["exc", "tst", "qpl", "iass"],
254  "feedback" => ["poll", "svy", "spl"],
255  "templates" => ["prtt"]
256  ];
257 
258  $pos = 0;
259  foreach ($groups as $group => $items) {
260  $pos += 10;
261  $grp_id = $pos / 10;
262 
263  if (is_array($items)) {
264  $title = $lng->txt("rep_add_new_def_grp_" . $group);
265 
266  $res["groups"][$grp_id] = [
267  "id" => $grp_id,
268  "titles" => [$lng->getUserLanguage() => $title],
269  "pos" => $pos,
270  "type" => self::NEW_ITEM_GROUP_TYPE_GROUP,
271  "title" => $title
272  ];
273 
274  foreach ($items as $idx => $item) {
275  $res["items"][$item] = $grp_id;
276  $res["sort"][$item] = str_pad((string) $pos, 4, "0", STR_PAD_LEFT) .
277  str_pad((string) ($idx + 1), 4, "0", STR_PAD_LEFT);
278  }
279  } else {
280  $title = "COL_SEP";
281 
282  $res["groups"][$grp_id] = [
283  "id" => $grp_id,
284  "titles" => [$lng->getUserLanguage() => $title],
285  "pos" => $pos,
286  "type" => self::NEW_ITEM_GROUP_TYPE_SEPARATOR,
287  "title" => $title
288  ];
289  }
290  }
291 
292  return $res;
293  }
294 
295  public static function deleteObjectType(string $a_type): void
296  {
297  global $DIC;
298 
299  $ilSetting = $DIC->settings();
300 
301  // see ilObjRepositorySettingsGUI::saveModules()
302  $ilSetting->delete("obj_dis_creation_" . $a_type);
303  $ilSetting->delete("obj_add_new_pos_" . $a_type);
304  $ilSetting->delete("obj_add_new_pos_grp_" . $a_type);
305  }
306 }
string $title
$res
Definition: ltiservices.php:69
string $type
__construct(int $a_id, bool $a_call_by_reference=true)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
getUserLanguage()
Return language of user.
getDefaultLanguage()
Return default language.
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
ilLanguage $lng
static updateNewItemGroup(int $a_id, array $a_titles)
static updateNewItemGroupOrder(array $a_order)
static addNewItemGroup(array $a_titles)
global $ilSetting
Definition: privfeed.php:18
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...