ILIAS  Release_4_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  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35 abstract class ilContainerContentGUI
36 {
38  const DETAILS_TITLE = 1;
39  const DETAILS_ALL = 2;
40 
41 
43 
46 
51  function __construct(&$container_gui_obj)
52  {
53  $this->container_gui = $container_gui_obj;
54  $this->container_obj = $this->container_gui->object;
55  }
56 
64  protected function getDetailsLevel($a_item_id)
65  {
66  return $this->details_level;
67  }
68 
74  public function getContainerObject()
75  {
76  return $this->container_obj;
77  }
78 
84  public function getContainerGUI()
85  {
86  return $this->container_gui;
87  }
88 
95  public function setOutput()
96  {
97  global $tpl;
98 
99  // BEGIN ChangeEvent: record read event.
100  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
102  {
103  global $ilUser;
104  $obj_id = ilObject::_lookupObjId($this->getContainerObject()->getRefId());
105  ilChangeEvent::_recordReadEvent($obj_id, $ilUser->getId());
106  }
107  // END ChangeEvent: record read event.
108 
109  $tpl->setContent($this->getCenterColumnHTML());
110  $tpl->setRightContent($this->getRightColumnHTML());
111  }
112 
116  protected function getRightColumnHTML()
117  {
118  global $ilUser, $lng, $ilCtrl, $ilAccess;
119 
120  $ilCtrl->saveParameterByClass("ilcolumngui", "col_return");
121 
122  $obj_id = ilObject::_lookupObjId($this->getContainerObject()->getRefId());
123  $obj_type = ilObject::_lookupType($obj_id);
124 
125  include_once("Services/Block/classes/class.ilColumnGUI.php");
126  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
127 
128  if ($column_gui->getScreenMode() == IL_SCREEN_FULL)
129  {
130  return "";
131  }
132 
133  $this->getContainerGUI()->setColumnSettings($column_gui);
134 
135  if ($ilCtrl->getNextClass() == "ilcolumngui" &&
136  $column_gui->getCmdSide() == IL_COL_RIGHT &&
137  $column_gui->getScreenMode() == IL_SCREEN_SIDE)
138  {
139 
140  $html = $ilCtrl->forwardCommand($column_gui);
141  }
142  else
143  {
144  if (!$ilCtrl->isAsynch())
145  {
146  $html = $ilCtrl->getHTML($column_gui);
147  }
148  }
149 
150  return $html;
151  }
152 
156  protected function getCenterColumnHTML()
157  {
158  global $ilCtrl, $tpl;
159 
160  $ilCtrl->saveParameterByClass("ilcolumngui", "col_return");
161 
162  switch ($ilCtrl->getNextClass())
163  {
164  case "ilcolumngui":
165  $ilCtrl->setReturn($this->container_gui, "");
166  $html = $this->__forwardToColumnGUI();
167  break;
168 
169  default:
170  $html = $this->getMainContent();
171  break;
172  }
173 
174  return $html;
175  }
176 
181  abstract function getMainContent();
182 
186  final private function __forwardToColumnGUI()
187  {
188  global $ilCtrl, $ilAccess;
189 
190  include_once("Services/Block/classes/class.ilColumnGUI.php");
191 
192  // this gets us the subitems we need in setColumnSettings()
193  // todo: this should be done in ilCourseGUI->getSubItems
194  //$this->course_obj->initCourseItemObject($this->getContainerObject()->getRefId());
195 
196  $obj_id = ilObject::_lookupObjId($this->getContainerObject()->getRefId());
197  $obj_type = ilObject::_lookupType($obj_id);
198 
199  if (!$ilCtrl->isAsynch())
200  {
201  //if ($column_gui->getScreenMode() != IL_SCREEN_SIDE)
203  {
204  // right column wants center
206  {
207  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
208  $this->getContainerGUI()->setColumnSettings($column_gui);
209  $html = $ilCtrl->forwardCommand($column_gui);
210  }
211  // left column wants center
213  {
214  $column_gui = new ilColumnGUI($obj_type, IL_COL_LEFT);
215  $this->getContainerGUI()->setColumnSettings($column_gui);
216  $html = $ilCtrl->forwardCommand($column_gui);
217  }
218  }
219  else
220  {
221  $html = $this->getMainContent();
222  }
223  }
224 
225  return $html;
226  }
227 
231  protected function clearAdminCommandsDetermination()
232  {
233  $this->adminCommands = false;
234  }
235 
239  protected function determineAdminCommands($a_ref_id, $a_admin_com_included_in_list = false)
240  {
241  global $rbacsystem;
242 
243 //echo "-".$a_admin_com_included_in_list."-";
244 
245  if (!$this->adminCommands)
246  {
247  if (!$this->getContainerGUI()->isActiveAdministrationPanel())
248  {
249  if ($rbacsystem->checkAccess("delete", $a_ref_id))
250  {
251  $this->adminCommands = true;
252  }
253  }
254  else
255  {
256  $this->adminCommands = $a_admin_com_included_in_list;
257  }
258  }
259  }
260 
264  protected function getItemGUI($item_data,$a_show_path = false)
265  {
266  include_once './classes/class.ilObjectListGUIFactory.php';
267 
268  // get item list gui object
269  if (!is_object ($this->list_gui[$item_data["type"]]))
270  {
271  $item_list_gui =& ilObjectListGUIFactory::_getListGUIByType($item_data["type"]);
272  $item_list_gui->setContainerObject($this->getContainerGUI());
273  $this->list_gui[$item_data["type"]] =& $item_list_gui;
274  }
275  else
276  {
277  $item_list_gui =& $this->list_gui[$item_data["type"]];
278  }
279 
280  // show administration command buttons (or not)
281  if (!$this->getContainerGUI()->isActiveAdministrationPanel())
282  {
283 // $item_list_gui->enableDelete(false);
284 // $item_list_gui->enableLink(false);
285 // $item_list_gui->enableCut(false);
286  }
287 
288  // container specific modifications
289  $this->getContainerGUI()->modifyItemGUI($item_list_gui, $item_data, $a_show_path);
290 
291  return $item_list_gui;
292  }
293 
297  function determinePageEmbeddedBlocks($a_container_page_html)
298  {
299  $type_grps = $this->getGroupedObjTypes();
300 
301  // iterate all types
302  foreach ($type_grps as $type => $v)
303  {
304  // set template (overall or type specific)
305  if (is_int(strpos($a_container_page_html, "[list-".$type."]")))
306  {
307  $this->addEmbeddedBlock("type", $type);
308  }
309  }
310  }
311 
317  function addEmbeddedBlock($block_type, $block_parameter)
318  {
319  $this->embedded_block[$block_type][] = $block_parameter;
320  }
321 
325  function getEmbeddedBlocks()
326  {
327  return $this->embedded_block;
328  }
329 
334  {
335  global $lng;
336 
337  // first all type specific blocks
338  if (is_array($this->embedded_block["type"]))
339  {
340  // all embedded typed blocks
341  foreach ($this->embedded_block["type"] as $k => $type)
342  {
343  if ($this->rendered_block["type"][$type] == "")
344  {
345  if (is_array($this->items[$type]))
346  {
347  $tpl = $this->newBlockTemplate();
348 
349  // the header
350  $this->addHeaderRow($tpl, $type);
351 
352  // all rows
353  $item_rendered = false;
354  $position = 1;
355  foreach($this->items[$type] as $k => $item_data)
356  {
357  $html = $this->renderItem($item_data,$position++);
358  if ($html != "")
359  {
360  $this->addStandardRow($tpl, $html, $item_data["child"]);
361  $item_rendered = true;
362  $this->rendered_items[$item_data["child"]] = true;
363  }
364  }
365 
366  // if no item has been rendered, add message
367  if (!$item_rendered)
368  {
369  //$this->addMessageRow($tpl, $lng->txt("msg_no_type_accessible"), $type);
370  $this->rendered_block["type"][$type] = "";
371  }
372  else
373  {
374  $this->rendered_block["type"][$type] = $tpl->get();
375  }
376  }
377  }
378  }
379  }
380  }
381 
389  function renderItem($a_item_data,$a_position = 0,$a_force_icon = false)
390  {
391  global $ilSetting,$ilAccess,$ilCtrl;
392 
393  // Pass type, obj_id and tree to checkAccess method to improve performance
394  if(!$ilAccess->checkAccess('visible','',$a_item_data['ref_id'],$a_item_data['type'],$a_item_data['obj_id'],$a_item_data['tree']))
395  {
396  return '';
397  }
398 
399  $item_list_gui = $this->getItemGUI($a_item_data);
400  if ($ilSetting->get("icon_position_in_lists") == "item_rows" ||
401  $a_item_data["type"] == "sess" || $a_force_icon)
402  {
403  $item_list_gui->enableIcon(true);
404  }
405  if ($this->getContainerGUI()->isActiveAdministrationPanel() && !$_SESSION["clipboard"])
406  {
407  $item_list_gui->enableCheckbox(true);
408  }
409  if ($this->getContainerGUI()->isActiveOrdering())
410  {
411  $item_list_gui->setPositionInputField("[".$a_item_data["ref_id"]."]",
412  sprintf('%.1f', $a_position));
413  }
414  if($a_item_data['type'] == 'sess' and get_class($this) != 'ilContainerObjectiveGUI')
415  {
416  switch($this->getDetailsLevel($a_item_data['obj_id']))
417  {
418  case self::DETAILS_TITLE:
419  $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_MINIMAL);
420  $item_list_gui->enableExpand(true);
421  $item_list_gui->setExpanded(false);
422  $item_list_gui->enableDescription(false);
423  $item_list_gui->enableProperties(true);
424  break;
425 
426  case self::DETAILS_ALL:
427  $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_ALL);
428  $item_list_gui->enableExpand(true);
429  $item_list_gui->setExpanded(true);
430  $item_list_gui->enableDescription(true);
431  $item_list_gui->enableProperties(true);
432  break;
433 
434  default:
435  $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_ALL);
436  $item_list_gui->enableExpand(true);
437  $item_list_gui->enableDescription(true);
438  $item_list_gui->enableProperties(true);
439  break;
440  }
441  }
442 
443  // show subitems
444  if($a_item_data['type'] == 'sess' and (
445  $this->getDetailsLevel($a_item_data['obj_id']) != self::DETAILS_TITLE or
446  $this->getContainerGUI()->isActiveAdministrationPanel() or
447  $this->getContainerGUI()->isActiveOrdering()
448  )
449  )
450  {
451  $pos = 1;
452 
453  include_once('./Services/Container/classes/class.ilContainerSorting.php');
454  $items = $this->getContainerObject()->items_obj->getItemsByEvent($a_item_data['obj_id']);
455  $items = ilContainerSorting::_getInstance($this->getContainerObject()->getId())->sortSubItems('sess',$a_item_data['obj_id'],$items);
456 
457  foreach($items as $item)
458  {
459  // TODO: this should be removed and be handled by if(strlen($sub_item_html))
460  // see mantis: 0003944
461  if(!$ilAccess->checkAccess('visible','',$item['ref_id']))
462  {
463  continue;
464  }
465 
466  $item_list_gui2 = $this->getItemGUI($item);
467  $item_list_gui2->enableIcon(true);
468  $item_list_gui2->enableItemDetailLinks(false);
469  if ($this->getContainerGUI()->isActiveAdministrationPanel() && !$_SESSION["clipboard"])
470  {
471  $item_list_gui2->enableCheckbox(true);
472  }
473  if ($this->getContainerGUI()->isActiveOrdering())
474  {
475  if ($this->getContainerObject()->getOrderType() == ilContainer::SORT_MANUAL)
476  {
477  $item_list_gui2->setPositionInputField("[sess][".$a_item_data['obj_id']."][".$item["ref_id"]."]",
478  sprintf('%.1f', $pos));
479  $pos++;
480  }
481 
482  }
483  $sub_item_html = $item_list_gui2->getListItemHTML($item['ref_id'],
484  $item['obj_id'], $item['title'], $item['description']);
485 
486 
487  $this->determineAdminCommands($item["ref_id"],$item_list_gui2->adminCommandsIncluded());
488  if(strlen($sub_item_html))
489  {
490  $item_list_gui->addSubItemHTML($sub_item_html);
491  }
492  }
493  }
494 
495  if ($ilSetting->get("item_cmd_asynch"))
496  {
497  $asynch = true;
498  $ilCtrl->setParameter($this->container_gui, "cmdrefid", $a_item_data['ref_id']);
499  $asynch_url = $ilCtrl->getLinkTarget($this->container_gui,
500  "getAsynchItemList");
501  $ilCtrl->setParameter($this->container_gui, "cmdrefid", "");
502  }
503 
504  $html = $item_list_gui->getListItemHTML($a_item_data['ref_id'],
505  $a_item_data['obj_id'], $a_item_data['title'], $a_item_data['description'],
506  $asynch, false, $asynch_url);
507  $this->determineAdminCommands($a_item_data["ref_id"],
508  $item_list_gui->adminCommandsIncluded());
509 
510 
511  return $html;
512  }
513 
520  function &newBlockTemplate()
521  {
522  $tpl = new ilTemplate ("tpl.container_list_block.html", true, true,
523  "Services/Container");
524  $this->cur_row_type = "row_type_1";
525  return $tpl;
526  }
527 
531  function addStandardRow(&$a_tpl, $a_html, $a_ref_id = 0)
532  {
533  global $ilSetting, $lng;
534 
535  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
536  ? "row_type_2"
537  : "row_type_1";
538 
539  if ($a_ref_id > 0)
540  {
541  $a_tpl->setCurrentBlock($this->cur_row_type);
542  $a_tpl->setVariable("ROW_ID", 'id="item_row_'.$a_ref_id.'"');
543  $a_tpl->parseCurrentBlock();
544  }
545  else
546  {
547  $a_tpl->touchBlock($this->cur_row_type);
548  }
549 
550  $a_tpl->setCurrentBlock("container_standard_row");
551  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
552  $a_tpl->parseCurrentBlock();
553  $a_tpl->touchBlock("container_row");
554  }
555 
559  function addHeaderRow($a_tpl, $a_type = "", $a_text = "")
560  {
561  global $lng, $ilSetting, $objDefinition;
562 
563  $a_tpl->setVariable("CB_ID", ' id="bl_cntr_'.$this->bl_cnt.'"');
564  if ($this->getContainerGUI()->isActiveAdministrationPanel() && !$_SESSION["clipboard"])
565  {
566  $a_tpl->setCurrentBlock("select_all_row");
567  $a_tpl->setVariable("CHECKBOXNAME", "bl_cb_".$this->bl_cnt);
568  $a_tpl->setVariable("SEL_ALL_PARENT", "bl_cntr_".$this->bl_cnt);
569  $a_tpl->setVariable("SEL_ALL_PARENT", "bl_cntr_".$this->bl_cnt);
570  $a_tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
571  $a_tpl->parseCurrentBlock();
572  $this->bl_cnt++;
573  }
574 
575  if ($a_text == "" && $a_type != "")
576  {
577  if (!$objDefinition->isPlugin($a_type))
578  {
579  $title = $lng->txt("objs_".$a_type);
580  }
581  else
582  {
583  include_once("./Services/Component/classes/class.ilPlugin.php");
584  $title = ilPlugin::lookupTxt("rep_robj", $a_type, "objs_".$a_type);
585  }
586  }
587  else
588  {
589  $title = $a_text;
590  }
591 
592  if ($ilSetting->get("icon_position_in_lists") != "item_rows" &&
593  $a_type != "")
594  {
595  $icon = ilUtil::getImagePath("icon_".$a_type.".gif");
596 
597  $a_tpl->setCurrentBlock("container_header_row_image");
598  $a_tpl->setVariable("HEADER_IMG", $icon);
599  $a_tpl->setVariable("HEADER_ALT", $title);
600  }
601  else
602  {
603  $a_tpl->setCurrentBlock("container_header_row");
604  }
605 
606  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
607  $a_tpl->parseCurrentBlock();
608  $a_tpl->touchBlock("container_row");
609 
610  $this->resetRowType();
611  }
612 
613 
617  function resetRowType()
618  {
619  $this->cur_row_type = "";
620  }
621 
625  function insertPageEmbeddedBlocks($a_output_html)
626  {
627  $this->determinePageEmbeddedBlocks($a_output_html);
628  $this->renderPageEmbeddedBlocks($this->items);
629 
630  $type_grps = $this->getGroupedObjTypes();
631 
632  // iterate all types
633  foreach ($type_grps as $type => $v)
634  {
635  // set template (overall or type specific)
636  if (is_int(strpos($a_output_html, "[list-".$type."]")))
637  {
638  $a_output_html = eregi_replace("\[list-".$type."\]",
639  $this->rendered_block["type"][$type], $a_output_html);
640  }
641  }
642 
643  return $a_output_html;
644  }
645 
649  function addMessageRow(&$a_tpl, $a_message, $a_type)
650  {
651  global $lng, $objDefinition;
652 
653  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
654  ? "row_type_2"
655  : "row_type_1";
656 
657  $a_tpl->touchBlock($this->cur_row_type);
658 
659  if (!$objDefinition->isPlugin($type))
660  {
661  $type = $lng->txt("obj_".$a_type);
662  }
663  else
664  {
665  include_once("./Services/Component/classes/class.ilPlugin.php");
666  $title = ilPlugin::lookupTxt("rep_robj", $a_type, "objs_".$a_type);
667  }
668  $a_message = str_replace("[type]", $type, $a_message);
669 
670  $a_tpl->setVariable("ROW_NBSP", "&nbsp;");
671 
672  $a_tpl->setCurrentBlock("container_standard_row");
673  $a_tpl->setVariable("BLOCK_ROW_CONTENT",
674  $a_message);
675  $a_tpl->parseCurrentBlock();
676  $a_tpl->touchBlock("container_row");
677  }
678 
682  function addSeparatorRow(&$a_tpl)
683  {
684  global $lng;
685 
686  $a_tpl->setCurrentBlock("container_block");
687  $a_tpl->parseCurrentBlock();
688  }
689 
696  {
697  global $objDefinition;
698 
699  if (empty($this->type_grps))
700  {
701  $this->type_grps =
702  $objDefinition->getGroupedRepositoryObjectTypes($this->getContainerObject()->getType());
703  }
704  return $this->type_grps;
705  }
706 
710  function getIntroduction()
711  {
712  global $ilUser, $lng, $ilCtrl;
713 
714  $lng->loadLanguageModule("rep");
715 
716  $tpl = new ilTemplate("tpl.rep_intro.html", true, true, "Services/Repository");
717  $tpl->setVariable("IMG_REP_LARGE", ilUtil::getImagePath("icon_root_xxl.gif"));
718  $tpl->setVariable("TXT_WELCOME", $lng->txt("rep_intro"));
719  $tpl->setVariable("TXT_INTRO_1", $lng->txt("rep_intro1"));
720  $tpl->setVariable("TXT_INTRO_2", $lng->txt("rep_intro2"));
721  $tpl->setVariable("TXT_INTRO_3", sprintf($lng->txt("rep_intro3"), $lng->txt("add")));
722  $tpl->setVariable("TXT_INTRO_4", sprintf($lng->txt("rep_intro4"), $lng->txt("cat_add")));
723  $tpl->setVariable("TXT_INTRO_5", $lng->txt("rep_intro5"));
724  $tpl->setVariable("TXT_INTRO_6", $lng->txt("rep_intro6"));
725 
726  return $tpl->get();
727  }
728 
729 } // END class.ilContainerContentGUI
730 ?>