ILIAS  release_8 Revision v8.24
class.ilTestResultHeaderLabelBuilder.php
Go to the documentation of this file.
1<?php
2
26{
27 public const LO_TEST_TYPE_INITIAL = 'loTestInitial';
28 public const LO_TEST_TYPE_QUALIFYING = 'loTestQualifying';
32 protected $lng;
33
37 protected $objCache;
38
43
47 protected $testObjId;
48
52 protected $testRefId;
53
57 protected $userId;
58
62 protected $crsTitle;
63
67 protected $testType;
68
72 protected $objectives;
73
79 {
80 $this->lng = $lng;
81 $this->objCache = $objCache;
82
83 $this->objectiveOrientedContainerId = null;
84 $this->testObjId = null;
85 $this->testRefId = null;
86 $this->userId = null;
87
88 $this->testType = null;
89 $this->crsTitle = null;
90
91 $this->objectives = array();
92 }
93
98 {
100 }
101
106 {
107 $this->objectiveOrientedContainerId = $objectiveOrientedContainerId;
108 }
109
113 public function getTestObjId(): ?int
114 {
115 return $this->testObjId;
116 }
117
121 public function setTestObjId($testObjId)
122 {
123 $this->testObjId = $testObjId;
124 }
125
129 public function getTestRefId(): ?int
130 {
131 return $this->testRefId;
132 }
133
137 public function setTestRefId($testRefId)
138 {
139 $this->testRefId = $testRefId;
140 }
141
145 public function getUserId(): ?int
146 {
147 return $this->userId;
148 }
149
153 public function setUserId($userId)
154 {
155 $this->userId = $userId;
156 }
157
159 {
160 $this->initTestType();
161 $this->initObjectives();
162 $this->initCourseTitle();
163 }
164
165 private function initTestType()
166 {
168
169 if ($loSettings->getInitialTest() == $this->getTestRefId()) {
170 $this->testType = self::LO_TEST_TYPE_INITIAL;
171 } elseif ($loSettings->getQualifiedTest() == $this->getTestRefId()) {
172 $this->testType = self::LO_TEST_TYPE_QUALIFYING;
173 }
174 }
175
176 private function initObjectives()
177 {
178 $loRuns = ilLOTestRun::getRun($this->getObjectiveOrientedContainerId(), $this->getUserId(), $this->getTestObjId());
179
180 $this->objectives = array();
181
182 foreach ($loRuns as $loRun) {
183 /* @var ilLOTestRun $loRun */
184
185 $this->objectives[$loRun->getObjectiveId()] = $this->getObjectiveTitle($loRun);
186 }
187 }
188
189 private function initCourseTitle()
190 {
191 $this->crsTitle = $this->objCache->lookupTitle((int) $this->getObjectiveOrientedContainerId());
192 }
193
197 public function getPassOverviewHeaderLabel(): string
198 {
199 if (!$this->getObjectiveOrientedContainerId()) {
200 return $this->lng->txt('tst_results_overview');
201 }
202
203 if ($this->isInitialTestForAllObjectives()) {
204 return sprintf(
205 $this->lng->txt('tst_pass_overview_header_lo_initial_all_objectives'),
206 $this->crsTitle
207 );
208 } elseif ($this->isInitialTestPerObjective()) {
209 return sprintf(
210 $this->lng->txt('tst_pass_overview_header_lo_initial_per_objective'),
211 $this->getObjectivesString(),
212 $this->crsTitle
213 );
214 } elseif ($this->isQualifyingTestForAllObjectives()) {
215 return sprintf(
216 $this->lng->txt('tst_pass_overview_header_lo_qualifying_all_objectives'),
217 $this->crsTitle
218 );
219 } elseif ($this->isQualifyingTestPerObjective()) {
220 return sprintf(
221 $this->lng->txt('tst_pass_overview_header_lo_qualifying_per_objective'),
222 $this->getObjectivesString(),
223 $this->crsTitle
224 );
225 }
226
227 return '';
228 }
229
233 public function getPassDetailsHeaderLabel($attemptNumber): string
234 {
235 if (!$this->getObjectiveOrientedContainerId()) {
236 return sprintf(
237 $this->lng->txt('tst_pass_details_overview_table_title'),
238 $attemptNumber
239 );
240 }
241
242 if ($this->isInitialTest()) {
243 return sprintf(
244 $this->lng->txt('tst_pass_details_header_lo_initial'),
245 $this->getObjectivesString(),
246 $this->getAttemptLabel($attemptNumber)
247 );
248 } elseif ($this->isQualifyingTest()) {
249 return sprintf(
250 $this->lng->txt('tst_pass_details_header_lo_qualifying'),
251 $this->getObjectivesString(),
252 $this->getAttemptLabel($attemptNumber)
253 );
254 }
255
256 return '';
257 }
258
259 private function isInitialTest(): bool
260 {
261 return $this->testType == self::LO_TEST_TYPE_INITIAL;
262 }
263
264 private function isQualifyingTest(): bool
265 {
266 return $this->testType == self::LO_TEST_TYPE_QUALIFYING;
267 }
268
269 private function isInitialTestForAllObjectives(): bool
270 {
271 if ($this->testType != self::LO_TEST_TYPE_INITIAL) {
272 return false;
273 }
274
275 if (count($this->objectives) <= 1) {
276 return false;
277 }
278
279 return true;
280 }
281
282 private function isInitialTestPerObjective(): bool
283 {
284 if ($this->testType != self::LO_TEST_TYPE_INITIAL) {
285 return false;
286 }
287
288 if (count($this->objectives) > 1) {
289 return false;
290 }
291
292 return true;
293 }
294
295 private function isQualifyingTestForAllObjectives(): bool
296 {
297 if ($this->testType != self::LO_TEST_TYPE_QUALIFYING) {
298 return false;
299 }
300
301 if (count($this->objectives) <= 1) {
302 return false;
303 }
304
305 return true;
306 }
307
308 private function isQualifyingTestPerObjective(): bool
309 {
310 if ($this->testType != self::LO_TEST_TYPE_QUALIFYING) {
311 return false;
312 }
313
314 if (count($this->objectives) > 1) {
315 return false;
316 }
317
318 return true;
319 }
320
321 private function getObjectiveTitle(ilLOTestRun $loRun)
322 {
324 }
325
326 private function getObjectivesString(): string
327 {
328 return implode(', ', $this->objectives);
329 }
330
331 private function getAttemptLabel($attemptNumber): string
332 {
333 return sprintf($this->lng->txt('tst_res_lo_try_n'), $attemptNumber);
334 }
335
336 public function getListOfAnswersHeaderLabel($attemptNumber): string
337 {
338 $langVar = 'tst_eval_results_by_pass';
339
340 if ($this->getObjectiveOrientedContainerId()) {
341 $langVar = 'tst_eval_results_by_pass_lo';
342 }
343
344 return sprintf($this->lng->txt($langVar), $attemptNumber);
345 }
346
347 public function getVirtualListOfAnswersHeaderLabel(): string
348 {
349 return $this->lng->txt('tst_eval_results_lo');
350 }
351
352 public function getVirtualPassDetailsHeaderLabel($objectiveTitle): string
353 {
354 if ($this->isInitialTest()) {
355 return sprintf(
356 $this->lng->txt('tst_virtual_pass_header_lo_initial'),
357 $objectiveTitle
358 );
359 } elseif ($this->isQualifyingTest()) {
360 return sprintf(
361 $this->lng->txt('tst_virtual_pass_header_lo_qualifying'),
362 $objectiveTitle
363 );
364 }
365
366 return '';
367 }
368}
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
static getInstanceByObjId(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getRun(int $a_container_id, int $a_user_id, int $a_test_id)
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilLanguage $lng, ilObjectDataCache $objCache)
setObjectiveOrientedContainerId($objectiveOrientedContainerId)