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