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