ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestResultHeaderLabelBuilder.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
12 {
13  const LO_TEST_TYPE_INITIAL = 'loTestInitial';
14  const LO_TEST_TYPE_QUALIFYING = 'loTestQualifying';
18  protected $lng;
19 
23  protected $objCache;
24 
29 
33  protected $testObjId;
34 
38  protected $testRefId;
39 
43  protected $userId;
44 
48  protected $crsTitle;
49 
53  protected $testType;
54 
58  protected $objectives;
59 
65  {
66  $this->lng = $lng;
67  $this->objCache = $objCache;
68 
69  $this->objectiveOrientedContainerId = null;
70  $this->testObjId = null;
71  $this->testRefId = null;
72  $this->userId = null;
73 
74  $this->testType = null;
75  $this->crsTitle = null;
76 
77  $this->objectives = array();
78  }
79 
84  {
86  }
87 
92  {
93  $this->objectiveOrientedContainerId = $objectiveOrientedContainerId;
94  }
95 
99  public function getTestObjId()
100  {
101  return $this->testObjId;
102  }
103 
107  public function setTestObjId($testObjId)
108  {
109  $this->testObjId = $testObjId;
110  }
111 
115  public function getTestRefId()
116  {
117  return $this->testRefId;
118  }
119 
123  public function setTestRefId($testRefId)
124  {
125  $this->testRefId = $testRefId;
126  }
127 
131  public function getUserId()
132  {
133  return $this->userId;
134  }
135 
139  public function setUserId($userId)
140  {
141  $this->userId = $userId;
142  }
143 
144  public function initObjectiveOrientedMode()
145  {
146  $this->initTestType();
147  $this->initObjectives();
148  $this->initCourseTitle();
149  }
150 
151  private function initTestType()
152  {
153  require_once 'Modules/Course/classes/Objectives/class.ilLOSettings.php';
155 
156  if( $loSettings->getInitialTest() == $this->getTestRefId() )
157  {
158  $this->testType = self::LO_TEST_TYPE_INITIAL;
159  }
160  elseif( $loSettings->getQualifiedTest() == $this->getTestRefId() )
161  {
162  $this->testType = self::LO_TEST_TYPE_QUALIFYING;
163  }
164  }
165 
166  private function initObjectives()
167  {
168  require_once 'Modules/Course/classes/Objectives/class.ilLOTestRun.php';
169  $loRuns = ilLOTestRun::getRun($this->getObjectiveOrientedContainerId(), $this->getUserId(), $this->getTestObjId());
170 
171  $this->objectives = array();
172 
173  foreach( $loRuns as $loRun )
174  {
175  /* @var ilLOTestRun $loRun */
176 
177  $this->objectives[$loRun->getObjectiveId()] = $this->getObjectiveTitle($loRun);
178  }
179  }
180 
181  private function initCourseTitle()
182  {
183  $this->crsTitle = $this->objCache->lookupTitle($this->getObjectiveOrientedContainerId());
184  }
185 
189  public function getPassOverviewHeaderLabel()
190  {
191  if( !$this->getObjectiveOrientedContainerId() )
192  {
193  return $this->lng->txt('tst_results_overview');
194  }
195 
196  if( $this->isInitialTestForAllObjectives() )
197  {
198  return sprintf(
199  $this->lng->txt('tst_pass_overview_header_lo_initial_all_objectives'), $this->crsTitle
200  );
201  }
202  elseif( $this->isInitialTestPerObjective() )
203  {
204  return sprintf(
205  $this->lng->txt('tst_pass_overview_header_lo_initial_per_objective'),
207  );
208  }
209  elseif( $this->isQualifyingTestForAllObjectives() )
210  {
211  return sprintf(
212  $this->lng->txt('tst_pass_overview_header_lo_qualifying_all_objectives'), $this->crsTitle
213  );
214  }
215  elseif( $this->isQualifyingTestPerObjective() )
216  {
217  return sprintf(
218  $this->lng->txt('tst_pass_overview_header_lo_qualifying_per_objective'),
220  );
221  }
222 
223  return '';
224  }
225 
229  public function getPassDetailsHeaderLabel($attemptNumber)
230  {
231  if( !$this->getObjectiveOrientedContainerId() )
232  {
233  return sprintf(
234  $this->lng->txt('tst_pass_details_overview_table_title'), $attemptNumber
235  );
236  }
237 
238  if( $this->isInitialTest() )
239  {
240  return sprintf(
241  $this->lng->txt('tst_pass_details_header_lo_initial'),
242  $this->getObjectivesString(), $this->getAttemptLabel($attemptNumber)
243  );
244  }
245  elseif( $this->isQualifyingTest() )
246  {
247  return sprintf(
248  $this->lng->txt('tst_pass_details_header_lo_qualifying'),
249  $this->getObjectivesString(), $this->getAttemptLabel($attemptNumber)
250  );
251  }
252 
253  return '';
254  }
255 
256  private function isInitialTest()
257  {
258  return $this->testType == self::LO_TEST_TYPE_INITIAL;
259  }
260 
261  private function isQualifyingTest()
262  {
263  return $this->testType == self::LO_TEST_TYPE_QUALIFYING;
264  }
265 
266  private function isInitialTestForAllObjectives()
267  {
268  if( $this->testType != self::LO_TEST_TYPE_INITIAL )
269  {
270  return false;
271  }
272 
273  if( count($this->objectives) <= 1 )
274  {
275  return false;
276  }
277 
278  return true;
279  }
280 
281  private function isInitialTestPerObjective()
282  {
283  if( $this->testType != self::LO_TEST_TYPE_INITIAL )
284  {
285  return false;
286  }
287 
288  if( count($this->objectives) > 1 )
289  {
290  return false;
291  }
292 
293  return true;
294  }
295 
297  {
298  if( $this->testType != self::LO_TEST_TYPE_QUALIFYING )
299  {
300  return false;
301  }
302 
303  if( count($this->objectives) <= 1 )
304  {
305  return false;
306  }
307 
308  return true;
309  }
310 
311  private function isQualifyingTestPerObjective()
312  {
313  if( $this->testType != self::LO_TEST_TYPE_QUALIFYING )
314  {
315  return false;
316  }
317 
318  if( count($this->objectives) > 1 )
319  {
320  return false;
321  }
322 
323  return true;
324  }
325 
326  private function getObjectiveTitle(ilLOTestRun $loRun)
327  {
328  require_once 'Modules/Course/classes/class.ilCourseObjective.php';
330  }
331 
332  private function getObjectivesString()
333  {
334  return implode(', ', $this->objectives);
335  }
336 
337  private function getAttemptLabel($attemptNumber)
338  {
339  return sprintf($this->lng->txt('tst_res_lo_try_n'), $attemptNumber);
340  }
341 
342  public function getListOfAnswersHeaderLabel($attemptNumber)
343  {
344  $langVar = 'tst_eval_results_by_pass';
345 
346  if( $this->getObjectiveOrientedContainerId() )
347  {
348  $langVar = 'tst_eval_results_by_pass_lo';
349  }
350 
351  return sprintf($this->lng->txt($langVar), $attemptNumber);
352  }
353 
355  {
356  return $this->lng->txt('tst_eval_results_lo');
357  }
358 
359  public function getVirtualPassDetailsHeaderLabel($objectiveTitle)
360  {
361  if( $this->isInitialTest() )
362  {
363  return sprintf(
364  $this->lng->txt('tst_virtual_pass_header_lo_initial'), $objectiveTitle
365  );
366  }
367  elseif( $this->isQualifyingTest() )
368  {
369  return sprintf(
370  $this->lng->txt('tst_virtual_pass_header_lo_qualifying'), $objectiveTitle
371  );
372  }
373 
374  return '';
375  }
376 }
static getInstanceByObjId($a_obj_id)
get singleton instance
__construct(ilLanguage $lng, ilObjectDataCache $objCache)
static lookupObjectiveTitle($a_objective_id, $a_add_description=false)
static getRun($a_container_id, $a_user_id, $a_test_id)
class ilObjectDataCache
Create styles array
The data for the language used.
language handling
setObjectiveOrientedContainerId($objectiveOrientedContainerId)
Stores current objective, questions and max points.