ILIAS  Release_4_2_x_branch Revision 61807
 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  $this->showMaterials($tpl,self::MATERIALS_OTHER);
110 
111  $tpl->setVariable('CONTAINER_PAGE_CONTENT',$this->output_html);
112  #$tpl->setVariable('cont_page_content',$info_tpl->get());
113  #$tpl->parseCurrentBlock('CONTAINER_PAGE_CONTENT',$this->output_html);
114  #$tpl->parseCurrentBlock();
115 
116  return $tpl->get();
117  }
118 
126  public function showStatus($tpl)
127  {
128  global $ilUser,$lng;
129 
130  include_once('./Modules/Course/classes/class.ilCourseObjectiveResultCache.php');
131 
132 
133  $status = ilCourseObjectiveResultCache::getStatus($ilUser->getId(),$this->getContainerObject()->getId());
134  if($status == IL_OBJECTIVE_STATUS_EMPTY) {
135  return;
136  }
137  $info_tpl = new ilTemplate('tpl.crs_objectives_view_info_table.html',true,true,'Modules/Course');
138  $info_tpl->setVariable("INFO_STRING",$lng->txt('crs_objectives_info_'.$status));
139  $info_tpl->setVariable("IMG_INFO", ilUtil::getImagePath("mess_info.gif"));
140 
141  $this->output_html .= $info_tpl->get();
142  }
143 
151  public function showObjectives($a_tpl)
152  {
153  global $lng,$ilSetting;
154 
156  $output_html = $this->getContainerGUI()->getContainerPageHTML();
157 
158 
159  // get embedded blocks
160  if ($output_html != "")
161  {
163  }
164 
165  $tpl = $this->newBlockTemplate();
166 
167  // All objectives
168  include_once './Modules/Course/classes/class.ilCourseObjective.php';
169  if(!count($objective_ids = ilCourseObjective::_getObjectiveIds($this->getContainerObject()->getId())))
170  {
171  return false;
172  }
173 
174  include_once('./Modules/Course/classes/class.ilCourseObjectiveListGUI.php');
175  $this->objective_list_gui = new ilCourseObjectiveListGUI();
176  $this->objective_list_gui->setContainerObject($this->getContainerGUI());
177  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
178  {
179  $this->objective_list_gui->enableIcon(true);
180  }
181 
182 
183  $item_html = array();
184  foreach($objective_ids as $objective_id)
185  {
186  if($html = $this->renderObjective($objective_id))
187  {
188  $item_html[] = $html;
189  }
190  }
191 
192  // if we have at least one item, output the block
193  if (count($item_html) > 0)
194  {
195  $this->addHeaderRow($tpl,'lobj',$lng->txt('crs_objectives'));
196  foreach($item_html as $h)
197  {
198  $this->addStandardRow($tpl, $h);
199  }
200  }
201 
202  $this->addFooterRow($tpl);
203  $this->output_html .= $output_html.$tpl->get();
204  }
205 
213  public function addFooterRow($tpl)
214  {
215  $tpl->setCurrentBlock('details_img');
216 
217  $append = $this->details_level == self::DETAILS_TITLE ? 'off' : '';
218  $tpl->setCurrentBlock('details_img');
219  $tpl->setVariable('DETAILS_SRC',ilUtil::getImagePath('details2'.$append.'.gif'));
220  $tpl->setVariable('DETAILS_ALT',$this->lng->txt('details').' 2');
221  $tpl->setVariable('DETAILS_LINK','repository.php?ref_id='.$this->getContainerObject()->getRefId().'&details_level=1');
222  $tpl->parseCurrentBlock();
223 
224  $append = $this->details_level == self::DETAILS_ALL ? 'off' : '';
225  $tpl->setCurrentBlock('details_img');
226  $tpl->setVariable('DETAILS_SRC',ilUtil::getImagePath('details3'.$append.'.gif'));
227  $tpl->setVariable('DETAILS_ALT',$this->lng->txt('details').' 3');
228  $tpl->setVariable('DETAILS_LINK','repository.php?ref_id='.$this->getContainerObject()->getRefId().'&details_level=2');
229  $tpl->parseCurrentBlock();
230 
231  $tpl->setCurrentBlock('container_details_row');
232  $tpl->setVariable('TXT_DETAILS',$this->lng->txt('details'));
233  $tpl->parseCurrentBlock();
234  }
235 
236 
237 
245  public function showMaterials($a_tpl,$a_mode)
246  {
247  global $ilAccess, $lng;
248 
250 
251  #$output_html = $this->getContainerGUI()->getContainerPageHTML();
252 
253  // get embedded blocks
254  if ($output_html != "")
255  {
257  }
258 
259  $tpl = $this->newBlockTemplate();
260  if (is_array($this->items["_all"]))
261  {
262  // all rows
263  $item_r = array();
264 
265  $position = 1;
266  foreach($this->items["_all"] as $k => $item_data)
267  {
268  if($a_mode == self::MATERIALS_TESTS and $item_data['type'] != 'tst')
269  {
270  continue;
271  }
272 
273  if($this->rendered_items[$item_data["child"]] !== true)
274  {
275  $this->rendered_items[$item_data['child']] = true;
276 
277  // TODO: Position (DONE ?)
278  $html = $this->renderItem($item_data,$position++,$a_mode == self::MATERIALS_TESTS ? false : true);
279  if ($html != "")
280  {
281  $item_r[] = array("html" => $html, "id" => $item_data["child"]);
282  }
283  }
284  }
285 
286  // if we have at least one item, output the block
287  if (count($item_r) > 0)
288  {
289  switch($a_mode)
290  {
291  case self::MATERIALS_TESTS:
292  $txt = $lng->txt('objs_tst');
293  break;
294 
295  case self::MATERIALS_OTHER:
296  $txt = $lng->txt('crs_other_resources');
297  break;
298  }
299 
300  $this->addHeaderRow($tpl,$a_mode == self::MATERIALS_TESTS ? 'tst' : '',$txt);
301  foreach($item_r as $h)
302  {
303  $this->addStandardRow($tpl, $h["html"], $h["id"]);
304  }
305  }
306  }
307 
308  #$output_html .= $tpl->get();
309  $this->output_html .= $tpl->get();
310  #$a_tpl->setCurrentBlock('cont_page_content');
311  #$a_tpl->setVariable("CONTAINER_PAGE_CONTENT", $output_html);
312  #$a_tpl->parseCurrentBlock();
313  }
314 
322  protected function renderObjective($a_objective_id)
323  {
324  global $ilUser,$lng;
325 
326  include_once('./Modules/Course/classes/class.ilCourseObjective.php');
327  $objective = new ilCourseObjective($this->getContainerObject(),$a_objective_id);
328 
329  include_once('./Services/Container/classes/class.ilContainerSorting.php');
330  $items = $this->getContainerObject()->getCourseItemObject()->getItemsByObjective($a_objective_id);
331  $items = ilContainerSorting::_getInstance($this->getContainerObject()->getId())->sortSubItems('lobj',$a_objective_id,$items);
332 
333  include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
334  $objectives_lm_obj = new ilCourseObjectiveMaterials($a_objective_id);
335 
336  $pos = 1;
337  foreach($items as $item)
338  {
339  if($this->getDetailsLevel($a_objective_id) < self::DETAILS_ALL)
340  {
341  continue;
342  }
343 
344  $chapters = $objectives_lm_obj->getChapters();
345 
346  $item_list_gui2 = $this->getItemGUI($item);
347  $item_list_gui2->enableIcon(true);
348 
349  if(count($chapters))
350  {
351  $num = 0;
352  $has_sections = false;
353  foreach($chapters as $chapter)
354  {
355  if($chapter['ref_id'] != $item['child'])
356  {
357  continue;
358  }
359  $has_sections = true;
360  include_once './Modules/LearningModule/classes/class.ilLMObject.php';
361 
362  $details[$num]['desc'] = $lng->txt('obj_'.$chapter['type']).' -> ';
363  $details[$num]['target'] = '_top';
364  $details[$num]['link'] = "ilias.php?baseClass=ilLMPresentationGUI&ref_id=".$chapter['ref_id'].'&obj_id='.$chapter['obj_id'];
365  $details[$num]['name'] = ilLMObject::_lookupTitle($chapter['obj_id']);
366  $num++;
367  }
368  if($has_sections)
369  {
370  $item_list_gui2->enableItemDetailLinks(true);
371  $item_list_gui2->setItemDetailLinks($details,$lng->txt('crs_suggested_sections').': ');
372  }
373  }
374 
375  if ($this->getContainerGUI()->isActiveAdministrationPanel())
376  {
377  $item_list_gui2->enableCheckbox(true);
378  if ($this->getContainerObject()->getOrderType() == ilContainer::SORT_MANUAL)
379  {
380  $item_list_gui2->setPositionInputField("[lobj][".$a_objective_id."][".$item["ref_id"]."]",
381  sprintf('%.1f', $pos));
382  $pos++;
383  }
384 
385  }
386  $this->rendered_items[$item['child']] = true;
387  $sub_item_html = $item_list_gui2->getListItemHTML($item['ref_id'],
388  $item['obj_id'], $item['title'], $item['description']);
389 
390  $this->determineAdminCommands($item["ref_id"],
391  $item_list_gui2->adminCommandsIncluded());
392  $this->objective_list_gui->addSubItemHTML($sub_item_html);
393  }
394 
395  if($this->getDetailsLevel($a_objective_id) == self::DETAILS_ALL)
396  {
397  $this->objective_list_gui->enableCommands(false);
398  }
399  else
400  {
401  $this->objective_list_gui->enableCommands(true);
402  }
403 
404  $html = $this->objective_list_gui->getListItemHTML(
405  0,
406  $a_objective_id,
407  $objective->getTitle(),
408  $objective->getDescription());
409 
410  return $html;
411  }
412 
420  protected function initDetails()
421  {
422  global $ilUser;
423 
424  if(isset($_GET['details_level']))
425  {
426  $this->details_level = (int) $_GET['details_level'];
427  ilObjUser::_writePref($ilUser->getId(),'crs_objectives_details',$this->details_level);
428  }
429  else
430  {
431  $this->details_level = $ilUser->getPref('crs_objectives_details') ? $ilUser->getPref('crs_objectives_details') : self::DETAILS_TITLE;
432  }
433  if(isset($_GET['objective_details']))
434  {
435  $this->force_details = (int) $_GET['objective_details'];
436  ilObjUser::_writePref($ilUser->getId(),'crs_objectives_force_details_'.$this->getContainerObject()->getId(),$this->force_details);
437  }
438  elseif($details_id = $ilUser->getPref('crs_objectives_force_details_'.$this->getContainerObject()->getId()))
439  {
440  $this->force_details = $details_id;
441  }
442  else
443  {
444  include_once './Modules/Course/classes/class.ilCourseObjective.php';
445  include_once('./Modules/Course/classes/class.ilCourseObjectiveResultCache.php');
446  foreach(ilCourseObjective::_getObjectiveIds($this->getContainerObject()->getId()) as $objective_id)
447  {
448  if(ilCourseObjectiveResultCache::isSuggested($ilUser->getId(),$this->getContainerObject()->getId(),$objective_id))
449  {
450  $this->force_details = $objective_id;
451  break;
452  }
453  }
454  }
455  return true;
456  }
457 
465  protected function showButton($a_cmd,$a_text,$a_target = '')
466  {
467  global $tpl,$ilCtrl;
468 
469  $tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
470 
471  // display button
472  $tpl->setCurrentBlock("btn_cell");
473  $tpl->setVariable("BTN_LINK",$ilCtrl->getLinkTarget($this->getContainerGUI(),$a_cmd));
474  $tpl->setVariable("BTN_TXT",$a_text);
475 
476  if($a_target)
477  {
478  $tpl->setVariable("BTN_TARGET",$a_target);
479  }
480 
481  $tpl->parseCurrentBlock();
482  }
483 }
484 ?>