ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilContainerObjectiveGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
25 include_once("./Services/Container/classes/class.ilContainerContentGUI.php");
26 
36 {
37  protected $force_details = 0;
38 
39  const MATERIALS_TESTS = 1;
40  const MATERIALS_OTHER = 2;
41 
42  private $output_html = '';
43 
51  public function __construct($a_container_gui)
52  {
53  global $lng;
54 
55  $this->lng = $lng;
56  parent::__construct($a_container_gui);
57 
58  $this->initDetails();
59  }
60 
68  public function getDetailsLevel($a_objective_id)
69  {
70  if($a_objective_id == $this->force_details)
71  {
72  return self::DETAILS_ALL;
73  }
74  return $this->details_level;
75  }
76 
83  public function getMainContent()
84  {
85  global $lng,$ilTabs,$ilAccess;
86 
87  // see bug #7452
88 // $ilTabs->setSubTabActive($this->getContainerObject()->getType().'_content');
89 
90 
91  include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
92 
93  $tpl = new ilTemplate("tpl.container_page.html", true, true,"Services/Container");
94 
95  // Feedback
96  // @todo
97 // $this->__showFeedBack();
98 
99  if($ilAccess->checkAccess('write','',$this->getContainerObject()->getRefId()) or 1)
100  {
101  $this->showButton('askReset',$lng->txt('crs_reset_results'));
102  }
103 
104  $this->items = $this->getContainerObject()->getSubItems($this->getContainerGUI()->isActiveAdministrationPanel());
105 
106  $this->showStatus($tpl);
107  $this->showObjectives($tpl);
108  $this->showMaterials($tpl,self::MATERIALS_TESTS);
109 
110  $this->showMaterials($tpl,self::MATERIALS_OTHER);
111 
112  $tpl->setVariable('CONTAINER_PAGE_CONTENT',$this->output_html);
113  #$tpl->setVariable('cont_page_content',$info_tpl->get());
114  #$tpl->parseCurrentBlock('CONTAINER_PAGE_CONTENT',$this->output_html);
115  #$tpl->parseCurrentBlock();
116 
117  return $tpl->get();
118  }
119 
127  public function showStatus($tpl)
128  {
129  global $ilUser,$lng;
130 
131  include_once('./Modules/Course/classes/class.ilCourseObjectiveResultCache.php');
132 
133 
134  $status = ilCourseObjectiveResultCache::getStatus($ilUser->getId(),$this->getContainerObject()->getId());
135  if($status == IL_OBJECTIVE_STATUS_EMPTY) {
136  return;
137  }
138  $info_tpl = new ilTemplate('tpl.crs_objectives_view_info_table.html',true,true,'Modules/Course');
139  $info_tpl->setVariable("INFO_STRING",$lng->txt('crs_objectives_info_'.$status));
140  $info_tpl->setVariable("IMG_INFO", ilUtil::getImagePath("mess_info.png"));
141 
142  $this->output_html .= $info_tpl->get();
143  }
144 
152  public function showObjectives($a_tpl)
153  {
154  global $lng,$ilSetting;
155 
157  $output_html = $this->getContainerGUI()->getContainerPageHTML();
158 
159 
160  // get embedded blocks
161  if ($output_html != "")
162  {
164  }
165 
166  $tpl = $this->newBlockTemplate();
167 
168  // All objectives
169  include_once './Modules/Course/classes/class.ilCourseObjective.php';
170  if(!count($objective_ids = ilCourseObjective::_getObjectiveIds($this->getContainerObject()->getId())))
171  {
172  return false;
173  }
174 
175  include_once('./Modules/Course/classes/class.ilCourseObjectiveListGUI.php');
176  $this->objective_list_gui = new ilCourseObjectiveListGUI();
177  $this->objective_list_gui->setContainerObject($this->getContainerGUI());
178  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
179  {
180  $this->objective_list_gui->enableIcon(true);
181  }
182 
183 
184  $item_html = array();
185  foreach($objective_ids as $objective_id)
186  {
187  if($html = $this->renderObjective($objective_id))
188  {
189  $item_html[] = $html;
190  }
191  }
192 
193  // if we have at least one item, output the block
194  if (count($item_html) > 0)
195  {
196  $this->addHeaderRow($tpl,'lobj',$lng->txt('crs_objectives'));
197  foreach($item_html as $h)
198  {
199  $this->addStandardRow($tpl, $h);
200  }
201  }
202 
203  $this->addFooterRow($tpl);
204  $this->output_html .= $output_html.$tpl->get();
205  }
206 
214  public function addFooterRow($tpl)
215  {
216  global $ilCtrl;
217 
218  $tpl->setCurrentBlock('details_img');
219 
220  $append = $this->details_level == self::DETAILS_TITLE ? 'off' : '';
221  $tpl->setCurrentBlock('details_img');
222  $tpl->setVariable('DETAILS_SRC',ilUtil::getImagePath('details2'.$append.'.png'));
223  $tpl->setVariable('DETAILS_ALT',$this->lng->txt('details').' 2');
224  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->getContainerObject()->getRefId());
225  $ilCtrl->setParameterByClass("ilrepositorygui", "details_level", "1");
226  $tpl->setVariable('DETAILS_LINK',
227  $ilCtrl->getLinkTargetByClass("ilrepositorygui", ""));
228  $tpl->parseCurrentBlock();
229 
230  $append = $this->details_level == self::DETAILS_ALL ? 'off' : '';
231  $tpl->setCurrentBlock('details_img');
232  $tpl->setVariable('DETAILS_SRC',ilUtil::getImagePath('details3'.$append.'.png'));
233  $tpl->setVariable('DETAILS_ALT',$this->lng->txt('details').' 3');
234  $ilCtrl->setParameterByClass("ilrepositorygui", "details_level", "2");
235  $tpl->setVariable('DETAILS_LINK',
236  $ilCtrl->getLinkTargetByClass("ilrepositorygui", ""));
237  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
238  $tpl->parseCurrentBlock();
239 
240  $tpl->setCurrentBlock('container_details_row');
241  $tpl->setVariable('TXT_DETAILS',$this->lng->txt('details'));
242  $tpl->parseCurrentBlock();
243  }
244 
245 
246 
254  public function showMaterials($a_tpl,$a_mode)
255  {
256  global $ilAccess, $lng;
257 
259 
260  #$output_html = $this->getContainerGUI()->getContainerPageHTML();
261 
262  // get embedded blocks
263  if ($output_html != "")
264  {
266  }
267 
268  $tpl = $this->newBlockTemplate();
269 
270  // item groups
271  $tpl = $this->newBlockTemplate();
272 
273  if ($a_mode == self::MATERIALS_OTHER)
274  {
275  $this->getItemGroupsHTML($tpl);
276  }
277 
278 
279  if (is_array($this->items["_all"]))
280  {
281  // all rows
282  $item_r = array();
283 
284  $position = 1;
285  foreach($this->items["_all"] as $k => $item_data)
286  {
287  if($a_mode == self::MATERIALS_TESTS and $item_data['type'] != 'tst')
288  {
289  continue;
290  }
291  if ($item_data['type'] == 'itgr')
292  {
293  continue;
294  }
295 
296  if($this->rendered_items[$item_data["child"]] !== true)
297  {
298  $this->rendered_items[$item_data['child']] = true;
299 
300  // TODO: Position (DONE ?)
301  $html = $this->renderItem($item_data,$position++,$a_mode == self::MATERIALS_TESTS ? false : true);
302  if ($html != "")
303  {
304  $item_r[] = array("html" => $html, "id" => $item_data["child"]);
305  }
306  }
307  }
308 
309  // if we have at least one item, output the block
310  if (count($item_r) > 0)
311  {
312  switch($a_mode)
313  {
314  case self::MATERIALS_TESTS:
315  $txt = $lng->txt('objs_tst');
316  break;
317 
318  case self::MATERIALS_OTHER:
319  $txt = $lng->txt('crs_other_resources');
320  break;
321  }
322 
323  $this->addHeaderRow($tpl,$a_mode == self::MATERIALS_TESTS ? 'tst' : '',$txt);
324  foreach($item_r as $h)
325  {
326  $this->addStandardRow($tpl, $h["html"], $h["id"]);
327  }
328  }
329  }
330 
331  #$output_html .= $tpl->get();
332  $this->output_html .= $tpl->get();
333  #$a_tpl->setCurrentBlock('cont_page_content');
334  #$a_tpl->setVariable("CONTAINER_PAGE_CONTENT", $output_html);
335  #$a_tpl->parseCurrentBlock();
336  }
337 
345  protected function renderObjective($a_objective_id)
346  {
347  global $ilUser,$lng;
348 
349  include_once('./Modules/Course/classes/class.ilCourseObjective.php');
350  $objective = new ilCourseObjective($this->getContainerObject(),$a_objective_id);
351 
352  include_once('./Services/Container/classes/class.ilContainerSorting.php');
353  include_once('./Services/Object/classes/class.ilObjectActivation.php');
354  $items = ilObjectActivation::getItemsByObjective($a_objective_id);
355  $items = ilContainerSorting::_getInstance($this->getContainerObject()->getId())->sortSubItems('lobj',$a_objective_id,$items);
356 
357  include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
358  $objectives_lm_obj = new ilCourseObjectiveMaterials($a_objective_id);
359 
360  $pos = 1;
361  foreach($items as $item)
362  {
363  if($this->getDetailsLevel($a_objective_id) < self::DETAILS_ALL)
364  {
365  continue;
366  }
367 
368  $chapters = $objectives_lm_obj->getChapters();
369 
370  $item_list_gui2 = $this->getItemGUI($item);
371  $item_list_gui2->enableIcon(true);
372 
373  if(count($chapters))
374  {
375  $num = 0;
376  $has_sections = false;
377  foreach($chapters as $chapter)
378  {
379  if($chapter['ref_id'] != $item['child'])
380  {
381  continue;
382  }
383  $has_sections = true;
384  include_once './Modules/LearningModule/classes/class.ilLMObject.php';
385 
386  $details[$num]['desc'] = $lng->txt('obj_'.$chapter['type']).' -> ';
387  $details[$num]['target'] = '_top';
388  $details[$num]['link'] = "ilias.php?baseClass=ilLMPresentationGUI&ref_id=".$chapter['ref_id'].'&obj_id='.$chapter['obj_id'];
389  $details[$num]['name'] = ilLMObject::_lookupTitle($chapter['obj_id']);
390  $num++;
391  }
392  if($has_sections)
393  {
394  $item_list_gui2->enableItemDetailLinks(true);
395  $item_list_gui2->setItemDetailLinks($details,$lng->txt('crs_suggested_sections').': ');
396  }
397  }
398 
399  if ($this->getContainerGUI()->isActiveAdministrationPanel())
400  {
401  $item_list_gui2->enableCheckbox(true);
402  if ($this->getContainerObject()->getOrderType() == ilContainer::SORT_MANUAL)
403  {
404  $item_list_gui2->setPositionInputField("[lobj][".$a_objective_id."][".$item["ref_id"]."]",
405  sprintf('%.1f', $pos));
406  $pos++;
407  }
408 
409  }
410  $this->rendered_items[$item['child']] = true;
411  $sub_item_html = $item_list_gui2->getListItemHTML($item['ref_id'],
412  $item['obj_id'], $item['title'], $item['description']);
413 
414  $this->determineAdminCommands($item["ref_id"],
415  $item_list_gui2->adminCommandsIncluded());
416  $this->objective_list_gui->addSubItemHTML($sub_item_html);
417  }
418 
419  if($this->getDetailsLevel($a_objective_id) == self::DETAILS_ALL)
420  {
421  $this->objective_list_gui->enableCommands(false);
422  }
423  else
424  {
425  $this->objective_list_gui->enableCommands(true);
426  }
427 
428  $html = $this->objective_list_gui->getListItemHTML(
429  0,
430  $a_objective_id,
431  $objective->getTitle(),
432  $objective->getDescription());
433 
434  return $html;
435  }
436 
444  protected function initDetails()
445  {
446  global $ilUser;
447 
448  if(isset($_GET['details_level']))
449  {
450  $this->details_level = (int) $_GET['details_level'];
451  ilObjUser::_writePref($ilUser->getId(),'crs_objectives_details',$this->details_level);
452  }
453  else
454  {
455  $this->details_level = $ilUser->getPref('crs_objectives_details') ? $ilUser->getPref('crs_objectives_details') : self::DETAILS_TITLE;
456  }
457  if(isset($_GET['objective_details']))
458  {
459  $this->force_details = (int) $_GET['objective_details'];
460  ilObjUser::_writePref($ilUser->getId(),'crs_objectives_force_details_'.$this->getContainerObject()->getId(),$this->force_details);
461  }
462  elseif($details_id = $ilUser->getPref('crs_objectives_force_details_'.$this->getContainerObject()->getId()))
463  {
464  $this->force_details = $details_id;
465  }
466  else
467  {
468  include_once './Modules/Course/classes/class.ilCourseObjective.php';
469  include_once('./Modules/Course/classes/class.ilCourseObjectiveResultCache.php');
470  foreach(ilCourseObjective::_getObjectiveIds($this->getContainerObject()->getId()) as $objective_id)
471  {
472  if(ilCourseObjectiveResultCache::isSuggested($ilUser->getId(),$this->getContainerObject()->getId(),$objective_id))
473  {
474  $this->force_details = $objective_id;
475  break;
476  }
477  }
478  }
479  return true;
480  }
481 
489  protected function showButton($a_cmd,$a_text,$a_target = '')
490  {
491  global $ilToolbar, $ilCtrl;
492 
493  // #11842
494  $ilToolbar->addButton($a_text,
495  $ilCtrl->getLinkTarget($this->getContainerGUI(),$a_cmd),
496  $a_target);
497  }
498 }
499 ?>