ILIAS  release_8 Revision v8.24
class.ilObjectAddNewItemGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
28 protected ilLanguage $lng;
32 protected ilCtrl $ctrl;
35
36 protected int $parent_ref_id;
37 protected int $mode;
38 protected array $disabled_object_types = [];
39 protected array $sub_objects = [];
40 protected int $url_creation_callback = 0;
41 protected string $url_creation;
42 protected ?ilGroupedListGUI $gl = null;
43
44 public function __construct(int $parent_ref_id)
45 {
46 global $DIC;
47
48 $this->lng = $DIC->language();
49 $this->obj_definition = $DIC["objDefinition"];
50 $this->settings = $DIC->settings();
51 $this->access = $DIC->access();
52 $this->ctrl = $DIC->ctrl();
53 $this->toolbar = $DIC->toolbar();
54 $this->tpl = $DIC["tpl"];
55
56 $this->parent_ref_id = $parent_ref_id;
58
59 $this->lng->loadLanguageModule("rep");
60 $this->lng->loadLanguageModule("cntr");
61 }
62
63 public function setMode(int $mode): void
64 {
65 $this->mode = $mode;
66 }
67
71 public function setDisabledObjectTypes(array $types): void
72 {
73 $this->disabled_object_types = $types;
74 }
75
79 public function setAfterCreationCallback(int $ref_id): void
80 {
81 $this->url_creation_callback = $ref_id;
82 }
83
87 public function setCreationUrl(string $url): void
88 {
89 $this->url_creation = $url;
90 }
91
97 protected function parsePersonalWorkspace(): bool
98 {
99 $objDefinition = $this->obj_definition;
102
103 $this->sub_objects = array();
104
105 $settings_map = [
106 'blog' => 'blogs',
107 'file' => 'files',
108 'webr' => 'links',
109 ];
110
111 $subtypes = $objDefinition->getCreatableSubObjects("wfld", ilObjectDefinition::MODE_WORKSPACE);
112 if (count($subtypes) > 0) {
113 foreach (array_keys($subtypes) as $type) {
114 if (isset($settings_map[$type]) &&
115 $ilSetting->get("disable_wsp_" . $settings_map[$type])) {
116 continue;
117 }
118
119 $this->sub_objects[] = array("type" => "object",
120 "value" => $type,
121 "title" => $lng->txt("wsp_type_" . $type));
122 }
123 }
124
125 $this->sub_objects = ilArrayUtil::sortArray($this->sub_objects, "title");
126
127 return (bool) sizeof($this->sub_objects);
128 }
129
133 protected function parseRepository(): bool
134 {
135 $objDefinition = $this->obj_definition;
137 $ilAccess = $this->access;
138
139 $this->sub_objects = array();
140
141 if (!is_array($this->disabled_object_types)) {
142 $this->disabled_object_types = array();
143 }
144 $this->disabled_object_types[] = "rolf";
145
146 $parent_type = ilObject::_lookupType($this->parent_ref_id, true);
147 $subtypes = $objDefinition->getCreatableSubObjects($parent_type, $this->mode, $this->parent_ref_id);
148 if (count($subtypes) > 0) {
149 // grouping of object types
150
151 $grp_map = $pos_group_map = array();
152
154
155 // no groups => use default
156 if (!$groups) {
158 $groups = $default["groups"];
159 $grp_map = $default["items"];
160
161 // reset positions (9999 = "other"/unassigned)
162 $pos = 0;
163 foreach ($subtypes as $item_type => $item) {
164 // see ilObjectDefinition
165 if (substr($item_type, 0, 1) == "x") {
166 $subtypes[$item_type]["pos"] = "99992000";
167 } else {
168 $subtypes[$item_type]["pos"] = "9999" . str_pad((string) ++$pos, 4, "0", STR_PAD_LEFT);
169 }
170 }
171
172 // assign default positions
173 foreach ($default["sort"] as $item_type => $pos) {
174 if (array_key_exists($item_type, $subtypes)) {
175 $subtypes[$item_type]["pos"] = $pos;
176 }
177 }
178
179 // sort by default positions
180 $subtypes = ilArrayUtil::sortArray($subtypes, "pos", "asc", true, true);
181 }
182 // use group assignment
183 else {
184 foreach (ilObjRepositorySettings::getNewItemGroupSubItems() as $grp_id => $subitems) {
185 foreach ($subitems as $subitem) {
186 $grp_map[$subitem] = $grp_id;
187 }
188 }
189 }
190
191 $group_separators = array();
192 $pos_group_map[0] = $lng->txt("rep_new_item_group_other");
193 $old_grp_ids = array();
194 foreach ($groups as $item) {
196 $pos_group_map[$item["id"]] = $item["title"];
197 } elseif (sizeof($old_grp_ids)) {
198 $group_separators[$item["id"]] = $old_grp_ids;
199 }
200 $old_grp_ids[] = $item["id"];
201 }
202
203 $current_grp = null;
204 foreach ($subtypes as $type => $subitem) {
205 if (!in_array($type, $this->disabled_object_types)) {
206 // #9950
207 if ($ilAccess->checkAccess("create_" . $type, "", $this->parent_ref_id, $parent_type)) {
208 // if only assigned - do not add groups
209 if (sizeof($pos_group_map) > 1) {
210 $obj_grp_id = 0;
211 if (array_key_exists($type, $grp_map)) {
212 $obj_grp_id = (int) $grp_map[$type];
213 }
214 if ($obj_grp_id !== $current_grp) {
215 // add seperator after last group?
216 $sdone = false;
217 foreach ($group_separators as $idx => $spath) {
218 // #11986 - all separators up to next group
219 if ($current_grp && !in_array($obj_grp_id, $spath)) {
220 // 1 only separator between groups
221 if (!$sdone) {
222 $this->sub_objects[] = array("type" => "column_separator");
223 $sdone = true;
224 }
225 unset($group_separators[$idx]);
226 }
227 }
228
229 $title = $pos_group_map[$obj_grp_id];
230
231 $this->sub_objects[] = array("type" => "group",
232 "title" => $title);
233
234 $current_grp = $obj_grp_id;
235 }
236 }
237
238 if (isset($subitem["plugin"]) && $subitem["plugin"]) {
239 $title = ilObjectPlugin::lookupTxtById($type, "obj_" . $type);
240 } else {
241 // #13088
242 $title = $lng->txt("obj_" . $type);
243 }
244
245 $this->sub_objects[] = array("type" => "object",
246 "value" => $type,
247 "title" => $title);
248 }
249 }
250 }
251 }
252
253 return (bool) sizeof($this->sub_objects);
254 }
255
259 protected function getHTML(): string
260 {
261 if ($this->mode != ilObjectDefinition::MODE_WORKSPACE && !isset($this->url_creation)) {
262 $base_url = "ilias.php?baseClass=ilRepositoryGUI&ref_id=" . $this->parent_ref_id . "&cmd=create";
263 } else {
264 $base_url = $this->url_creation;
265 }
266 // I removed the token statement because you can now
267 // generate links with ilCtrl::getLinkTargetByClass()
268 // which automatically appends one.
269
270 if ($this->url_creation_callback) {
271 $base_url .= "&crtcb=" . $this->url_creation_callback;
272 }
273
274 $gl = new ilGroupedListGUI("il-add-new-item-gl");
275 $gl->setAsDropDown(true);
276
277 foreach ($this->sub_objects as $item) {
278 switch ($item["type"]) {
279 case "column_separator":
280 $gl->nextColumn();
281 break;
282 case "group":
283 $gl->addGroupHeader($item["title"]);
284 break;
285 case "object":
286 $type = $item["value"];
287 $path = ilObject::_getIcon(0, 'tiny', $type);
288 $icon = ($path != "") ? ilUtil::img($path, "") . " " : "";
289 $url = $base_url . "&new_type=" . $type;
291 $gl->addEntry(
292 $icon . $item["title"],
293 $url,
294 "_top",
295 "",
296 "",
297 $type,
298 $ttip,
299 "bottom center",
300 "top center",
301 false
302 );
303
304 break;
305 }
306 }
307 $this->gl = $gl;
308
309 return $gl->getHTML();
310 }
311
315 public function render(): void
316 {
317 if ($this->mode == ilObjectDefinition::MODE_WORKSPACE) {
318 if (!$this->parsePersonalWorkspace()) {
319 return;
320 }
321 } elseif (!$this->parseRepository()) {
322 return;
323 }
324
325 $adv = new ilAdvancedSelectionListGUI();
326 $adv->setPullRight(false);
327 $adv->setListTitle($this->lng->txt("cntr_add_new_item"));
328 $this->getHTML();
329 $adv->setGroupedList($this->gl);
331 $this->toolbar->addStickyItem($adv);
332 }
333}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addGroupHeader(string $a_content, string $a_add_class="")
addEntry(string $a_content, string $a_href="", string $a_target="", string $a_onclick="", string $a_add_class="", string $a_id="", string $a_ttip="", string $a_tt_my="right center", string $a_tt_at="left center", bool $a_tt_use_htmlspecialchars=true)
setAsDropDown(bool $a_val, bool $a_pullright=false)
static getObjCreationTooltipText(string $a_type)
Get object_creation tooltip tab text.
language handling
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parsePersonalWorkspace()
Parse creatable sub objects for personal workspace.
setCreationUrl(string $url)
Set (custom) url for object creation.
render()
Add new item selection to current page incl.
setDisabledObjectTypes(array $types)
Set object types which may not be created.
ilGlobalTemplateInterface $tpl
setAfterCreationCallback(int $ref_id)
Set after creation callback.
parseRepository()
Parse creatable sub objects for repository incl.
getHTML()
Get rendered html of sub object list.
parses the objects.xml it handles the xml-description of all ilias objects
static lookupTxtById(string $plugin_id, string $lang_var)
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
$path
Definition: ltiservices.php:32
global $ilSetting
Definition: privfeed.php:17
$type
$url