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