ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjectAddNewItemGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3require_once('./Services/Repository/classes/class.ilObjectPlugin.php');
4
14{
18 protected $lng;
19
23 protected $obj_definition;
24
28 protected $settings;
29
33 protected $access;
34
38 protected $ctrl;
39
43 protected $toolbar;
44
48 protected $tpl;
49
50 protected $mode; // [int]
51 protected $parent_ref_id; // [int]
52 protected $disabled_object_types; // [array]
53 protected $sub_objects; // [array]
54 protected $url_creation_callback; // [int]
55 protected $url_creation; // [string]
56
63 public function __construct($a_parent_ref_id)
64 {
65 global $DIC;
66
67 $this->lng = $DIC->language();
68 $this->obj_definition = $DIC["objDefinition"];
69 $this->settings = $DIC->settings();
70 $this->access = $DIC->access();
71 $this->ctrl = $DIC->ctrl();
72 $this->toolbar = $DIC->toolbar();
73 $this->tpl = $DIC["tpl"];
74 $lng = $DIC->language();
75
76 $this->parent_ref_id = (int) $a_parent_ref_id;
78
79 $lng->loadLanguageModule("rep");
80 $lng->loadLanguageModule("cntr");
81 }
82
83 public function setMode($a_mode)
84 {
85 $this->mode = (int) $a_mode;
86 }
87
93 public function setDisabledObjectTypes(array $a_types)
94 {
95 $this->disabled_object_types = $a_types;
96 }
97
103 public function setAfterCreationCallback($a_ref_id)
104 {
105 $this->url_creation_callback = $a_ref_id;
106 }
107
113 public function setCreationUrl($a_url)
114 {
115 $this->url_creation = $a_url;
116 }
117
125 protected function parsePersonalWorkspace()
126 {
127 $objDefinition = $this->obj_definition;
130
131 $this->sub_objects = array();
132
133 $settings_map = [
134 'blog' => 'blogs',
135 'file' => 'files',
136 'webr' => 'links',
137 ];
138
139 $subtypes = $objDefinition->getCreatableSubObjects("wfld", ilObjectDefinition::MODE_WORKSPACE);
140 if (count($subtypes) > 0) {
141 foreach (array_keys($subtypes) as $type) {
142 if (isset($settings_map[$type]) &&
143 $ilSetting->get("disable_wsp_" . $settings_map[$type])) {
144 continue;
145 }
146
147 $this->sub_objects[] = array("type" => "object",
148 "value" => $type,
149 "title" => $lng->txt("wsp_type_" . $type));
150 }
151 }
152
153 $this->sub_objects = ilUtil::sortArray($this->sub_objects, "title", 1);
154
155 return (bool) sizeof($this->sub_objects);
156 }
157
163 protected function parseRepository()
164 {
165 $objDefinition = $this->obj_definition;
167 $ilAccess = $this->access;
168
169 $this->sub_objects = array();
170
171 if (!is_array($this->disabled_object_types)) {
172 $this->disabled_object_types = array();
173 }
174 $this->disabled_object_types[] = "rolf";
175
176 $parent_type = ilObject::_lookupType($this->parent_ref_id, true);
177 $subtypes = $objDefinition->getCreatableSubObjects($parent_type, $this->mode, $this->parent_ref_id);
178 if (count($subtypes) > 0) {
179 // grouping of object types
180
181 $grp_map = $pos_group_map = array();
182
183 include_once("Services/Repository/classes/class.ilObjRepositorySettings.php");
185
186 // no groups => use default
187 if (!$groups) {
189 $groups = $default["groups"];
190 $grp_map = $default["items"];
191
192 // reset positions (9999 = "other"/unassigned)
193 $pos = 0;
194 foreach ($subtypes as $item_type => $item) {
195 // see ilObjectDefinition
196 if (substr($item_type, 0, 1) == "x") {
197 $subtypes[$item_type]["pos"] = "99992000";
198 } else {
199 $subtypes[$item_type]["pos"] = "9999" . str_pad(++$pos, 4, "0", STR_PAD_LEFT);
200 }
201 }
202
203 // assign default positions
204 foreach ($default["sort"] as $item_type => $pos) {
205 if (array_key_exists($item_type, $subtypes)) {
206 $subtypes[$item_type]["pos"] = $pos;
207 }
208 }
209
210 // sort by default positions
211 $subtypes = ilUtil::sortArray($subtypes, "pos", "asc", true, true);
212 }
213 // use group assignment
214 else {
215 foreach (ilObjRepositorySettings::getNewItemGroupSubItems() as $grp_id => $subitems) {
216 foreach ($subitems as $subitem) {
217 $grp_map[$subitem] = $grp_id;
218 }
219 }
220 }
221
222 $group_separators = array();
223 $pos_group_map[0] = $lng->txt("rep_new_item_group_other");
224 $old_grp_ids = array();
225 foreach ($groups as $item) {
227 $pos_group_map[$item["id"]] = $item["title"];
228 } elseif (sizeof($old_grp_ids)) {
229 $group_separators[$item["id"]] = $old_grp_ids;
230 }
231 $old_grp_ids[] = $item["id"];
232 }
233
234 $current_grp = null;
235 foreach ($subtypes as $type => $subitem) {
236 if (!in_array($type, $this->disabled_object_types)) {
237 // #9950
238 if ($ilAccess->checkAccess("create_" . $type, "", $this->parent_ref_id, $parent_type)) {
239 // if only assigned - do not add groups
240 if (sizeof($pos_group_map) > 1) {
241 $obj_grp_id = (int) $grp_map[$type];
242 if ($obj_grp_id !== $current_grp) {
243 // add seperator after last group?
244 $sdone = false;
245 foreach ($group_separators as $idx => $spath) {
246 // #11986 - all separators up to next group
247 if ($current_grp && !in_array($obj_grp_id, $spath)) {
248 // 1 only separator between groups
249 if (!$sdone) {
250 $this->sub_objects[] = array("type" => "column_separator");
251 $sdone = true;
252 }
253 unset($group_separators[$idx]);
254 }
255 }
256
257 $title = $pos_group_map[$obj_grp_id];
258
259 $this->sub_objects[] = array("type" => "group",
260 "title" => $title);
261
262 $current_grp = $obj_grp_id;
263 }
264 }
265
266 if ($subitem["plugin"]) {
267 include_once("./Services/Component/classes/class.ilPlugin.php");
268 $title = ilObjectPlugin::lookupTxtById($type, "obj_" . $type);
269 } else {
270 // #13088
271 $title = $lng->txt("obj_" . $type);
272 }
273
274 $this->sub_objects[] = array("type" => "object",
275 "value" => $type,
276 "title" => $title);
277 }
278 }
279 }
280 }
281
282 return (bool) sizeof($this->sub_objects);
283 }
284
290 protected function getHTML()
291 {
292 $ilCtrl = $this->ctrl;
293
294 if ($this->mode != ilObjectDefinition::MODE_WORKSPACE && !isset($this->url_creation)) {
295 $base_url = "ilias.php?baseClass=ilRepositoryGUI&ref_id=" . $this->parent_ref_id . "&cmd=create";
296 } else {
297 $base_url = $this->url_creation;
298 }
299 $base_url = $ilCtrl->appendRequestTokenParameterString($base_url);
300
301 if ($this->url_creation_callback) {
302 $base_url .= "&crtcb=" . $this->url_creation_callback;
303 }
304
305 include_once("./Services/UIComponent/GroupedList/classes/class.ilGroupedListGUI.php");
306 $gl = new ilGroupedListGUI("il-add-new-item-gl");
307 $gl->setAsDropDown(true, false);
308
309 foreach ($this->sub_objects as $item) {
310 switch ($item["type"]) {
311 case "column_separator":
312 $gl->nextColumn();
313 break;
314
315 /*
316 case "separator":
317 $gl->addSeparator();
318 break;
319 */
320
321 case "group":
322 $gl->addGroupHeader($item["title"]);
323 break;
324
325 case "object":
326 $type = $item["value"];
327
328 $path = ilObject::_getIcon('', 'tiny', $type);
329 $icon = ($path != "")
330 ? ilUtil::img($path, "") . " "
331 : "";
332
333 $url = $base_url . "&new_type=" . $type;
334
336
337 $gl->addEntry(
338 $icon . $item["title"],
339 $url,
340 "_top",
341 "",
342 "",
343 $type,
344 $ttip,
345 "bottom center",
346 "top center",
347 false
348 );
349
350 break;
351 }
352 }
353 $this->gl = $gl;
354
355 return $gl->getHTML();
356 }
357
361 public function render()
362 {
363 $ilToolbar = $this->toolbar;
366
367 if ($this->mode == ilObjectDefinition::MODE_WORKSPACE) {
368 if (!$this->parsePersonalWorkspace()) {
369 return;
370 }
371 } elseif (!$this->parseRepository()) {
372 return;
373 }
374
375 $ov_id = "il_add_new_item_ov";
376 $ov_trigger_id = $ov_id . "_tr";
377
378
379 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
380 $adv = new ilAdvancedSelectionListGUI();
381 $adv->setPullRight(false);
382 $adv->setListTitle($lng->txt("cntr_add_new_item"));
383 $this->getHTML();
384 $adv->setGroupedList($this->gl);
386 //$ilToolbar->addAdvancedSelectionList($adv);
387 $ilToolbar->addStickyItem($adv);
388 //$tpl->setVariable("SELECT_OBJTYPE_REPOS", $adv->getHTML());
389 }
390}
An exception for terminatinating execution or to throw for unit testing.
User interface class for advanced drop-down selection lists.
Grouped list GUI class.
static getObjCreationTooltipText($a_type)
Get object_creation tooltip tab text.
Render add new item selector.
parsePersonalWorkspace()
Parse creatable sub objects for personal workspace.
render()
Add new item selection to current page incl.
setDisabledObjectTypes(array $a_types)
Set object types which may not be created.
setCreationUrl($a_url)
Set (custom) url for object creation.
parseRepository()
Parse creatable sub objects for repository incl.
getHTML()
Get rendered html of sub object list.
__construct($a_parent_ref_id)
Constructor.
setAfterCreationCallback($a_ref_id)
Set after creation callback.
static lookupTxtById($plugin_id, $lang_var)
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
global $DIC
Definition: goto.php:24
global $ilSetting
Definition: privfeed.php:17
$type
$url
settings()
Definition: settings.php:2