ILIAS  eassessment Revision 61809
 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 
22 
24 
27 
32  function __construct(&$container_gui_obj)
33  {
34  $this->container_gui = $container_gui_obj;
35  $this->container_obj = $this->container_gui->object;
36  }
37 
45  protected function getDetailsLevel($a_item_id)
46  {
47  return $this->details_level;
48  }
49 
55  public function getContainerObject()
56  {
57  return $this->container_obj;
58  }
59 
65  public function getContainerGUI()
66  {
67  return $this->container_gui;
68  }
69 
76  public function setOutput()
77  {
78  global $tpl;
79 
80  // BEGIN ChangeEvent: record read event.
81  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
83  {
84  global $ilUser;
85  $obj_id = ilObject::_lookupObjId($this->getContainerObject()->getRefId());
87  $this->getContainerObject()->getType(),
88  $this->getContainerObject()->getRefId(),
89  $obj_id, $ilUser->getId());
90  }
91  // END ChangeEvent: record read event.
92 
93  $tpl->setContent($this->getCenterColumnHTML());
94  $tpl->setRightContent($this->getRightColumnHTML());
95  }
96 
100  protected function getRightColumnHTML()
101  {
102  global $ilUser, $lng, $ilCtrl, $ilAccess;
103 
104  $ilCtrl->saveParameterByClass("ilcolumngui", "col_return");
105 
106  $obj_id = ilObject::_lookupObjId($this->getContainerObject()->getRefId());
107  $obj_type = ilObject::_lookupType($obj_id);
108 
109  include_once("Services/Block/classes/class.ilColumnGUI.php");
110  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
111 
112  if ($column_gui->getScreenMode() == IL_SCREEN_FULL)
113  {
114  return "";
115  }
116 
117  $this->getContainerGUI()->setColumnSettings($column_gui);
118 
119  if ($ilCtrl->getNextClass() == "ilcolumngui" &&
120  $column_gui->getCmdSide() == IL_COL_RIGHT &&
121  $column_gui->getScreenMode() == IL_SCREEN_SIDE)
122  {
123 
124  $html = $ilCtrl->forwardCommand($column_gui);
125  }
126  else
127  {
128  if (!$ilCtrl->isAsynch())
129  {
130  $html = $ilCtrl->getHTML($column_gui);
131  }
132  }
133 
134  return $html;
135  }
136 
140  protected function getCenterColumnHTML()
141  {
142  global $ilCtrl, $tpl;
143 
144  $ilCtrl->saveParameterByClass("ilcolumngui", "col_return");
145 
146  switch ($ilCtrl->getNextClass())
147  {
148  case "ilcolumngui":
149  $ilCtrl->setReturn($this->container_gui, "");
150  $html = $this->__forwardToColumnGUI();
151  break;
152 
153  default:
154  $html = $this->getMainContent();
155  break;
156  }
157 
158  return $html;
159  }
160 
165  abstract function getMainContent();
166 
170  final private function __forwardToColumnGUI()
171  {
172  global $ilCtrl, $ilAccess;
173 
174  include_once("Services/Block/classes/class.ilColumnGUI.php");
175 
176  // this gets us the subitems we need in setColumnSettings()
177  // todo: this should be done in ilCourseGUI->getSubItems
178  //$this->course_obj->initCourseItemObject($this->getContainerObject()->getRefId());
179 
180  $obj_id = ilObject::_lookupObjId($this->getContainerObject()->getRefId());
181  $obj_type = ilObject::_lookupType($obj_id);
182 
183  if (!$ilCtrl->isAsynch())
184  {
185  //if ($column_gui->getScreenMode() != IL_SCREEN_SIDE)
187  {
188  // right column wants center
190  {
191  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
192  $this->getContainerGUI()->setColumnSettings($column_gui);
193  $html = $ilCtrl->forwardCommand($column_gui);
194  }
195  // left column wants center
197  {
198  $column_gui = new ilColumnGUI($obj_type, IL_COL_LEFT);
199  $this->getContainerGUI()->setColumnSettings($column_gui);
200  $html = $ilCtrl->forwardCommand($column_gui);
201  }
202  }
203  else
204  {
205  $html = $this->getMainContent();
206  }
207  }
208 
209  return $html;
210  }
211 
215  protected function clearAdminCommandsDetermination()
216  {
217  $this->adminCommands = false;
218  }
219 
223  protected function determineAdminCommands($a_ref_id, $a_admin_com_included_in_list = false)
224  {
225  global $rbacsystem;
226 
227 //echo "-".$a_admin_com_included_in_list."-";
228 
229  if (!$this->adminCommands)
230  {
231  if (!$this->getContainerGUI()->isActiveAdministrationPanel())
232  {
233  if ($rbacsystem->checkAccess("delete", $a_ref_id))
234  {
235  $this->adminCommands = true;
236  }
237  }
238  else
239  {
240  $this->adminCommands = $a_admin_com_included_in_list;
241  }
242  }
243  }
244 
248  protected function getItemGUI($item_data,$a_show_path = false)
249  {
250  include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
251 
252  // get item list gui object
253  if (!is_object ($this->list_gui[$item_data["type"]]))
254  {
255  $item_list_gui =& ilObjectListGUIFactory::_getListGUIByType($item_data["type"]);
256  $item_list_gui->setContainerObject($this->getContainerGUI());
257  $this->list_gui[$item_data["type"]] =& $item_list_gui;
258  }
259  else
260  {
261  $item_list_gui =& $this->list_gui[$item_data["type"]];
262  }
263 
264  // show administration command buttons (or not)
265  if (!$this->getContainerGUI()->isActiveAdministrationPanel())
266  {
267 // $item_list_gui->enableDelete(false);
268 // $item_list_gui->enableLink(false);
269 // $item_list_gui->enableCut(false);
270  }
271 
272  // container specific modifications
273  $this->getContainerGUI()->modifyItemGUI($item_list_gui, $item_data, $a_show_path);
274 
275  return $item_list_gui;
276  }
277 
281  function determinePageEmbeddedBlocks($a_container_page_html)
282  {
283  $type_grps = $this->getGroupedObjTypes();
284 
285  // iterate all types
286  foreach ($type_grps as $type => $v)
287  {
288  // set template (overall or type specific)
289  if (is_int(strpos($a_container_page_html, "[list-".$type."]")))
290  {
291  $this->addEmbeddedBlock("type", $type);
292  }
293  }
294  }
295 
301  function addEmbeddedBlock($block_type, $block_parameter)
302  {
303  $this->embedded_block[$block_type][] = $block_parameter;
304  }
305 
309  function getEmbeddedBlocks()
310  {
311  return $this->embedded_block;
312  }
313 
318  {
319  global $lng;
320 
321  // first all type specific blocks
322  if (is_array($this->embedded_block["type"]))
323  {
324  // all embedded typed blocks
325  foreach ($this->embedded_block["type"] as $k => $type)
326  {
327  if ($this->rendered_block["type"][$type] == "")
328  {
329  if (is_array($this->items[$type]))
330  {
331  $tpl = $this->newBlockTemplate();
332 
333  // the header
334  $this->addHeaderRow($tpl, $type);
335 
336  // all rows
337  $item_rendered = false;
338  $position = 1;
339 
340  if($type == 'sess')
341  {
342  $this->items['sess'] = ilUtil::sortArray($this->items['sess'],'start','ASC',true,true);
343  }
344 
345  foreach($this->items[$type] as $k => $item_data)
346  {
347  $html = $this->renderItem($item_data,$position++);
348  if ($html != "")
349  {
350  $this->addStandardRow($tpl, $html, $item_data["child"]);
351  $item_rendered = true;
352  $this->rendered_items[$item_data["child"]] = true;
353  }
354  }
355 
356  // if no item has been rendered, add message
357  if (!$item_rendered)
358  {
359  //$this->addMessageRow($tpl, $lng->txt("msg_no_type_accessible"), $type);
360  $this->rendered_block["type"][$type] = "";
361  }
362  else
363  {
364  $this->rendered_block["type"][$type] = $tpl->get();
365  }
366  }
367  }
368  }
369  }
370  }
371 
379  function renderItem($a_item_data,$a_position = 0,$a_force_icon = false)
380  {
381  global $ilSetting,$ilAccess,$ilCtrl;
382 
383  // Pass type, obj_id and tree to checkAccess method to improve performance
384  if(!$ilAccess->checkAccess('visible','',$a_item_data['ref_id'],$a_item_data['type'],$a_item_data['obj_id'],$a_item_data['tree']))
385  {
386  return '';
387  }
388 
389  $item_list_gui = $this->getItemGUI($a_item_data);
390  if ($ilSetting->get("icon_position_in_lists") == "item_rows" ||
391  $a_item_data["type"] == "sess" || $a_force_icon)
392  {
393  $item_list_gui->enableIcon(true);
394  }
395  if ($this->getContainerGUI()->isActiveAdministrationPanel() && !$_SESSION["clipboard"])
396  {
397  $item_list_gui->enableCheckbox(true);
398  }
399  if ($this->getContainerGUI()->isActiveOrdering())
400  {
401  $item_list_gui->setPositionInputField("[".$a_item_data["ref_id"]."]",
402  sprintf('%.1f', $a_position));
403  }
404  if($a_item_data['type'] == 'sess' and get_class($this) != 'ilContainerObjectiveGUI')
405  {
406  switch($this->getDetailsLevel($a_item_data['obj_id']))
407  {
408  case self::DETAILS_TITLE:
409  $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_MINIMAL);
410  $item_list_gui->enableExpand(true);
411  $item_list_gui->setExpanded(false);
412  $item_list_gui->enableDescription(false);
413  $item_list_gui->enableProperties(true);
414  break;
415 
416  case self::DETAILS_ALL:
417  $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_ALL);
418  $item_list_gui->enableExpand(true);
419  $item_list_gui->setExpanded(true);
420  $item_list_gui->enableDescription(true);
421  $item_list_gui->enableProperties(true);
422  break;
423 
424  default:
425  $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_ALL);
426  $item_list_gui->enableExpand(true);
427  $item_list_gui->enableDescription(true);
428  $item_list_gui->enableProperties(true);
429  break;
430  }
431  }
432 
433  // show subitems
434  if($a_item_data['type'] == 'sess' and (
435  $this->getDetailsLevel($a_item_data['obj_id']) != self::DETAILS_TITLE or
436  $this->getContainerGUI()->isActiveAdministrationPanel() or
437  $this->getContainerGUI()->isActiveOrdering()
438  )
439  )
440  {
441  $pos = 1;
442 
443  include_once('./Services/Container/classes/class.ilContainerSorting.php');
444  $items = $this->getContainerObject()->items_obj->getItemsByEvent($a_item_data['obj_id']);
445  $items = ilContainerSorting::_getInstance($this->getContainerObject()->getId())->sortSubItems('sess',$a_item_data['obj_id'],$items);
446 
447  foreach($items as $item)
448  {
449  // TODO: this should be removed and be handled by if(strlen($sub_item_html))
450  // see mantis: 0003944
451  if(!$ilAccess->checkAccess('visible','',$item['ref_id']))
452  {
453  continue;
454  }
455 
456  $item_list_gui2 = $this->getItemGUI($item);
457  $item_list_gui2->enableIcon(true);
458  $item_list_gui2->enableItemDetailLinks(false);
459  if ($this->getContainerGUI()->isActiveAdministrationPanel() && !$_SESSION["clipboard"])
460  {
461  $item_list_gui2->enableCheckbox(true);
462  }
463  if ($this->getContainerGUI()->isActiveOrdering())
464  {
465  if ($this->getContainerObject()->getOrderType() == ilContainer::SORT_MANUAL)
466  {
467  $item_list_gui2->setPositionInputField("[sess][".$a_item_data['obj_id']."][".$item["ref_id"]."]",
468  sprintf('%.1f', $pos));
469  $pos++;
470  }
471 
472  }
473  $sub_item_html = $item_list_gui2->getListItemHTML($item['ref_id'],
474  $item['obj_id'], $item['title'], $item['description']);
475 
476 
477  $this->determineAdminCommands($item["ref_id"],$item_list_gui2->adminCommandsIncluded());
478  if(strlen($sub_item_html))
479  {
480  $item_list_gui->addSubItemHTML($sub_item_html);
481  }
482  }
483  }
484 
485  if ($ilSetting->get("item_cmd_asynch"))
486  {
487  $asynch = true;
488  $ilCtrl->setParameter($this->container_gui, "cmdrefid", $a_item_data['ref_id']);
489  $asynch_url = $ilCtrl->getLinkTarget($this->container_gui,
490  "getAsynchItemList", "", true, false);
491  $ilCtrl->setParameter($this->container_gui, "cmdrefid", "");
492  }
493 
494  $html = $item_list_gui->getListItemHTML($a_item_data['ref_id'],
495  $a_item_data['obj_id'], $a_item_data['title'], $a_item_data['description'],
496  $asynch, false, $asynch_url);
497  $this->determineAdminCommands($a_item_data["ref_id"],
498  $item_list_gui->adminCommandsIncluded());
499 
500 
501  return $html;
502  }
503 
510  function &newBlockTemplate()
511  {
512  $tpl = new ilTemplate ("tpl.container_list_block.html", true, true,
513  "Services/Container");
514  $this->cur_row_type = "row_type_1";
515  return $tpl;
516  }
517 
521  function addStandardRow(&$a_tpl, $a_html, $a_ref_id = 0)
522  {
523  global $ilSetting, $lng;
524 
525  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
526  ? "row_type_2"
527  : "row_type_1";
528 
529  if ($a_ref_id > 0)
530  {
531  $a_tpl->setCurrentBlock($this->cur_row_type);
532  $a_tpl->setVariable("ROW_ID", 'id="item_row_'.$a_ref_id.'"');
533  $a_tpl->parseCurrentBlock();
534  }
535  else
536  {
537  $a_tpl->touchBlock($this->cur_row_type);
538  }
539 
540  $a_tpl->setCurrentBlock("container_standard_row");
541  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
542  $a_tpl->parseCurrentBlock();
543  $a_tpl->touchBlock("container_row");
544  }
545 
549  function addHeaderRow($a_tpl, $a_type = "", $a_text = "")
550  {
551  global $lng, $ilSetting, $objDefinition;
552 
553  $a_tpl->setVariable("CB_ID", ' id="bl_cntr_'.$this->bl_cnt.'"');
554  if ($this->getContainerGUI()->isActiveAdministrationPanel() && !$_SESSION["clipboard"])
555  {
556  $a_tpl->setCurrentBlock("select_all_row");
557  $a_tpl->setVariable("CHECKBOXNAME", "bl_cb_".$this->bl_cnt);
558  $a_tpl->setVariable("SEL_ALL_PARENT", "bl_cntr_".$this->bl_cnt);
559  $a_tpl->setVariable("SEL_ALL_PARENT", "bl_cntr_".$this->bl_cnt);
560  $a_tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
561  $a_tpl->parseCurrentBlock();
562  $this->bl_cnt++;
563  }
564 
565  if ($a_text == "" && $a_type != "")
566  {
567  if (!$objDefinition->isPlugin($a_type))
568  {
569  $title = $lng->txt("objs_".$a_type);
570  }
571  else
572  {
573  include_once("./Services/Component/classes/class.ilPlugin.php");
574  $title = ilPlugin::lookupTxt("rep_robj", $a_type, "objs_".$a_type);
575  }
576  }
577  else
578  {
579  $title = $a_text;
580  }
581 
582  if ($ilSetting->get("icon_position_in_lists") != "item_rows" &&
583  $a_type != "")
584  {
585  $icon = ilUtil::getImagePath("icon_".$a_type.".gif");
586 
587  $a_tpl->setCurrentBlock("container_header_row_image");
588  $a_tpl->setVariable("HEADER_IMG", $icon);
589  $a_tpl->setVariable("HEADER_ALT", $title);
590  }
591  else
592  {
593  $a_tpl->setCurrentBlock("container_header_row");
594  }
595 
596  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
597  $a_tpl->parseCurrentBlock();
598  $a_tpl->touchBlock("container_row");
599 
600  $this->resetRowType();
601  }
602 
603 
607  function resetRowType()
608  {
609  $this->cur_row_type = "";
610  }
611 
615  function insertPageEmbeddedBlocks($a_output_html)
616  {
617  $this->determinePageEmbeddedBlocks($a_output_html);
618  $this->renderPageEmbeddedBlocks($this->items);
619 
620  $type_grps = $this->getGroupedObjTypes();
621 
622  // iterate all types
623  foreach ($type_grps as $type => $v)
624  {
625  // set template (overall or type specific)
626  if (is_int(strpos($a_output_html, "[list-".$type."]")))
627  {
628  $a_output_html = eregi_replace("\[list-".$type."\]",
629  $this->rendered_block["type"][$type], $a_output_html);
630  }
631  }
632 
633  return $a_output_html;
634  }
635 
639  function addMessageRow(&$a_tpl, $a_message, $a_type)
640  {
641  global $lng, $objDefinition;
642 
643  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
644  ? "row_type_2"
645  : "row_type_1";
646 
647  $a_tpl->touchBlock($this->cur_row_type);
648 
649  if (!$objDefinition->isPlugin($type))
650  {
651  $type = $lng->txt("obj_".$a_type);
652  }
653  else
654  {
655  include_once("./Services/Component/classes/class.ilPlugin.php");
656  $title = ilPlugin::lookupTxt("rep_robj", $a_type, "objs_".$a_type);
657  }
658  $a_message = str_replace("[type]", $type, $a_message);
659 
660  $a_tpl->setVariable("ROW_NBSP", "&nbsp;");
661 
662  $a_tpl->setCurrentBlock("container_standard_row");
663  $a_tpl->setVariable("BLOCK_ROW_CONTENT",
664  $a_message);
665  $a_tpl->parseCurrentBlock();
666  $a_tpl->touchBlock("container_row");
667  }
668 
672  function addSeparatorRow(&$a_tpl)
673  {
674  global $lng;
675 
676  $a_tpl->setCurrentBlock("container_block");
677  $a_tpl->parseCurrentBlock();
678  }
679 
686  {
687  global $objDefinition;
688 
689  if (empty($this->type_grps))
690  {
691  $this->type_grps =
692  $objDefinition->getGroupedRepositoryObjectTypes($this->getContainerObject()->getType());
693  }
694  return $this->type_grps;
695  }
696 
700  function getIntroduction()
701  {
702  global $ilUser, $lng, $ilCtrl;
703 
704  $lng->loadLanguageModule("rep");
705 
706  $tpl = new ilTemplate("tpl.rep_intro.html", true, true, "Services/Repository");
707  $tpl->setVariable("IMG_REP_LARGE", ilUtil::getImagePath("icon_root_xxl.gif"));
708  $tpl->setVariable("TXT_WELCOME", $lng->txt("rep_intro"));
709  $tpl->setVariable("TXT_INTRO_1", $lng->txt("rep_intro1"));
710  $tpl->setVariable("TXT_INTRO_2", $lng->txt("rep_intro2"));
711  $tpl->setVariable("TXT_INTRO_3", sprintf($lng->txt("rep_intro3"), $lng->txt("add")));
712  $tpl->setVariable("TXT_INTRO_4", sprintf($lng->txt("rep_intro4"), $lng->txt("cat_add")));
713  $tpl->setVariable("TXT_INTRO_5", $lng->txt("rep_intro5"));
714  $tpl->setVariable("TXT_INTRO_6", $lng->txt("rep_intro6"));
715 
716  return $tpl->get();
717  }
718 
719 } // END class.ilContainerContentGUI
720 ?>