ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestResultHeaderLabelBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  public const LO_TEST_TYPE_INITIAL = 'loTestInitial';
30  public const LO_TEST_TYPE_QUALIFYING = 'loTestQualifying';
34  protected $lng;
35 
39  protected $objCache;
40 
45 
49  protected $testObjId;
50 
54  protected $testRefId;
55 
59  protected $userId;
60 
64  protected $crsTitle;
65 
69  protected $testType;
70 
74  protected $objectives;
75 
81  {
82  $this->lng = $lng;
83  $this->objCache = $objCache;
84 
85  $this->objectiveOrientedContainerId = null;
86  $this->testObjId = null;
87  $this->testRefId = null;
88  $this->userId = null;
89 
90  $this->testType = null;
91  $this->crsTitle = null;
92 
93  $this->objectives = array();
94  }
95 
100  {
102  }
103 
108  {
109  $this->objectiveOrientedContainerId = $objectiveOrientedContainerId;
110  }
111 
115  public function getTestObjId(): ?int
116  {
117  return $this->testObjId;
118  }
119 
123  public function setTestObjId($testObjId)
124  {
125  $this->testObjId = $testObjId;
126  }
127 
131  public function getTestRefId(): ?int
132  {
133  return $this->testRefId;
134  }
135 
139  public function setTestRefId($testRefId)
140  {
141  $this->testRefId = $testRefId;
142  }
143 
147  public function getUserId(): ?int
148  {
149  return $this->userId;
150  }
151 
155  public function setUserId($userId)
156  {
157  $this->userId = $userId;
158  }
159 
160  public function initObjectiveOrientedMode()
161  {
162  $this->initTestType();
163  $this->initObjectives();
164  $this->initCourseTitle();
165  }
166 
167  private function initTestType()
168  {
170 
171  if ($loSettings->getInitialTest() == $this->getTestRefId()) {
172  $this->testType = self::LO_TEST_TYPE_INITIAL;
173  } elseif ($loSettings->getQualifiedTest() == $this->getTestRefId()) {
174  $this->testType = self::LO_TEST_TYPE_QUALIFYING;
175  }
176  }
177 
178  private function initObjectives()
179  {
180  $loRuns = ilLOTestRun::getRun($this->getObjectiveOrientedContainerId(), $this->getUserId(), $this->getTestObjId());
181 
182  $this->objectives = array();
183 
184  foreach ($loRuns as $loRun) {
185  /* @var ilLOTestRun $loRun */
186 
187  $this->objectives[$loRun->getObjectiveId()] = $this->getObjectiveTitle($loRun);
188  }
189  }
190 
191  private function initCourseTitle()
192  {
193  $this->crsTitle = $this->objCache->lookupTitle((int) $this->getObjectiveOrientedContainerId());
194  }
195 
199  public function getPassOverviewHeaderLabel(): string
200  {
201  if (!$this->getObjectiveOrientedContainerId()) {
202  return $this->lng->txt('tst_results_overview');
203  }
204 
205  if ($this->isInitialTestForAllObjectives()) {
206  return sprintf(
207  $this->lng->txt('tst_pass_overview_header_lo_initial_all_objectives'),
209  );
210  } elseif ($this->isInitialTestPerObjective()) {
211  return sprintf(
212  $this->lng->txt('tst_pass_overview_header_lo_initial_per_objective'),
213  $this->getObjectivesString(),
215  );
216  } elseif ($this->isQualifyingTestForAllObjectives()) {
217  return sprintf(
218  $this->lng->txt('tst_pass_overview_header_lo_qualifying_all_objectives'),
220  );
221  } elseif ($this->isQualifyingTestPerObjective()) {
222  return sprintf(
223  $this->lng->txt('tst_pass_overview_header_lo_qualifying_per_objective'),
224  $this->getObjectivesString(),
226  );
227  }
228 
229  return '';
230  }
231 
235  public function getPassDetailsHeaderLabel($attemptNumber): string
236  {
237  if (!$this->getObjectiveOrientedContainerId()) {
238  return sprintf(
239  $this->lng->txt('tst_pass_details_overview_table_title'),
240  $attemptNumber
241  );
242  }
243 
244  if ($this->isInitialTest()) {
245  return sprintf(
246  $this->lng->txt('tst_pass_details_header_lo_initial'),
247  $this->getObjectivesString(),
248  $this->getAttemptLabel($attemptNumber)
249  );
250  } elseif ($this->isQualifyingTest()) {
251  return sprintf(
252  $this->lng->txt('tst_pass_details_header_lo_qualifying'),
253  $this->getObjectivesString(),
254  $this->getAttemptLabel($attemptNumber)
255  );
256  }
257 
258  return '';
259  }
260 
261  private function isInitialTest(): bool
262  {
263  return $this->testType == self::LO_TEST_TYPE_INITIAL;
264  }
265 
266  private function isQualifyingTest(): bool
267  {
268  return $this->testType == self::LO_TEST_TYPE_QUALIFYING;
269  }
270 
271  private function isInitialTestForAllObjectives(): bool
272  {
273  if ($this->testType != self::LO_TEST_TYPE_INITIAL) {
274  return false;
275  }
276 
277  if (count($this->objectives) <= 1) {
278  return false;
279  }
280 
281  return true;
282  }
283 
284  private function isInitialTestPerObjective(): bool
285  {
286  if ($this->testType != self::LO_TEST_TYPE_INITIAL) {
287  return false;
288  }
289 
290  if (count($this->objectives) > 1) {
291  return false;
292  }
293 
294  return true;
295  }
296 
297  private function isQualifyingTestForAllObjectives(): bool
298  {
299  if ($this->testType != self::LO_TEST_TYPE_QUALIFYING) {
300  return false;
301  }
302 
303  if (count($this->objectives) <= 1) {
304  return false;
305  }
306 
307  return true;
308  }
309 
310  private function isQualifyingTestPerObjective(): bool
311  {
312  if ($this->testType != self::LO_TEST_TYPE_QUALIFYING) {
313  return false;
314  }
315 
316  if (count($this->objectives) > 1) {
317  return false;
318  }
319 
320  return true;
321  }
322 
323  private function getObjectiveTitle(ilLOTestRun $loRun)
324  {
326  }
327 
328  private function getObjectivesString(): string
329  {
330  return implode(', ', $this->objectives);
331  }
332 
333  private function getAttemptLabel($attemptNumber): string
334  {
335  return sprintf($this->lng->txt('tst_res_lo_try_n'), $attemptNumber);
336  }
337 
338  public function getListOfAnswersHeaderLabel($attemptNumber): string
339  {
340  $langVar = 'tst_eval_results_by_pass';
341 
342  if ($this->getObjectiveOrientedContainerId()) {
343  $langVar = 'tst_eval_results_by_pass_lo';
344  }
345 
346  return sprintf($this->lng->txt($langVar), $attemptNumber);
347  }
348 
349  public function getVirtualListOfAnswersHeaderLabel(): string
350  {
351  return $this->lng->txt('tst_eval_results_lo');
352  }
353 
354  public function getVirtualPassDetailsHeaderLabel($objectiveTitle): string
355  {
356  if ($this->isInitialTest()) {
357  return sprintf(
358  $this->lng->txt('tst_virtual_pass_header_lo_initial'),
359  $objectiveTitle
360  );
361  } elseif ($this->isQualifyingTest()) {
362  return sprintf(
363  $this->lng->txt('tst_virtual_pass_header_lo_qualifying'),
364  $objectiveTitle
365  );
366  }
367 
368  return '';
369  }
370 }
__construct(ilLanguage $lng, ilObjectDataCache $objCache)
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
static getInstanceByObjId(int $a_obj_id)
static getRun(int $a_container_id, int $a_user_id, int $a_test_id)
setObjectiveOrientedContainerId($objectiveOrientedContainerId)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...