ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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);
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 
295  foreach ($this->sub_objects as $item)
296  {
297  switch($item["type"])
298  {
299  case "column_separator":
300  $gl->nextColumn();
301  break;
302 
303  /*
304  case "separator":
305  $gl->addSeparator();
306  break;
307  */
308 
309  case "group":
310  $gl->addGroupHeader($item["title"]);
311  break;
312 
313  case "object":
314  $type = $item["value"];
315 
316  $path = ilObject::_getIcon('', 'tiny', $type);
317  $icon = ($path != "")
318  ? ilUtil::img($path)." "
319  : "";
320 
321  $url = $base_url . "&new_type=".$type;
322 
323  $ttip = ilHelp::getObjCreationTooltipText($type);
324 
325  $gl->addEntry($icon.$item["title"], $url, "_top", "", "",
326  $type, $ttip, "bottom center", "top center", false);
327 
328  break;
329  }
330  }
331 
332  return $gl->getHTML();
333  }
334 
338  public function render()
339  {
340  global $ilToolbar, $tpl, $lng;
341 
342  if($this->mode == ilObjectDefinition::MODE_WORKSPACE)
343  {
344  if (!$this->parsePersonalWorkspace())
345  {
346  return;
347  }
348  }
349  else if(!$this->parseRepository())
350  {
351  return;
352  }
353 
354  $ov_id = "il_add_new_item_ov";
355  $ov_trigger_id = $ov_id."_tr";
356 
357  include_once "Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php";
358  $ov = new ilOverlayGUI($ov_id);
359 // $ov->setAnchor($ov_trigger_id, "tl", "tr");
360 // $ov->setTrigger($ov_trigger_id, "click", $ov_trigger_id);
361  $ov->add();
362 
363  // trigger
364  $ov->addTrigger($ov_trigger_id, "click", $ov_trigger_id, false, "tl", "tr");
365 
366  // toolbar
367  $ilToolbar->addButton($lng->txt("cntr_add_new_item"), "#", "", "",
368  "", $ov_trigger_id, 'submit emphsubmit');
369 
370  // css?
371  $tpl->setVariable("SELECT_OBJTYPE_REPOS",
372  '<div id="'.$ov_id.'" style="display:none;" class="ilOverlay">'.
373  $this->getHTML().'</div>');
374  }
375 }
376 
377 ?>