ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilContainerContentGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
16 abstract class ilContainerContentGUI
17 {
19  const DETAILS_TITLE = 1;
20  const DETAILS_ALL = 2;
21 
23 
24  protected $renderer; // [ilContainerRenderer]
25 
28 
33  function __construct(&$container_gui_obj)
34  {
35  $this->container_gui = $container_gui_obj;
36  $this->container_obj = $this->container_gui->object;
37  }
38 
46  protected function getDetailsLevel($a_item_id)
47  {
48  return $this->details_level;
49  }
50 
56  public function getContainerObject()
57  {
58  return $this->container_obj;
59  }
60 
66  public function getContainerGUI()
67  {
68  return $this->container_gui;
69  }
70 
77  public function setOutput()
78  {
79  global $tpl, $ilCtrl;
80 
81  // note: we do not want to get the center html in case of
82  // asynchronous calls to blocks in the right column (e.g. news)
83  // see #13012
84  if ($ilCtrl->getNextClass() == "ilcolumngui" &&
85  $ilCtrl->isAsynch())
86  {
87  $tpl->setRightContent($this->getRightColumnHTML());
88  }
89 
90  // BEGIN ChangeEvent: record read event.
91  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
92  global $ilUser;
93 //global $log;
94 //$log->write("setOutput");
95 
96  $obj_id = ilObject::_lookupObjId($this->getContainerObject()->getRefId());
98  $this->getContainerObject()->getType(),
99  $this->getContainerObject()->getRefId(),
100  $obj_id, $ilUser->getId());
101  // END ChangeEvent: record read event.
102 
103 
104  $tpl->setContent($this->getCenterColumnHTML());
105 
106  // see above, all other cases (this was the old position of setRightContent,
107  // maybe the position above is ok and all ifs can be removed)
108  if ($ilCtrl->getNextClass() != "ilcolumngui" ||
109  !$ilCtrl->isAsynch())
110  {
111  $tpl->setRightContent($this->getRightColumnHTML());
112  }
113 
114  }
115 
119  protected function getRightColumnHTML()
120  {
121  global $ilUser, $lng, $ilCtrl, $ilAccess, $ilPluginAdmin;;
122 
123  $ilCtrl->saveParameterByClass("ilcolumngui", "col_return");
124 
125  $obj_id = ilObject::_lookupObjId($this->getContainerObject()->getRefId());
126  $obj_type = ilObject::_lookupType($obj_id);
127 
128  include_once("Services/Block/classes/class.ilColumnGUI.php");
129  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
130 
131  if ($column_gui->getScreenMode() == IL_SCREEN_FULL)
132  {
133  return "";
134  }
135 
136  $this->getContainerGUI()->setColumnSettings($column_gui);
137 
138  if ($ilCtrl->getNextClass() == "ilcolumngui" &&
139  $column_gui->getCmdSide() == IL_COL_RIGHT &&
140  $column_gui->getScreenMode() == IL_SCREEN_SIDE)
141  {
142 
143  $html = $ilCtrl->forwardCommand($column_gui);
144  }
145  else
146  {
147  if (!$ilCtrl->isAsynch())
148  {
149  $html = "";
150 
151  // user interface plugin slot + default rendering
152  include_once("./Services/UIComponent/classes/class.ilUIHookProcessor.php");
153  $uip = new ilUIHookProcessor("Services/Container", "right_column",
154  array("container_content_gui" => $this));
155  if (!$uip->replaced())
156  {
157  $html = $ilCtrl->getHTML($column_gui);
158  }
159  $html = $uip->getHTML($html);
160  }
161  }
162 
163  return $html;
164  }
165 
169  protected function getCenterColumnHTML()
170  {
171  global $ilCtrl, $tpl, $ilDB;
172 
173  $ilCtrl->saveParameterByClass("ilcolumngui", "col_return");
174 
175  $tpl->addOnLoadCode("il.Object.setRedrawListItemUrl('".
176  $ilCtrl->getLinkTarget($this->container_gui, "redrawListItem", "", true)."');");
177 
178  $tpl->addOnLoadCode("il.Object.setRatingUrl('".
179  $ilCtrl->getLinkTargetByClass(array(get_class($this->container_gui), "ilcommonactiondispatchergui", "ilratinggui"),
180  "saveRating", "", true, false)."');");
181 
182  switch ($ilCtrl->getNextClass())
183  {
184  case "ilcolumngui":
185  $ilCtrl->setReturn($this->container_gui, "");
186  $html = $this->__forwardToColumnGUI();
187  break;
188 
189  default:
190  $ilDB->useSlave(true);
191  $html = $this->getMainContent();
192  $ilDB->useSlave(false);
193  break;
194  }
195 
196  return $html;
197  }
198 
203  abstract function getMainContent();
204 
208  protected function initRenderer()
209  {
210  include_once('./Services/Container/classes/class.ilContainerSorting.php');
211  $sorting = ilContainerSorting::_getInstance($this->getContainerObject()->getId());
212 
213  include_once "Services/Container/classes/class.ilContainerRenderer.php";
214  $this->renderer = new ilContainerRenderer(
215  ($this->getContainerGUI()->isActiveAdministrationPanel() && !$_SESSION["clipboard"])
216  ,$this->getContainerGUI()->isMultiDownloadEnabled()
217  ,$this->getContainerGUI()->isActiveOrdering() && (get_class($this) != "ilContainerObjectiveGUI") // no block sorting in objective view
218  ,$sorting->getBlockPositions()
219  );
220  }
221 
225  final private function __forwardToColumnGUI()
226  {
227  global $ilCtrl, $ilAccess;
228 
229  include_once("Services/Block/classes/class.ilColumnGUI.php");
230 
231  // this gets us the subitems we need in setColumnSettings()
232  // todo: this should be done in ilCourseGUI->getSubItems
233 
234  $obj_id = ilObject::_lookupObjId($this->getContainerObject()->getRefId());
235  $obj_type = ilObject::_lookupType($obj_id);
236 
237  if (!$ilCtrl->isAsynch())
238  {
239  //if ($column_gui->getScreenMode() != IL_SCREEN_SIDE)
241  {
242  // right column wants center
244  {
245  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
246  $this->getContainerGUI()->setColumnSettings($column_gui);
247  $html = $ilCtrl->forwardCommand($column_gui);
248  }
249  // left column wants center
251  {
252  $column_gui = new ilColumnGUI($obj_type, IL_COL_LEFT);
253  $this->getContainerGUI()->setColumnSettings($column_gui);
254  $html = $ilCtrl->forwardCommand($column_gui);
255  }
256  }
257  else
258  {
259  $html = $this->getMainContent();
260  }
261  }
262 
263  return $html;
264  }
265 
269  protected function clearAdminCommandsDetermination()
270  {
271  $this->adminCommands = false;
272  }
273 
277  protected function determineAdminCommands($a_ref_id, $a_admin_com_included_in_list = false)
278  {
279  global $rbacsystem;
280 
281 //echo "-".$a_admin_com_included_in_list."-";
282 
283  if (!$this->adminCommands)
284  {
285  if (!$this->getContainerGUI()->isActiveAdministrationPanel())
286  {
287  if ($rbacsystem->checkAccess("delete", $a_ref_id))
288  {
289  $this->adminCommands = true;
290  }
291  }
292  else
293  {
294  $this->adminCommands = $a_admin_com_included_in_list;
295  }
296  }
297  }
298 
302  protected function getItemGUI($item_data,$a_show_path = false)
303  {
304  include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
305 
306  // get item list gui object
307  if (!is_object ($this->list_gui[$item_data["type"]]))
308  {
309  $item_list_gui =& ilObjectListGUIFactory::_getListGUIByType($item_data["type"]);
310  $item_list_gui->setContainerObject($this->getContainerGUI());
311  $this->list_gui[$item_data["type"]] =& $item_list_gui;
312  }
313  else
314  {
315  $item_list_gui =& $this->list_gui[$item_data["type"]];
316 
317  }
318 
319  // unique js-ids
320  $item_list_gui->setParentRefId($item_data["parent"]);
321 
322  $item_list_gui->setDefaultCommandParameters(array());
323  $item_list_gui->disableTitleLink(false);
324  $item_list_gui->resetConditionTarget();
325 
326  // show administration command buttons (or not)
327  if (!$this->getContainerGUI()->isActiveAdministrationPanel())
328  {
329 // $item_list_gui->enableDelete(false);
330 // $item_list_gui->enableLink(false);
331 // $item_list_gui->enableCut(false);
332  }
333 
334  // activate common social commands
335  $item_list_gui->enableComments(true);
336  $item_list_gui->enableNotes(true);
337  $item_list_gui->enableTags(true);
338  $item_list_gui->enableRating(true);
339 
340  // container specific modifications
341  $this->getContainerGUI()->modifyItemGUI($item_list_gui, $item_data, $a_show_path);
342 
343  return $item_list_gui;
344  }
345 
349  function determinePageEmbeddedBlocks($a_container_page_html)
350  {
351  $type_grps = $this->getGroupedObjTypes();
352 
353  // iterate all types
354  foreach ($type_grps as $type => $v)
355  {
356  // set template (overall or type specific)
357  if (is_int(strpos($a_container_page_html, "[list-".$type."]")))
358  {
359  $this->addEmbeddedBlock("type", $type);
360  }
361  }
362 
363  // determine item groups
364  while (eregi("\[(item-group-([0-9]*))\]", $a_container_page_html, $found))
365  {
366  $this->addEmbeddedBlock("itgr", (int) $found[2]);
367 
368  $a_container_page_html = eregi_replace("\[".$found[1]."\]", $html, $a_container_page_html);
369  }
370  }
371 
377  function addEmbeddedBlock($block_type, $block_parameter)
378  {
379  $this->embedded_block[$block_type][] = $block_parameter;
380  }
381 
385  function getEmbeddedBlocks()
386  {
387  return $this->embedded_block;
388  }
389 
394  {
395  global $lng;
396 
397  // item groups
398  if (is_array($this->embedded_block["itgr"]))
399  {
400  $item_groups = array();
401  if (is_array($this->items["itgr"]))
402  {
403  foreach ($this->items["itgr"] as $ig)
404  {
405  $item_groups[$ig["ref_id"]] = $ig;
406  }
407  }
408 
409  foreach ($this->embedded_block["itgr"] as $ref_id)
410  {
411  if(isset($item_groups[$ref_id]))
412  {
413  $this->renderItemGroup($item_groups[$ref_id]);
414  }
415  }
416  }
417 
418  // type specific blocks
419  if (is_array($this->embedded_block["type"]))
420  {
421  foreach ($this->embedded_block["type"] as $k => $type)
422  {
423  if (is_array($this->items[$type]) &&
424  $this->renderer->addTypeBlock($type))
425  {
426  // :TODO: obsolete?
427  if($type == 'sess')
428  {
429  $this->items['sess'] = ilUtil::sortArray($this->items['sess'],'start','ASC',true,true);
430  }
431 
432  $position = 1;
433 
434  foreach($this->items[$type] as $k => $item_data)
435  {
436  if(!$this->renderer->hasItem($item_data["child"]))
437  {
438  $html = $this->renderItem($item_data, $position++);
439  if ($html != "")
440  {
441  $this->renderer->addItemToBlock($type, $item_data["type"], $item_data["child"], $html);
442  }
443  }
444  }
445  }
446  }
447  }
448  }
449 
457  function renderItem($a_item_data,$a_position = 0,$a_force_icon = false, $a_pos_prefix = "")
458  {
459  global $ilSetting,$ilAccess,$ilCtrl;
460 
461  // Pass type, obj_id and tree to checkAccess method to improve performance
462  if(!$ilAccess->checkAccess('visible','',$a_item_data['ref_id'],$a_item_data['type'],$a_item_data['obj_id'],$a_item_data['tree']))
463  {
464  return '';
465  }
466 
467  $item_list_gui = $this->getItemGUI($a_item_data);
468  if ($ilSetting->get("icon_position_in_lists") == "item_rows" ||
469  $a_item_data["type"] == "sess" || $a_force_icon)
470  {
471  $item_list_gui->enableIcon(true);
472  }
473 
474  if ($this->getContainerGUI()->isActiveAdministrationPanel() && !$_SESSION["clipboard"])
475  {
476  $item_list_gui->enableCheckbox(true);
477  }
478  else if ($this->getContainerGUI()->isMultiDownloadEnabled())
479  {
480  // display multi download checkboxes
481  $item_list_gui->enableDownloadCheckbox($a_item_data["ref_id"], true);
482  }
483 
484  if ($this->getContainerGUI()->isActiveItemOrdering() && ($a_item_data['type'] != 'sess' || get_class($this) != 'ilContainerSessionsContentGUI'))
485  {
486  $item_list_gui->setPositionInputField($a_pos_prefix."[".$a_item_data["ref_id"]."]",
487  sprintf('%d', (int)$a_position*10));
488  }
489 
490  if($a_item_data['type'] == 'sess' and get_class($this) != 'ilContainerObjectiveGUI')
491  {
492  switch($this->getDetailsLevel($a_item_data['obj_id']))
493  {
494  case self::DETAILS_TITLE:
495  $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_MINIMAL);
496  $item_list_gui->enableExpand(true);
497  $item_list_gui->setExpanded(false);
498  $item_list_gui->enableDescription(false);
499  $item_list_gui->enableProperties(true);
500  break;
501 
502  case self::DETAILS_ALL:
503  $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_ALL);
504  $item_list_gui->enableExpand(true);
505  $item_list_gui->setExpanded(true);
506  $item_list_gui->enableDescription(true);
507  $item_list_gui->enableProperties(true);
508  break;
509 
510  default:
511  $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_ALL);
512  $item_list_gui->enableExpand(true);
513  $item_list_gui->enableDescription(true);
514  $item_list_gui->enableProperties(true);
515  break;
516  }
517  }
518 
519  if(method_exists($this, "addItemDetails"))
520  {
521  $this->addItemDetails($item_list_gui, $a_item_data);
522  }
523 
524  // show subitems
525  if($a_item_data['type'] == 'sess' and (
526  $this->getDetailsLevel($a_item_data['obj_id']) != self::DETAILS_TITLE or
527  $this->getContainerGUI()->isActiveAdministrationPanel() or
528  $this->getContainerGUI()->isActiveItemOrdering()
529  )
530  )
531  {
532  $pos = 1;
533 
534  include_once('./Services/Container/classes/class.ilContainerSorting.php');
535  include_once('./Services/Object/classes/class.ilObjectActivation.php');
536  $items = ilObjectActivation::getItemsByEvent($a_item_data['obj_id']);
537  $items = ilContainerSorting::_getInstance($this->getContainerObject()->getId())->sortSubItems('sess',$a_item_data['obj_id'],$items);
538  $items = ilContainer::getCompleteDescriptions($items);
539 
540  $item_readable = $ilAccess->checkAccess('read','',$a_item_data['ref_id']);
541 
542  foreach($items as $item)
543  {
544  // TODO: this should be removed and be handled by if(strlen($sub_item_html))
545  // see mantis: 0003944
546  if(!$ilAccess->checkAccess('visible','',$item['ref_id']))
547  {
548  continue;
549  }
550 
551  $item_list_gui2 = $this->getItemGUI($item);
552  $item_list_gui2->enableIcon(true);
553  $item_list_gui2->enableItemDetailLinks(false);
554 
555  // unique js-ids
556  $item_list_gui2->setParentRefId($a_item_data['ref_id']);
557 
558  // @see mantis 10488
559  if(!$item_readable and !$ilAccess->checkAccess('write','',$item['ref_id']))
560  {
561  $item_list_gui2->forceVisibleOnly(true);
562  }
563 
564  if ($this->getContainerGUI()->isActiveAdministrationPanel() && !$_SESSION["clipboard"])
565  {
566  $item_list_gui2->enableCheckbox(true);
567  }
568  else if ($this->getContainerGUI()->isMultiDownloadEnabled())
569  {
570  // display multi download checkbox
571  $item_list_gui2->enableDownloadCheckbox($item['ref_id'], true);
572  }
573 
574  if ($this->getContainerGUI()->isActiveItemOrdering())
575  {
576  $item_list_gui2->setPositionInputField("[sess][".$a_item_data['obj_id']."][".$item["ref_id"]."]",
577  sprintf('%d', (int)$pos*10));
578  $pos++;
579  }
580 
581  // #10611
582  ilObjectActivation::addListGUIActivationProperty($item_list_gui2, $item);
583 
584  $sub_item_html = $item_list_gui2->getListItemHTML($item['ref_id'],
585  $item['obj_id'], $item['title'], $item['description']);
586 
587  $this->determineAdminCommands($item["ref_id"],$item_list_gui2->adminCommandsIncluded());
588  if(strlen($sub_item_html))
589  {
590  $item_list_gui->addSubItemHTML($sub_item_html);
591  }
592  }
593  }
594 
595  if ($ilSetting->get("item_cmd_asynch"))
596  {
597  $asynch = true;
598  $ilCtrl->setParameter($this->container_gui, "cmdrefid", $a_item_data['ref_id']);
599  $asynch_url = $ilCtrl->getLinkTarget($this->container_gui,
600  "getAsynchItemList", "", true, false);
601  $ilCtrl->setParameter($this->container_gui, "cmdrefid", "");
602  }
603 
604  include_once "Services/Object/classes/class.ilObjectActivation.php";
605  ilObjectActivation::addListGUIActivationProperty($item_list_gui, $a_item_data);
606 
607  $html = $item_list_gui->getListItemHTML($a_item_data['ref_id'],
608  $a_item_data['obj_id'], $a_item_data['title'], $a_item_data['description'],
609  $asynch, false, $asynch_url);
610  $this->determineAdminCommands($a_item_data["ref_id"],
611  $item_list_gui->adminCommandsIncluded());
612 
613 
614  return $html;
615  }
616 
620  function insertPageEmbeddedBlocks($a_output_html)
621  {
622  $this->determinePageEmbeddedBlocks($a_output_html);
623  $this->renderPageEmbeddedBlocks($this->items);
624 
625  // iterate all types
626  foreach ($this->getGroupedObjTypes() as $type => $v)
627  {
628  // set template (overall or type specific)
629  if (is_int(strpos($a_output_html, "[list-".$type."]")))
630  {
631  $a_output_html = eregi_replace("\[list-".$type."\]",
632  $this->renderer->renderSingleTypeBlock($type), $a_output_html);
633  }
634  }
635 
636  // insert all item groups
637  while (eregi("\[(item-group-([0-9]*))\]", $a_output_html, $found))
638  {
639  $itgr_ref_id = (int) $found[2];
640 
641  $a_output_html = eregi_replace("\[".$found[1]."\]",
642  $this->renderer->renderSingleCustomBlock($itgr_ref_id), $a_output_html);
643  }
644 
645  return $a_output_html;
646  }
647 
654  {
655  global $objDefinition;
656 
657  if (empty($this->type_grps))
658  {
659  $this->type_grps =
660  $objDefinition->getGroupedRepositoryObjectTypes($this->getContainerObject()->getType());
661  }
662  return $this->type_grps;
663  }
664 
668  function getIntroduction()
669  {
670  global $ilUser, $lng, $ilCtrl;
671 
672  $lng->loadLanguageModule("rep");
673 
674  $tpl = new ilTemplate("tpl.rep_intro.html", true, true, "Services/Repository");
675  $tpl->setVariable("IMG_REP_LARGE", ilObject::_getIcon("", "big", "root"));
676  $tpl->setVariable("TXT_WELCOME", $lng->txt("rep_intro"));
677  $tpl->setVariable("TXT_INTRO_1", $lng->txt("rep_intro1"));
678  $tpl->setVariable("TXT_INTRO_2", $lng->txt("rep_intro2"));
679  $tpl->setVariable("TXT_INTRO_3", sprintf($lng->txt("rep_intro3"), $lng->txt("add")));
680  $tpl->setVariable("TXT_INTRO_4", sprintf($lng->txt("rep_intro4"), $lng->txt("cat_add")));
681  $tpl->setVariable("TXT_INTRO_5", $lng->txt("rep_intro5"));
682  $tpl->setVariable("TXT_INTRO_6", $lng->txt("rep_intro6"));
683 
684  return $tpl->get();
685  }
686 
693  function getItemGroupsHTML($a_pos = 0)
694  {
695  if (is_array($this->items["itgr"]))
696  {
697  foreach ($this->items["itgr"] as $itgr)
698  {
699  if (!$this->renderer->hasCustomBlock($itgr["child"]))
700  {
701  $this->renderItemGroup($itgr);
702 
703  $this->renderer->setBlockPosition($itgr["ref_id"], ++$a_pos);
704  }
705  }
706  }
707  return $a_pos;
708  }
709 
716  function renderItemGroup($a_itgr)
717  {
718  global $ilAccess;
719 
720  // #16493
721  $perm_ok = ($ilAccess->checkAccess("visible", "", $a_itgr['ref_id']) &&
722  $ilAccess->checkAccess("read", "", $a_itgr['ref_id']));
723 
724  include_once('./Services/Container/classes/class.ilContainerSorting.php');
725  include_once('./Services/Object/classes/class.ilObjectActivation.php');
726  $items = ilObjectActivation::getItemsByItemGroup($a_itgr['ref_id']);
727 
728  // if no permission is given, set the items to "rendered" but
729  // do not display the whole block
730  if (!$perm_ok)
731  {
732  foreach($items as $item)
733  {
734  $this->renderer->hideItem($item["child"]);
735  }
736  return;
737  }
738 
739  $item_list_gui = $this->getItemGUI($a_itgr);
740  $item_list_gui->enableNotes(false);
741  $item_list_gui->enableTags(false);
742  $item_list_gui->enableComments(false);
743  $item_list_gui->enableTimings(false);
744  $item_list_gui->getListItemHTML($a_itgr["ref_id"], $a_itgr["obj_id"],
745  $a_itgr["title"], $a_itgr["description"]);
746  $commands_html = $item_list_gui->getCommandsHTML();
747 
748  $this->renderer->addCustomBlock($a_itgr["ref_id"], $a_itgr["title"], $commands_html);
749 
750 
751  // render item group sub items
752 
754  $this->getContainerObject()->getId())->sortSubItems('itgr', $a_itgr['obj_id'], $items);
755 
756  // #18285
757  $items = ilContainer::getCompleteDescriptions($items);
758 
759  $position = 1;
760  foreach($items as $item)
761  {
762  $html2 = $this->renderItem($item, $position++, false, "[itgr][".$a_itgr['obj_id']."]");
763  if ($html2 != "")
764  {
765  // :TODO: show it multiple times?
766  $this->renderer->addItemToBlock($a_itgr["ref_id"], $item["type"], $item["child"], $html2, true);
767  }
768  }
769  }
770 }
771 
772 ?>