ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseObjectivesTableGUI.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 include_once('./Services/Table/classes/class.ilTable2GUI.php');
25 include_once './Modules/Course/classes/class.ilCourseObjective.php';
26 include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
27 include_once('./Modules/Course/classes/class.ilCourseObjectiveQuestion.php');
28 include_once './Modules/Course/classes/Objectives/class.ilLOUtils.php';
29 
30 // begin-patch lok
31 include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
32 // end-patch lok
33 
42 {
43  protected $course_obj = null;
44 
45  // begin-patch lok
46  protected $settings = NULL;
47  // end-patch lok
48 
56  public function __construct($a_parent_obj,$a_course_obj)
57  {
58  global $lng,$ilCtrl;
59 
60  $this->course_obj = $a_course_obj;
61 
62  // begin-patch lok
63  $this->settings = ilLOSettings::getInstanceByObjId($this->course_obj->getId());
64  // end-patch lok
65 
66  $this->lng = $lng;
67  $this->lng->loadLanguageModule('crs');
68  $this->ctrl = $ilCtrl;
69 
70  parent::__construct($a_parent_obj,'listObjectives');
71  $this->setFormName('objectives');
72  $this->addColumn('','f',"1px");
73  $this->addColumn($this->lng->txt('position'),'position','10em');
74  $this->addColumn($this->lng->txt('title'),'title','20%');
75  $this->addColumn($this->lng->txt('crs_objective_assigned_materials'),'materials');
76  // begin-patch lok
77  if($this->getSettings()->worksWithInitialTest())
78  {
79  $this->addColumn($this->lng->txt('crs_objective_self_assessment'),'self');
80  }
81  // end-patch lok
82  $this->addColumn($this->lng->txt('crs_objective_final_test'),'final');
83  $this->addColumn($this->lng->txt(''),'5em');
84 
85  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
86  $this->setRowTemplate("tpl.crs_objectives_table_row.html","Modules/Course");
87  $this->disable('sort');
88  $this->enable('header');
89  $this->disable('numinfo');
90  $this->enable('select_all');
91  // begin-patch lok
92  $this->setSelectAllCheckbox('objective');
93  // end-patch lok
94  $this->setLimit(200);
95 
96  // begin-patch lo
97  $this->addMultiCommand('activateObjectives', $this->lng->txt('set_online'));
98  $this->addMultiCommand('deactivateObjectives', $this->lng->txt('set_offline'));
99  $this->addMultiCommand('askDeleteObjectives',$this->lng->txt('delete'));
100  // end-patch lok
101  $this->addCommandButton('saveSorting',$this->lng->txt('sorting_save'));
102  // $this->addCommandButton('create',$this->lng->txt('crs_add_objective'));
103  }
104 
105  // begin-patch lok
110  public function getSettings()
111  {
112  return $this->settings;
113  }
114  // end-patch lok
115 
116 
124  protected function fillRow($a_set)
125  {
126  $this->tpl->setVariable('VAL_ID',$a_set['id']);
127  $this->tpl->setVariable('VAL_POSITION',$a_set['position']);
128 
129  // begin-patch lok
130  if($a_set['online'])
131  {
132  $this->tpl->setVariable('VAL_ONOFFLINE',$this->lng->txt('online'));
133  $this->tpl->setVariable('ONOFFLINE_CLASS','smallgreen');
134  }
135  else
136  {
137  $this->tpl->setVariable('VAL_ONOFFLINE',$this->lng->txt('offline'));
138  $this->tpl->setVariable('ONOFFLINE_CLASS','smallred');
139  }
140 
141  if($a_set['passes'])
142  {
143  $this->tpl->setVariable('PASSES_TXT',$this->lng->txt('crs_loc_passes_info'));
144  $this->tpl->setVariable('PASSES_VAL',$a_set['passes']);
145  }
146 
147 
148  // begin-patch lok
149  $this->ctrl->setParameterByClass('ilcourseobjectivesgui','objective_id',$a_set['id']);
150  $this->tpl->setVariable('VAL_TITLE_LINKED',$this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui','edit'));
151  // end-patch lok
152 
153  $this->tpl->setVariable('VAL_TITLE',$a_set['title']);
154  if(strlen($a_set['description']))
155  {
156  $this->tpl->setVariable('VAL_DESC',$a_set['description']);
157  }
158 
159  // materials
160  foreach($a_set['materials'] as $ref_id => $data)
161  {
162  if($data['items'])
163  {
164  $this->tpl->touchBlock('ul_begin');
165  foreach($data['items'] as $pg_st)
166  {
167  $this->tpl->setCurrentBlock('st_pg');
168  $this->tpl->setVariable('MAT_IMG',ilObject::_getIcon($pg_st['obj_id'],"tiny", $pg_st['type']));
169  $this->tpl->setVariable('MAT_ALT',$this->lng->txt('obj_'.$pg_st['type']));
170  include_once('Modules/LearningModule/classes/class.ilLMObject.php');
171  $title = ilLMObject::_lookupTitle($pg_st['obj_id']);
172  $this->tpl->setVariable('MAT_TITLE',$title);
173  $this->tpl->parseCurrentBlock();
174  }
175  $this->tpl->touchBlock('ul_end');
176  }
177  else
178  {
179  $this->tpl->touchBlock('new_line');
180  }
181  $this->tpl->setCurrentBlock('mat_row');
182  $this->tpl->setVariable('LM_IMG',ilObject::_getIcon($data['obj_id'],"tiny", $data['type']));
183  $this->tpl->setVariable('LM_ALT',$this->lng->txt('obj_'.$data['type']));
184 
185  if($data['type'] == 'catr' or $data['type'] == 'crsr')
186  {
187  include_once './Services/ContainerReference/classes/class.ilContainerReference.php';
188  $this->tpl->setVariable(
189  'LM_TITLE',
191  );
192  }
193  else
194  {
195  $this->tpl->setVariable('LM_TITLE',ilObject::_lookupTitle($data['obj_id']));
196  }
197  $this->tpl->parseCurrentBlock();
198  }
199 
200  // self assessment
201  // begin-patch lok
202  if($this->getSettings()->worksWithInitialTest())
203  {
204  foreach($a_set['self'] as $test)
205  {
206  // begin-patch lok
207  foreach((array) $test['questions'] as $question)
208  {
209  $this->tpl->setCurrentBlock('self_qst_row');
210  $this->tpl->setVariable('SELF_QST_TITLE',$question['title']);
211  $this->tpl->parseCurrentBlock();
212  }
213  #$this->tpl->setCurrentBlock('self_test_row');
214  #$this->tpl->setVariable('SELF_TST_ALT',$this->lng->txt('obj_tst'));
215  #$this->tpl->setVariable('SELF_TST_TITLE',ilObject::_lookupTitle($test['obj_id']));
216  #$this->tpl->parseCurrentBlock();
217  // end-patch lok
218  }
219  // begin-patch lok
220  if(!count($a_set['self']))
221  {
222  $this->tpl->touchBlock('self_qst_row');
223  }
224  // end-patch lok
225  }
226  // end-patch lok
227 
228  // final test questions
229  foreach((array) $a_set['final'] as $test)
230  {
231  foreach((array) $test['questions'] as $question)
232  {
233  $this->tpl->setCurrentBlock('final_qst_row');
234  $this->tpl->setVariable('FINAL_QST_TITLE',$question['title']);
235  $this->tpl->parseCurrentBlock();
236  }
237  // begin-patch lok
238  #$this->tpl->setCurrentBlock('final_test_row');
239  #$this->tpl->setVariable('FINAL_TST_ALT',$this->lng->txt('obj_tst'));
240  #$this->tpl->setVariable('FINAL_TST_TITLE',ilObject::_lookupTitle($test['obj_id']));
241  #$this->tpl->parseCurrentBlock();
242  // end-patch lok
243  }
244 
245  // begin-patch lok
246  // Edit Link
247  #$this->ctrl->setParameterByClass(get_class($this->getParentObject()),'objective_id',$a_set['id']);
248  $this->ctrl->setParameterByClass('ilcourseobjectivesgui','objective_id',$a_set['id']);
249  #$this->tpl->setVariable('EDIT_LINK',$this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()),'edit'));
250  $this->tpl->setVariable('EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui','edit'));
251  // end-patch lok
252  $this->tpl->setVariable('TXT_EDIT',$this->lng->txt('edit'));
253 
254  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
255  $alist = new ilAdvancedSelectionListGUI();
256  $alist->setId($a_set['id']);
257  $alist->setListTitle($this->lng->txt("actions"));
258 
259  $alist->addItem(
260  $this->lng->txt('edit'),
261  '',
262  $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'edit')
263  );
264  // materials
265  $alist->addItem(
266  $this->lng->txt('crs_objective_action_materials'),
267  '',
268  $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'materialAssignment')
269  );
270  // itest
271  if($this->getSettings()->worksWithInitialTest())
272  {
273  $alist->addItem(
274  $this->lng->txt('crs_objective_action_itest'),
275  '',
276  $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'selfAssessmentAssignment')
277  );
278  }
279  // qtest
280  $alist->addItem(
281  $this->lng->txt('crs_objective_action_qtest'),
282  '',
283  $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'finalTestAssignment')
284  );
285 
286  if($this->getSettings()->isQualifiedTestPerObjectiveVisible())
287  {
288  $this->ctrl->setParameterByClass('ilconditionhandlerinterface','objective_id',$a_set['id']);
289  $alist->addItem(
290  $this->lng->txt('preconditions'),
291  '',
292  $this->ctrl->getLinkTargetByClass('ilconditionhandlerinterface','listConditions')
293  );
294  }
295 
296  $this->ctrl->setParameterByClass('illopagegui','objective_id',$a_set['id']);
297  $alist->addItem(
298  $this->lng->txt('edit_page'),
299  '',
300  $this->ctrl->getLinkTargetByClass('illopagegui', 'edit')
301  );
302 
303 
304  $this->tpl->setVariable('VAL_ACTIONS',$alist->getHTML());
305 
306  // end-patch lok
307  }
308 
309 
316  public function parse($a_objective_ids)
317  {
318  $position = 1;
319  foreach($a_objective_ids as $objective_id)
320  {
321  $objective = new ilCourseObjective($this->course_obj,$objective_id);
322 
323  $objective_data['id'] = $objective_id;
324  $objective_data['position'] = sprintf("%.1f",$position++) * 10;
325  $objective_data['title'] = $objective->getTitle();
326  $objective_data['description'] = $objective->getDescription();
327 
328  // begin-patch lok
329  $objective_data['online'] = $objective->isActive();
330  $objective_data['passes'] = $objective->getPasses();
331  // end-patch lok
332 
333  // assigned materials
334  $materials = array();
335  $ass_materials = new ilCourseObjectiveMaterials($objective_id);
336  foreach($ass_materials->getMaterials() as $material)
337  {
338  $materials[$material['ref_id']]['obj_id'] = $obj_id = ilObject::_lookupObjId($material['ref_id']);
339  $materials[$material['ref_id']]['type'] = ilObject::_lookupType($obj_id);
340 
341  switch($material['type'])
342  {
343  case 'pg':
344  case 'st':
345  $materials[$material['ref_id']]['items'][] = $material;
346  break;
347  default:
348 
349  }
350 
351 
352  }
353  $objective_data['materials'] = $materials;
354  $question_obj = new ilCourseObjectiveQuestion($objective_id);
355 
356  // self assessment questions
357  // begin-patch lok
358  if($this->getSettings()->worksWithInitialTest())
359  {
360  if(ilLOUtils::lookupRandomTest(ilObject::_lookupObjId($this->getSettings()->getInitialTest())))
361  {
362  $test = array();
363  include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
364  $rnd = new ilLORandomTestQuestionPools(
365  $this->course_obj->getId(),
366  $objective_id,
368  );
369  $test['obj_id'] = ilObject::_lookupObjId($this->getSettings()->getInitialTest());
370  $qst = ilLOUtils::lookupQplBySequence($this->getSettings()->getInitialTest(), $rnd->getQplSequence());
371  if($qst)
372  {
373  $test['questions'][] = array('title' => $qst);
374  }
375  $objective_data['self'] = array($test);
376  }
377  else
378  {
379  $tests = array();
380  foreach($question_obj->getSelfAssessmentTests() as $test)
381  {
382  $questions = array();
383  foreach($question_obj->getQuestionsOfTest($test['obj_id']) as $qst)
384  {
385  $questions[] = $qst;
386  }
387  $tmp_test = $test;
388  $tmp_test['questions'] = $questions;
389 
390  $tests[] = $tmp_test;
391  }
392  $objective_data['self'] = $tests;
393  }
394  }
395  // end-patch lok
396 
397  // final test questions
398  // begin-patch lok
399  if($this->getSettings()->getQualifiedTest())
400  {
401  if(ilLOUtils::lookupRandomTest(ilObject::_lookupObjId($this->getSettings()->getQualifiedTest())))
402  {
403  $test = array();
404  include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
405  $rnd = new ilLORandomTestQuestionPools(
406  $this->course_obj->getId(),
407  $objective_id,
409  );
410  $test['obj_id'] = ilObject::_lookupObjId($this->getSettings()->getQualifiedTest());
411  $qst = ilLOUtils::lookupQplBySequence($this->getSettings()->getQualifiedTest(), $rnd->getQplSequence());
412  if($qst)
413  {
414  $test['questions'][] = array('title' => $qst);
415  }
416  $objective_data['final'] = array($test);
417  }
418  else
419  {
420  $tests = array();
421  foreach($question_obj->getFinalTests() as $test)
422  {
423  $questions = array();
424  foreach($question_obj->getQuestionsOfTest($test['obj_id']) as $qst)
425  {
426  $questions[] = $qst;
427  }
428  $tmp_test = $test;
429  $tmp_test['questions'] = $questions;
430 
431  $tests[] = $tmp_test;
432  }
433  $objective_data['final'] = $tests;
434  }
435 
436  }
437  // end-patch lok
438  $objectives[] = (array) $objective_data;
439  }
440  $this->setData($objectives ? $objectives : array());
441  }
442 
443 }
444 ?>