ILIAS  Release_4_0_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 
49  public function __construct($a_container_gui)
50  {
51  global $lng;
52 
53  $this->lng = $lng;
54  parent::__construct($a_container_gui);
55 
56  $this->initDetails();
57  }
58 
66  public function getDetailsLevel($a_objective_id)
67  {
68  if($a_objective_id == $this->force_details)
69  {
70  return self::DETAILS_ALL;
71  }
72  return $this->details_level;
73  }
74 
81  public function getMainContent()
82  {
83  global $lng,$ilTabs,$ilAccess;
84 
85  $ilTabs->setSubTabActive($this->getContainerObject()->getType().'_content');
86 
87 
88  include_once './classes/class.ilObjectListGUIFactory.php';
89 
90  $tpl = new ilTemplate ("tpl.container_page.html", true, true,"Services/Container");
91 
92  // Feedback
93  // @todo
94 // $this->__showFeedBack();
95 
96  if($ilAccess->checkAccess('write','',$this->getContainerObject()->getRefId()) or 1)
97  {
98  $this->showButton('askReset',$lng->txt('crs_reset_results'));
99  }
100 
101  $this->items = $this->getContainerObject()->getSubItems($this->getContainerGUI()->isActiveAdministrationPanel());
102 
103  $this->showStatus($tpl);
104  $this->showObjectives($tpl);
105  $this->showMaterials($tpl,self::MATERIALS_TESTS);
106  $this->showMaterials($tpl,self::MATERIALS_OTHER);
107 
108  // @todo: Move this completely to GUI class?
109 /* $this->getContainerGUI()->adminCommands = $this->adminCommands;
110  $this->getContainerGUI()->showAdministrationPanel($tpl);
111  $this->getContainerGUI()->showPossibleSubObjects();
112  $this->getContainerGUI()->showPermanentLink($tpl);*/
113 
114  return $tpl->get();
115  }
116 
124  public function showStatus($tpl)
125  {
126  global $ilUser,$lng;
127 
128  include_once('./Modules/Course/classes/class.ilCourseObjectiveResultCache.php');
129 
130  $tpl->setCurrentBlock('cont_page_content');
131 
132  $status = ilCourseObjectiveResultCache::getStatus($ilUser->getId(),$this->getContainerObject()->getId());
133  if($status == IL_OBJECTIVE_STATUS_EMPTY) {
134  return;
135  }
136  $info_tpl = new ilTemplate('tpl.crs_objectives_view_info_table.html',true,true,'Modules/Course');
137  $info_tpl->setVariable("INFO_STRING",$lng->txt('crs_objectives_info_'.$status));
138  $info_tpl->setVariable("IMG_INFO", ilUtil::getImagePath("mess_info.gif"));
139 // ilUtil::sendInfo($this->lng->txt('crs_objectives_info_'.$status));
140 
141  $tpl->setVariable('CONTAINER_PAGE_CONTENT',$info_tpl->get());
142  $tpl->parseCurrentBlock();
143 
144  }
145 
153  public function showObjectives($a_tpl)
154  {
155  global $lng,$ilSetting;
156 
158  $output_html = $this->getContainerGUI()->getContainerPageHTML();
159 
160  // get embedded blocks
161  if ($output_html != "")
162  {
163  $output_html = $this->insertPageEmbeddedBlocks($output_html);
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 
205  $output_html .= $tpl->get();
206  $a_tpl->setCurrentBlock('cont_page_content');
207  $a_tpl->setVariable("CONTAINER_PAGE_CONTENT", $output_html);
208  $a_tpl->parseCurrentBlock();
209 
210 
211  }
212 
220  public function addFooterRow($tpl)
221  {
222  $tpl->setCurrentBlock('details_img');
223 
224  $append = $this->details_level == self::DETAILS_TITLE ? 'off' : '';
225  $tpl->setCurrentBlock('details_img');
226  $tpl->setVariable('DETAILS_SRC',ilUtil::getImagePath('details2'.$append.'.gif'));
227  $tpl->setVariable('DETAILS_ALT',$this->lng->txt('details').' 2');
228  $tpl->setVariable('DETAILS_LINK','repository.php?ref_id='.$this->getContainerObject()->getRefId().'&details_level=1');
229  $tpl->parseCurrentBlock();
230 
231  $append = $this->details_level == self::DETAILS_ALL ? 'off' : '';
232  $tpl->setCurrentBlock('details_img');
233  $tpl->setVariable('DETAILS_SRC',ilUtil::getImagePath('details3'.$append.'.gif'));
234  $tpl->setVariable('DETAILS_ALT',$this->lng->txt('details').' 3');
235  $tpl->setVariable('DETAILS_LINK','repository.php?ref_id='.$this->getContainerObject()->getRefId().'&details_level=2');
236  $tpl->parseCurrentBlock();
237 
238  $tpl->setCurrentBlock('container_details_row');
239  $tpl->setVariable('TXT_DETAILS',$this->lng->txt('details'));
240  $tpl->parseCurrentBlock();
241  }
242 
243 
244 
252  public function showMaterials($a_tpl,$a_mode)
253  {
254  global $ilAccess, $lng;
255 
257 
258  #$output_html = $this->getContainerGUI()->getContainerPageHTML();
259  $output_html = '';
260 
261  // get embedded blocks
262  if ($output_html != "")
263  {
264  $output_html = $this->insertPageEmbeddedBlocks($output_html);
265  }
266 
267  $tpl = $this->newBlockTemplate();
268  if (is_array($this->items["_all"]))
269  {
270  // all rows
271  $item_r = array();
272 
273  $position = 1;
274  foreach($this->items["_all"] as $k => $item_data)
275  {
276  if($a_mode == self::MATERIALS_TESTS and $item_data['type'] != 'tst')
277  {
278  continue;
279  }
280 
281  if($this->rendered_items[$item_data["child"]] !== true)
282  {
283  $this->rendered_items[$item_data['child']] = true;
284 
285  // TODO: Position (DONE ?)
286  $html = $this->renderItem($item_data,$position++,$a_mode == self::MATERIALS_TESTS ? false : true);
287  if ($html != "")
288  {
289  $item_r[] = array("html" => $html, "id" => $item_data["child"]);
290  }
291  }
292  }
293 
294  // if we have at least one item, output the block
295  if (count($item_r) > 0)
296  {
297  switch($a_mode)
298  {
299  case self::MATERIALS_TESTS:
300  $txt = $lng->txt('objs_tst');
301  break;
302 
303  case self::MATERIALS_OTHER:
304  $txt = $lng->txt('crs_other_resources');
305  break;
306  }
307 
308  $this->addHeaderRow($tpl,$a_mode == self::MATERIALS_TESTS ? 'tst' : '',$txt);
309  foreach($item_r as $h)
310  {
311  $this->addStandardRow($tpl, $h["html"], $h["id"]);
312  }
313  }
314  }
315 
316  $output_html .= $tpl->get();
317  $a_tpl->setCurrentBlock('cont_page_content');
318  $a_tpl->setVariable("CONTAINER_PAGE_CONTENT", $output_html);
319  $a_tpl->parseCurrentBlock();
320  }
321 
329  protected function renderObjective($a_objective_id)
330  {
331  global $ilUser,$lng;
332 
333  include_once('./Modules/Course/classes/class.ilCourseObjective.php');
334  $objective = new ilCourseObjective($this->getContainerObject(),$a_objective_id);
335 
336  include_once('./Services/Container/classes/class.ilContainerSorting.php');
337  $items = $this->getContainerObject()->getCourseItemObject()->getItemsByObjective($a_objective_id);
338  $items = ilContainerSorting::_getInstance($this->getContainerObject()->getId())->sortSubItems('lobj',$a_objective_id,$items);
339 
340  include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
341  $objectives_lm_obj = new ilCourseObjectiveMaterials($a_objective_id);
342 
343  $pos = 1;
344  foreach($items as $item)
345  {
346  if($this->getDetailsLevel($a_objective_id) < self::DETAILS_ALL)
347  {
348  continue;
349  }
350 
351  $chapters = $objectives_lm_obj->getChapters();
352 
353  $item_list_gui2 = $this->getItemGUI($item);
354  $item_list_gui2->enableIcon(true);
355 
356  if(count($chapters))
357  {
358  $num = 0;
359  $has_sections = false;
360  foreach($chapters as $chapter)
361  {
362  if($chapter['ref_id'] != $item['child'])
363  {
364  continue;
365  }
366  $has_sections = true;
367  include_once './Modules/LearningModule/classes/class.ilLMObject.php';
368 
369  $details[$num]['desc'] = $lng->txt('obj_'.$chapter['type']).' -> ';
370  $details[$num]['target'] = '_top';
371  $details[$num]['link'] = "ilias.php?baseClass=ilLMPresentationGUI&ref_id=".$chapter['ref_id'].'&obj_id='.$chapter['obj_id'];
372  $details[$num]['name'] = ilLMObject::_lookupTitle($chapter['obj_id']);
373  $num++;
374  }
375  if($has_sections)
376  {
377  $item_list_gui2->enableItemDetailLinks(true);
378  $item_list_gui2->setItemDetailLinks($details,$lng->txt('crs_suggested_sections').': ');
379  }
380  }
381 
382  if ($this->getContainerGUI()->isActiveAdministrationPanel())
383  {
384  $item_list_gui2->enableCheckbox(true);
385  if ($this->getContainerObject()->getOrderType() == ilContainer::SORT_MANUAL)
386  {
387  $item_list_gui2->setPositionInputField("[lobj][".$a_objective_id."][".$item["ref_id"]."]",
388  sprintf('%.1f', $pos));
389  $pos++;
390  }
391 
392  }
393  $this->rendered_items[$item['child']] = true;
394  $sub_item_html = $item_list_gui2->getListItemHTML($item['ref_id'],
395  $item['obj_id'], $item['title'], $item['description']);
396 
397  $this->determineAdminCommands($item["ref_id"],
398  $item_list_gui2->adminCommandsIncluded());
399  $this->objective_list_gui->addSubItemHTML($sub_item_html);
400  }
401 
402  if($this->getDetailsLevel($a_objective_id) == self::DETAILS_ALL)
403  {
404  $this->objective_list_gui->enableCommands(false);
405  }
406  else
407  {
408  $this->objective_list_gui->enableCommands(true);
409  }
410 
411  $html = $this->objective_list_gui->getListItemHTML(
412  0,
413  $a_objective_id,
414  $objective->getTitle(),
415  $objective->getDescription());
416 
417  return $html;
418  }
419 
427  protected function initDetails()
428  {
429  global $ilUser;
430 
431  if(isset($_GET['details_level']))
432  {
433  $this->details_level = (int) $_GET['details_level'];
434  ilObjUser::_writePref($ilUser->getId(),'crs_objectives_details',$this->details_level);
435  }
436  else
437  {
438  $this->details_level = $ilUser->getPref('crs_objectives_details') ? $ilUser->getPref('crs_objectives_details') : self::DETAILS_TITLE;
439  }
440  if(isset($_GET['objective_details']))
441  {
442  $this->force_details = (int) $_GET['objective_details'];
443  ilObjUser::_writePref($ilUser->getId(),'crs_objectives_force_details_'.$this->getContainerObject()->getId(),$this->force_details);
444  }
445  elseif($details_id = $ilUser->getPref('crs_objectives_force_details_'.$this->getContainerObject()->getId()))
446  {
447  $this->force_details = $details_id;
448  }
449  else
450  {
451  include_once './Modules/Course/classes/class.ilCourseObjective.php';
452  include_once('./Modules/Course/classes/class.ilCourseObjectiveResultCache.php');
453  foreach(ilCourseObjective::_getObjectiveIds($this->getContainerObject()->getId()) as $objective_id)
454  {
455  if(ilCourseObjectiveResultCache::isSuggested($ilUser->getId(),$this->getContainerObject()->getId(),$objective_id))
456  {
457  $this->force_details = $objective_id;
458  break;
459  }
460  }
461  }
462  return true;
463  }
464 
472  protected function showButton($a_cmd,$a_text,$a_target = '')
473  {
474  global $tpl,$ilCtrl;
475 
476  $tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
477 
478  // display button
479  $tpl->setCurrentBlock("btn_cell");
480  $tpl->setVariable("BTN_LINK",$ilCtrl->getLinkTarget($this->getContainerGUI(),$a_cmd));
481  $tpl->setVariable("BTN_TXT",$a_text);
482 
483  if($a_target)
484  {
485  $tpl->setVariable("BTN_TARGET",$a_target);
486  }
487 
488  $tpl->parseCurrentBlock();
489  }
490 }
491 ?>