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