ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLOTestAssignmentTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
5 include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
6 include_once './Services/Table/classes/class.ilTable2GUI.php';
7 include_once './Modules/Course/exceptions/class.ilLOInvalidConfiguationException.php';
8 
18 {
21 
22  private $test_type = 0;
23  private $assignment_type = self::TYPE_SINGLE_ASSIGNMENTS;
24  private $settings = NULL;
25  private $container_id = 0;
26 
27 
34  public function __construct($a_parent_obj, $a_parent_cmd, $a_container_id, $a_test_type, $a_assignment_type = self::TYPE_SINGLE_ASSIGNMENTS)
35  {
36  $this->test_type = $a_test_type;
37  $this->assignment_type = $a_assignment_type;
38  $this->container_id = $a_container_id;
39 
40  $this->setId('obj_loc_'.$a_container_id);
41  parent::__construct($a_parent_obj, $a_parent_cmd);
42 
43  $this->settings = ilLOSettings::getInstanceByObjId($a_container_id);
44  $this->initTitle();
45  $this->setTopCommands(FALSE);
46 
47  }
48 
49  public function initTitle()
50  {
51  switch($this->test_type)
52  {
54  if($this->getAssignmentType() == self::TYPE_SINGLE_ASSIGNMENTS)
55  {
56  if($this->getSettings()->isInitialTestQualifying())
57  {
58  $this->setTitle($this->lng->txt('crs_loc_settings_tbl_its_q_all'));
59  }
60  else
61  {
62  $this->setTitle($this->lng->txt('crs_loc_settings_tbl_its_nq_all'));
63  }
64  }
65  else
66  {
67  if($this->getSettings()->isInitialTestQualifying())
68  {
69  $this->setTitle($this->lng->txt('crs_loc_settings_tbl_it_q'));
70  }
71  else
72  {
73  $this->setTitle($this->lng->txt('crs_loc_settings_tbl_it_nq'));
74  }
75  }
76  break;
77 
78 
80  if($this->getAssignmentType() == self::TYPE_SINGLE_ASSIGNMENTS)
81  {
82  $this->setTitle($this->lng->txt('crs_loc_settings_tbl_qts_all'));
83  }
84  else
85  {
86  $this->setTitle($this->lng->txt('crs_loc_settings_tbl_qt'));
87  }
88  break;
89  }
90  }
91 
96  public function getSettings()
97  {
98  return $this->settings;
99  }
100 
101  public function getAssignmentType()
102  {
103  return $this->assignment_type;
104  }
105 
109  public function init()
110  {
111  $this->addColumn('','', '20px');
112  $this->addColumn($this->lng->txt('title'),'title');
113 
114  if($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS)
115  {
116  $this->addColumn($this->lng->txt('crs_objectives'), 'objective');
117  }
118 
119  $this->addColumn($this->lng->txt('crs_loc_tbl_tst_type'),'ttype');
120  $this->addColumn($this->lng->txt('crs_loc_tbl_tst_qst_qpl'),'qstqpl');
121 
122 
123  $this->setRowTemplate("tpl.crs_loc_tst_row.html","Modules/Course");
124  $this->setFormAction($GLOBALS['ilCtrl']->getFormAction($this->getParentObject()));
125 
126  if($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS)
127  {
128  $this->addMultiCommand('confirmDeleteTests', $this->lng->txt('crs_loc_delete_assignment'));
129  $this->setDefaultOrderField('objective');
130  $this->setDefaultOrderDirection('asc');
131  }
132  else
133  {
134  $this->addMultiCommand('confirmDeleteTest', $this->lng->txt('crs_loc_delete_assignment'));
135  $this->setDefaultOrderField('title');
136  $this->setDefaultOrderDirection('asc');
137  }
138  }
139 
144  public function fillRow($set)
145  {
146  global $ilCtrl;
147 
148  if($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS)
149  {
150  $this->tpl->setVariable('VAL_ID',$set['assignment_id']);
151  }
152  else
153  {
154  $this->tpl->setVariable('VAL_ID',$set['ref_id']);
155  }
156  $this->tpl->setVariable('VAL_TITLE',$set['title']);
157  include_once './Services/Link/classes/class.ilLink.php';
158 
159  $ilCtrl->setParameterByClass('ilobjtestgui','ref_id',$set['ref_id']);
160  $ilCtrl->setParameterByClass('ilobjtestgui','cmd','questionsTabGateway');
161  $this->tpl->setVariable(
162  'TITLE_LINK',
163  $ilCtrl->getLinkTargetByClass('ilobjtestgui')
164  );
165 
166  if($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS)
167  {
168  $this->tpl->setCurrentBlock('objectives');
169  $this->tpl->setVariable('VAL_OBJECTIVE',(string) $set['objective']);
170  $this->tpl->parseCurrentBlock();
171  }
172 
173 
174 
175  #$this->tpl->setVariable('TITLE_LINK',ilLink::_getLink($set['ref_id']));
176  if(strlen($set['description']))
177  {
178  $this->tpl->setVariable('VAL_DESC',$set['description']);
179  }
180 
181  switch($set['ttype'])
182  {
184  $type = $this->lng->txt('tst_question_set_type_fixed');
185  break;
186 
188  $type = $this->lng->txt('tst_question_set_type_random');
189  break;
190  }
191 
192  $this->tpl->setVariable('VAL_TTYPE',$type);
193  $this->tpl->setVariable('VAL_QST_QPL',$set['qst_info']);
194 
195  if(count($set['qpls']))
196  {
197  foreach($set['qpls'] as $title)
198  {
199  $this->tpl->setCurrentBlock('qpl');
200  $this->tpl->setVariable('MAT_TITLE',$title);
201  $this->tpl->parseCurrentBlock();
202  }
203  $this->tpl->touchBlock('ul_begin');
204  $this->tpl->touchBlock('ul_end');
205  }
206  }
207 
208  public function parseMultipleAssignments()
209  {
210  include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
211  $assignments = ilLOTestAssignments::getInstance($this->container_id);
212 
213  $available = $assignments->getAssignmentsByType($this->test_type);
214  $data = array();
215  foreach($available as $assignment)
216  {
217  try
218  {
219  $tmp = $this->doParse($assignment->getTestRefId(),$assignment->getObjectiveId());
220  }
222  {
223  $assignment->delete();
224  continue;
225  }
226  if($tmp)
227  {
228  // add assignment id
229  $tmp['assignment_id'] = $assignment->getAssignmentId();
230  $data[] = $tmp;
231  }
232  }
233 
234  $this->setData($data);
235  }
236 
242  public function parse($a_tst_ref_id)
243  {
244  $this->setData(array($this->doParse($a_tst_ref_id)));
245  return TRUE;
246  }
247 
252  protected function doParse($a_tst_ref_id, $a_objective_id = 0)
253  {
254  include_once './Modules/Test/classes/class.ilObjTest.php';
255  $tst = ilObjectFactory::getInstanceByRefId($a_tst_ref_id,false);
256 
257  if(!$tst instanceof ilObjTest)
258  {
259  throw new ilLOInvalidConfigurationException('No valid test given');
260  }
261  $tst_data['ref_id'] = $tst->getRefId();
262  $tst_data['title'] = $tst->getTitle();
263  $tst_data['description'] = $tst->getLongDescription();
264  $tst_data['ttype'] = $tst->getQuestionSetType();
265 
266 
267  if($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS)
268  {
269  include_once './Modules/Course/classes/class.ilCourseObjective.php';
270  $tst_data['objective'] = ilCourseObjective::lookupObjectiveTitle($a_objective_id);
271  }
272 
273  switch($tst->getQuestionSetType())
274  {
276  $tst_data['qst_info'] = $this->lng->txt('crs_loc_tst_num_qst');
277  $tst_data['qst_info'] .= (' ' . count($tst->getAllQuestions()));
278  break;
279 
280  default:
281  // get available assiged question pools
282  include_once './Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
283  include_once './Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
284 
286  $GLOBALS['ilDB'],
287  $tst,
289  $GLOBALS['ilDB'],
290  $tst
291  )
292  );
293 
294  $list->loadDefinitions();
295 
296  // tax translations
297  include_once './Modules/Test/classes/class.ilTestTaxonomyFilterLabelTranslater.php';
298  $translater = new ilTestTaxonomyFilterLabelTranslater($GLOBALS['ilDB']);
299  $translater->loadLabels($list);
300 
301  $tst_data['qst_info'] = $this->lng->txt('crs_loc_tst_qpls');
302  $num = 0;
303  foreach ($list as $definition)
304  {
306  $title = $definition->getPoolTitle();
307  $tax_id = $definition->getMappedFilterTaxId();
308  if($tax_id)
309  {
310  $title .= (' -> '. $translater->getTaxonomyTreeLabel($tax_id));
311  }
312  $tax_node = $definition->getMappedFilterTaxNodeId();
313  if($tax_node)
314  {
315  $title .= (' -> ' .$translater->getTaxonomyNodeLabel($tax_node));
316  }
317  $tst_data['qpls'][] = $title;
318  ++$num;
319  }
320  if(!$num)
321  {
322  $tst_data['qst_info'] .= (' '. (int) 0);
323  }
324  break;
325  }
326  return $tst_data;
327  }
328 }
329 ?>
static getInstanceByObjId($a_obj_id)
get singleton instance
static getInstance($a_container_id)
Get instance by container id.
static lookupObjectiveTitle($a_objective_id, $a_add_description=false)
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
const QUESTION_SET_TYPE_RANDOM
type setting value for random question set
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getParentObject()
Get parent object.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
__construct($a_parent_obj, $a_parent_cmd, $a_container_id, $a_test_type, $a_assignment_type=self::TYPE_SINGLE_ASSIGNMENTS)
Constructor.
setTopCommands($a_val)
Set top commands (display command buttons on top of table, too)
Class ilTable2GUI.
Class ilLOTestAssignmentTableGUI.
addMultiCommand($a_cmd, $a_text)
Add Command button.
Class ilLOInvalidConfigurationException.
getFormAction()
Get Form action parameter.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
settings()
Definition: settings.php:2
const QUESTION_SET_TYPE_FIXED
type setting value for fixed question set
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
parse($a_tst_ref_id)
Parse single test assignment.
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.