ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 */
3
13{
14 protected $mode; // [int]
15 protected $parent_ref_id; // [int]
16 protected $disabled_object_types; // [array]
17 protected $sub_objects; // [array]
18 protected $url_creation_callback; // [int]
19 protected $url_creation; // [string]
20
27 public function __construct($a_parent_ref_id)
28 {
29 global $lng;
30
31 $this->parent_ref_id = (int)$a_parent_ref_id;
33
34 $lng->loadLanguageModule("rep");
35 $lng->loadLanguageModule("cntr");
36 }
37
38 public function setMode($a_mode)
39 {
40 $this->mode = (int)$a_mode;
41 }
42
48 public function setDisabledObjectTypes(array $a_types)
49 {
50 $this->disabled_object_types = $a_types;
51 }
52
58 public function setAfterCreationCallback($a_ref_id)
59 {
60 $this->url_creation_callback = $a_ref_id;
61 }
62
68 public function setCreationUrl($a_url)
69 {
70 $this->url_creation = $a_url;
71 }
72
80 protected function parsePersonalWorkspace()
81 {
82 global $objDefinition, $lng, $ilSetting;
83
84 $this->sub_objects = array();
85
86 $settings_map = array("blog" => "blogs",
87 "file" => "files",
88 "tstv" => "certificates",
89 "excv" => "certificates",
90 "crsv" => "certificates",
91 "scov" => "certificates",
92 "webr" => "links");
93
94 $subtypes = $objDefinition->getCreatableSubObjects("wfld", ilObjectDefinition::MODE_WORKSPACE);
95 if (count($subtypes) > 0)
96 {
97 foreach (array_keys($subtypes) as $type)
98 {
99 if (isset($settings_map[$type]) &&
100 $ilSetting->get("disable_wsp_".$settings_map[$type]))
101 {
102 continue;
103 }
104
105 $this->sub_objects[] = array("type" => "object",
106 "value" => $type,
107 "title" => $lng->txt("wsp_type_".$type));
108 }
109 }
110
111 $this->sub_objects = ilUtil::sortArray($this->sub_objects, "title", 1);
112
113 return (bool)sizeof($this->sub_objects);
114 }
115
121 protected function parseRepository()
122 {
123 global $objDefinition, $lng, $ilAccess;
124
125 $this->sub_objects = array();
126
127 if(!is_array($this->disabled_object_types))
128 {
129 $this->disabled_object_types = array();
130 }
131 $this->disabled_object_types[] = "rolf";
132
133 $parent_type = ilObject::_lookupType($this->parent_ref_id, true);
134 $subtypes = $objDefinition->getCreatableSubObjects($parent_type, $this->mode, $this->parent_ref_id);
135 if (count($subtypes) > 0)
136 {
137 // grouping of object types
138
139 $grp_map = $pos_group_map = array();
140
141 include_once("Services/Repository/classes/class.ilObjRepositorySettings.php");
143
144 // no groups => use default
145 if(!$groups)
146 {
148 $groups = $default["groups"];
149 $grp_map = $default["items"];
150
151 // reset positions (9999 = "other"/unassigned)
152 $pos = 0;
153 foreach($subtypes as $item_type => $item)
154 {
155 // see ilObjectDefinition
156 if(substr($item_type, 0, 1) == "x")
157 {
158 $subtypes[$item_type]["pos"] = "99992000";
159 }
160 else
161 {
162 $subtypes[$item_type]["pos"] = "9999".str_pad(++$pos, 4, "0", STR_PAD_LEFT);
163 }
164 }
165
166 // assign default positions
167 foreach($default["sort"] as $item_type => $pos)
168 {
169 if(array_key_exists($item_type, $subtypes))
170 {
171 $subtypes[$item_type]["pos"] = $pos;
172 }
173 }
174
175 // sort by default positions
176 $subtypes = ilUtil::sortArray($subtypes, "pos", "asc", true, true);
177 }
178 // use group assignment
179 else
180 {
181 foreach(ilObjRepositorySettings::getNewItemGroupSubItems() as $grp_id => $subitems)
182 {
183 foreach($subitems as $subitem)
184 {
185 $grp_map[$subitem] = $grp_id;
186 }
187 }
188 }
189
190 $group_separators = array();
191 $pos_group_map[0] = $lng->txt("rep_new_item_group_other");
192 $old_grp_ids = array();
193 foreach($groups as $item)
194 {
196 {
197 $pos_group_map[$item["id"]] = $item["title"];
198 }
199 else if(sizeof($old_grp_ids))
200 {
201 $group_separators[$item["id"]] = $old_grp_ids;
202 }
203 $old_grp_ids[] = $item["id"];
204 }
205
206 $current_grp = null;
207 foreach ($subtypes as $type => $subitem)
208 {
209 if (!in_array($type, $this->disabled_object_types))
210 {
211 // #9950
212 if ($ilAccess->checkAccess("create_".$type, "", $this->parent_ref_id, $parent_type))
213 {
214 // if only assigned - do not add groups
215 if(sizeof($pos_group_map) > 1)
216 {
217 $obj_grp_id = (int)$grp_map[$type];
218 if($obj_grp_id !== $current_grp)
219 {
220 // add seperator after last group?
221 $sdone = false;
222 foreach($group_separators as $idx => $spath)
223 {
224 // #11986 - all separators up to next group
225 if($current_grp && !in_array($obj_grp_id, $spath))
226 {
227 // 1 only separator between groups
228 if(!$sdone)
229 {
230 $this->sub_objects[] = array("type" => "column_separator");
231 $sdone = true;
232 }
233 unset($group_separators[$idx]);
234 }
235 }
236
237 $title = $pos_group_map[$obj_grp_id];
238
239 $this->sub_objects[] = array("type" => "group",
240 "title" => $title);
241
242 $current_grp = $obj_grp_id;
243 }
244 }
245
246 if ($subitem["plugin"])
247 {
248 include_once("./Services/Component/classes/class.ilPlugin.php");
249 $title = ilPlugin::lookupTxt("rep_robj", $type, "obj_".$type);
250 }
251 else
252 {
253 // #13088
254 $title = $lng->txt("obj_".$type);
255 }
256
257 $this->sub_objects[] = array("type" => "object",
258 "value" => $type,
259 "title" => $title);
260 }
261 }
262 }
263 }
264
265 return (bool)sizeof($this->sub_objects);
266 }
267
273 protected function getHTML()
274 {
275 global $ilCtrl;
276
277 if($this->mode != ilObjectDefinition::MODE_WORKSPACE && !isset($this->url_creation))
278 {
279 $base_url = "ilias.php?baseClass=ilRepositoryGUI&ref_id=".$this->parent_ref_id."&cmd=create";
280 }
281 else
282 {
283 $base_url = $this->url_creation;
284 }
285 $base_url = $ilCtrl->appendRequestTokenParameterString($base_url);
286
287 if($this->url_creation_callback)
288 {
289 $base_url .= "&crtcb=".$this->url_creation_callback;
290 }
291
292 include_once("./Services/UIComponent/GroupedList/classes/class.ilGroupedListGUI.php");
293 $gl = new ilGroupedListGUI();
294 $gl->setAsDropDown(true, true);
295
296 foreach ($this->sub_objects as $item)
297 {
298 switch($item["type"])
299 {
300 case "column_separator":
301 $gl->nextColumn();
302 break;
303
304 /*
305 case "separator":
306 $gl->addSeparator();
307 break;
308 */
309
310 case "group":
311 $gl->addGroupHeader($item["title"]);
312 break;
313
314 case "object":
315 $type = $item["value"];
316
317 $path = ilObject::_getIcon('', 'tiny', $type);
318 $icon = ($path != "")
319 ? ilUtil::img($path)." "
320 : "";
321
322 $url = $base_url . "&new_type=".$type;
323
325
326 $gl->addEntry($icon.$item["title"], $url, "_top", "", "",
327 $type, $ttip, "bottom center", "top center", false);
328
329 break;
330 }
331 }
332 $this->gl = $gl;
333
334 return $gl->getHTML();
335 }
336
340 public function render()
341 {
342 global $ilToolbar, $tpl, $lng;
343
344 if($this->mode == ilObjectDefinition::MODE_WORKSPACE)
345 {
346 if (!$this->parsePersonalWorkspace())
347 {
348 return;
349 }
350 }
351 else if(!$this->parseRepository())
352 {
353 return;
354 }
355
356 $ov_id = "il_add_new_item_ov";
357 $ov_trigger_id = $ov_id."_tr";
358
359
360 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
361 $adv = new ilAdvancedSelectionListGUI();
362 $adv->setListTitle($lng->txt("cntr_add_new_item"));
363 $this->getHTML();
364 $adv->setGroupedList($this->gl);
366 $tpl->setVariable("SELECT_OBJTYPE_REPOS", $adv->getHTML());
367 //$ilToolbar->addDropDown($lng->txt("cntr_add_new_item"), $this->getHTML());
368
369 return;
370
371 // toolbar
372 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
373 $button = ilLinkButton::getInstance();
374 $button->setId($ov_trigger_id);
375 $button->setCaption("cntr_add_new_item");
376 $button->setPrimary(true);
377 $ilToolbar->addButtonInstance($button);
378
379 // css?
380 $tpl->setVariable("SELECT_OBJTYPE_REPOS",
381 '<div id="'.$ov_id.'" style="display:none;" class="ilOverlay">'.
382 $this->getHTML().'</div>');
383 }
384}
385
386?>
global $tpl
Definition: ilias.php:8
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 _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 lookupTxt($a_mod_prefix, $a_pl_id, $a_lang_var)
Lookup language text.
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 $lng
Definition: privfeed.php:40
global $ilSetting
Definition: privfeed.php:40
$url
Definition: shib_logout.php:72
$path
Definition: index.php:22