ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 = array("blog" => "blogs",
134 "file" => "files",
135 "tstv" => "certificates",
136 "excv" => "certificates",
137 "crsv" => "certificates",
138 "scov" => "certificates",
139 "webr" => "links");
140
141 $subtypes = $objDefinition->getCreatableSubObjects("wfld", ilObjectDefinition::MODE_WORKSPACE);
142 if (count($subtypes) > 0) {
143 foreach (array_keys($subtypes) as $type) {
144 if (isset($settings_map[$type]) &&
145 $ilSetting->get("disable_wsp_" . $settings_map[$type])) {
146 continue;
147 }
148
149 $this->sub_objects[] = array("type" => "object",
150 "value" => $type,
151 "title" => $lng->txt("wsp_type_" . $type));
152 }
153 }
154
155 $this->sub_objects = ilUtil::sortArray($this->sub_objects, "title", 1);
156
157 return (bool) sizeof($this->sub_objects);
158 }
159
165 protected function parseRepository()
166 {
167 $objDefinition = $this->obj_definition;
169 $ilAccess = $this->access;
170
171 $this->sub_objects = array();
172
173 if (!is_array($this->disabled_object_types)) {
174 $this->disabled_object_types = array();
175 }
176 $this->disabled_object_types[] = "rolf";
177
178 $parent_type = ilObject::_lookupType($this->parent_ref_id, true);
179 $subtypes = $objDefinition->getCreatableSubObjects($parent_type, $this->mode, $this->parent_ref_id);
180 if (count($subtypes) > 0) {
181 // grouping of object types
182
183 $grp_map = $pos_group_map = array();
184
185 include_once("Services/Repository/classes/class.ilObjRepositorySettings.php");
187
188 // no groups => use default
189 if (!$groups) {
191 $groups = $default["groups"];
192 $grp_map = $default["items"];
193
194 // reset positions (9999 = "other"/unassigned)
195 $pos = 0;
196 foreach ($subtypes as $item_type => $item) {
197 // see ilObjectDefinition
198 if (substr($item_type, 0, 1) == "x") {
199 $subtypes[$item_type]["pos"] = "99992000";
200 } else {
201 $subtypes[$item_type]["pos"] = "9999" . str_pad(++$pos, 4, "0", STR_PAD_LEFT);
202 }
203 }
204
205 // assign default positions
206 foreach ($default["sort"] as $item_type => $pos) {
207 if (array_key_exists($item_type, $subtypes)) {
208 $subtypes[$item_type]["pos"] = $pos;
209 }
210 }
211
212 // sort by default positions
213 $subtypes = ilUtil::sortArray($subtypes, "pos", "asc", true, true);
214 }
215 // use group assignment
216 else {
217 foreach (ilObjRepositorySettings::getNewItemGroupSubItems() as $grp_id => $subitems) {
218 foreach ($subitems as $subitem) {
219 $grp_map[$subitem] = $grp_id;
220 }
221 }
222 }
223
224 $group_separators = array();
225 $pos_group_map[0] = $lng->txt("rep_new_item_group_other");
226 $old_grp_ids = array();
227 foreach ($groups as $item) {
229 $pos_group_map[$item["id"]] = $item["title"];
230 } elseif (sizeof($old_grp_ids)) {
231 $group_separators[$item["id"]] = $old_grp_ids;
232 }
233 $old_grp_ids[] = $item["id"];
234 }
235
236 $current_grp = null;
237 foreach ($subtypes as $type => $subitem) {
238 if (!in_array($type, $this->disabled_object_types)) {
239 // #9950
240 if ($ilAccess->checkAccess("create_" . $type, "", $this->parent_ref_id, $parent_type)) {
241 // if only assigned - do not add groups
242 if (sizeof($pos_group_map) > 1) {
243 $obj_grp_id = (int) $grp_map[$type];
244 if ($obj_grp_id !== $current_grp) {
245 // add seperator after last group?
246 $sdone = false;
247 foreach ($group_separators as $idx => $spath) {
248 // #11986 - all separators up to next group
249 if ($current_grp && !in_array($obj_grp_id, $spath)) {
250 // 1 only separator between groups
251 if (!$sdone) {
252 $this->sub_objects[] = array("type" => "column_separator");
253 $sdone = true;
254 }
255 unset($group_separators[$idx]);
256 }
257 }
258
259 $title = $pos_group_map[$obj_grp_id];
260
261 $this->sub_objects[] = array("type" => "group",
262 "title" => $title);
263
264 $current_grp = $obj_grp_id;
265 }
266 }
267
268 if ($subitem["plugin"]) {
269 include_once("./Services/Component/classes/class.ilPlugin.php");
271 } else {
272 // #13088
273 $title = $lng->txt("obj_" . $type);
274 }
275
276 $this->sub_objects[] = array("type" => "object",
277 "value" => $type,
278 "title" => $title);
279 }
280 }
281 }
282 }
283
284 return (bool) sizeof($this->sub_objects);
285 }
286
292 protected function getHTML()
293 {
295
296 if ($this->mode != ilObjectDefinition::MODE_WORKSPACE && !isset($this->url_creation)) {
297 $base_url = "ilias.php?baseClass=ilRepositoryGUI&ref_id=" . $this->parent_ref_id . "&cmd=create";
298 } else {
299 $base_url = $this->url_creation;
300 }
301 $base_url = $ilCtrl->appendRequestTokenParameterString($base_url);
302
303 if ($this->url_creation_callback) {
304 $base_url .= "&crtcb=" . $this->url_creation_callback;
305 }
306
307 include_once("./Services/UIComponent/GroupedList/classes/class.ilGroupedListGUI.php");
308 $gl = new ilGroupedListGUI();
309 $gl->setAsDropDown(true, true);
310
311 foreach ($this->sub_objects as $item) {
312 switch ($item["type"]) {
313 case "column_separator":
314 $gl->nextColumn();
315 break;
316
317 /*
318 case "separator":
319 $gl->addSeparator();
320 break;
321 */
322
323 case "group":
324 $gl->addGroupHeader($item["title"]);
325 break;
326
327 case "object":
328 $type = $item["value"];
329
330 $path = ilObject::_getIcon('', 'tiny', $type);
331 $icon = ($path != "")
332 ? ilUtil::img($path) . " "
333 : "";
334
335 $url = $base_url . "&new_type=" . $type;
336
338
339 $gl->addEntry(
340 $icon . $item["title"],
341 $url,
342 "_top",
343 "",
344 "",
345 $type,
346 $ttip,
347 "bottom center",
348 "top center",
349 false
350 );
351
352 break;
353 }
354 }
355 $this->gl = $gl;
356
357 return $gl->getHTML();
358 }
359
363 public function render()
364 {
365 $ilToolbar = $this->toolbar;
368
369 if ($this->mode == ilObjectDefinition::MODE_WORKSPACE) {
370 if (!$this->parsePersonalWorkspace()) {
371 return;
372 }
373 } elseif (!$this->parseRepository()) {
374 return;
375 }
376
377 $ov_id = "il_add_new_item_ov";
378 $ov_trigger_id = $ov_id . "_tr";
379
380
381 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
382 $adv = new ilAdvancedSelectionListGUI();
383 $adv->setListTitle($lng->txt("cntr_add_new_item"));
384 $this->getHTML();
385 $adv->setGroupedList($this->gl);
387 $tpl->setVariable("SELECT_OBJTYPE_REPOS", $adv->getHTML());
388 //$ilToolbar->addDropDown($lng->txt("cntr_add_new_item"), $this->getHTML());
389
390 return;
391
392 // toolbar
393 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
394 $button = ilLinkButton::getInstance();
395 $button->setId($ov_trigger_id);
396 $button->setCaption("cntr_add_new_item");
397 $button->setPrimary(true);
398 $ilToolbar->addButtonInstance($button);
399
400 // css?
401 $tpl->setVariable(
402 "SELECT_OBJTYPE_REPOS",
403 '<div id="' . $ov_id . '" style="display:none;" class="ilOverlay">' .
404 $this->getHTML() . '</div>'
405 );
406 }
407}
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.
static getInstance()
Factory.
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="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
$type
$url
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2