ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilTestQuestionHeaderBlockBuilder.php
Go to the documentation of this file.
1<?php
2
26{
30 protected $lng;
31
35 protected $headerMode;
36
40 protected $questionTitle;
41
45 protected $questionPoints;
46
51
55 protected $questionCount;
56
61
66
71
72 // fau: testNav - answer status variable
77 // fau.
78
79 public function __construct(ilLanguage $lng)
80 {
81 $this->lng = $lng;
82
83 $this->headerMode = null;
84 $this->questionTitle = '';
85 $this->questionPoints = 0.0;
86 $this->questionPosition = 0;
87 $this->questionCount = 0;
88 $this->questionPostponed = false;
89 $this->questionObligatory = false;
90 $this->questionRelatedObjectives = '';
91 }
92
96 public function getHeaderMode(): ?int
97 {
98 return $this->headerMode;
99 }
100
104 public function setHeaderMode($headerMode)
105 {
106 $this->headerMode = $headerMode;
107 }
108
112 public function getQuestionTitle(): string
113 {
115 }
116
121 {
122 $this->questionTitle = $questionTitle;
123 }
124
128 public function getQuestionPoints(): float
129 {
131 }
132
137 {
138 $this->questionPoints = $questionPoints;
139 }
140
141 // fau: testNav - setter for question answered
146 {
147 $this->questionAnswered = $questionAnswered;
148 }
149 // fau.
153 public function getQuestionPosition(): int
154 {
156 }
157
162 {
163 $this->questionPosition = $questionPosition;
164 }
165
169 public function getQuestionCount(): int
170 {
172 }
173
178 {
179 $this->questionCount = $questionCount;
180 }
181
185 public function isQuestionPostponed(): bool
186 {
188 }
189
190 // fau: testNav - get question answered status
194 public function isQuestionAnswered(): ?bool
195 {
197 }
198 // fau.
199
204 {
205 $this->questionPostponed = $questionPostponed;
206 }
207
211 public function isQuestionObligatory(): bool
212 {
214 }
215
220 {
221 $this->questionObligatory = $questionObligatory;
222 }
223
227 public function getQuestionRelatedObjectives(): string
228 {
230 }
231
236 {
237 $this->questionRelatedObjectives = $questionRelatedObjectives;
238 }
239
240 protected function buildQuestionPositionString(): string
241 {
242 if (!$this->getQuestionPosition()) {
243 return '';
244 }
245
246 if ($this->getQuestionCount()) {
247 return sprintf($this->lng->txt("tst_position"), $this->getQuestionPosition(), $this->getQuestionCount());
248 }
249
250 return sprintf($this->lng->txt("tst_position_without_total"), $this->getQuestionPosition());
251 }
252
253 // fau: testNav - remove HTML from building strings (is now in tpl.tst_question_info.html)
254 protected function buildQuestionPointsString(): string
255 {
256 if ($this->getQuestionPoints() == 1) {
257 return "{$this->getQuestionPoints()} {$this->lng->txt('point')}";
258 }
259
260 return "{$this->getQuestionPoints()} {$this->lng->txt('points')}";
261 }
262
263 protected function buildQuestionPostponedString(): string
264 {
265 if ($this->isQuestionPostponed()) {
266 return $this->lng->txt("postponed");
267 }
268
269 return '';
270 }
271
272 protected function buildQuestionObligatoryString(): string
273 {
274 if ($this->isQuestionObligatory()) {
275 return $this->lng->txt("tst_you_have_to_answer_this_question");
276 }
277
278 return '';
279 }
280
281 protected function buildQuestionRelatedObjectivesString(): string
282 {
283 if (strlen($this->getQuestionRelatedObjectives())) {
284 $label = $this->lng->txt('tst_res_lo_objectives_header');
285 return $label . ': ' . $this->getQuestionRelatedObjectives();
286 }
287
288 return '';
289 }
290 // fau.
291
292
293 // fau: testNav - split generation of presentation title and question info
294
300 public function getPresentationTitle(): string
301 {
302 switch ($this->getHeaderMode()) {
303 case 2: // neither titles nor points => show position as title
304 return $this->buildQuestionPositionString();
305 break;
306
307 case 0: // titles and points => show title here
308 case 1: // only titles => show title here
309 default:
310 return $this->getQuestionTitle();
311 }
312 }
313
314
320 public function getQuestionInfoHTML(): string
321 {
322 $tpl = new ilTemplate('tpl.tst_question_info.html', true, true, 'Modules/Test');
323
324 // position and/or points
325 switch ($this->getHeaderMode()) {
326 case 1: // only titles => show position here
327 $text = $this->buildQuestionPositionString();
328 break;
329
330 case 2: // neither titles nor points => position is separate title, show nothing here
331 $text = '';
332 break;
333
334 case 0: // titles and points => show position and points here
335 default:
336 $text = $this->buildQuestionPositionString() . ' (' . $this->buildQuestionPointsString() . ')';
337 }
338 if ($this->isQuestionPostponed()) {
339 $text .= ($text ? ', ' : '') . $this->buildQuestionPostponedString();
340 }
341
342 $tpl->setVariable('TXT_POSITION_POINTS', $text);
343
344 // obligatory
345 if ($this->isQuestionObligatory() && !$this->isQuestionAnswered()) {
346 $tpl->setVariable('TXT_OBLIGATORY', $this->buildQuestionObligatoryString());
347 }
348
349 // objectives
350 if (strlen($this->getQuestionRelatedObjectives())) {
351 $tpl->setVariable('TXT_OBJECTIVES', $this->buildQuestionRelatedObjectivesString());
352 }
353
354 // answer status
355 if ($this->isQuestionAnswered()) {
356 $tpl->setVariable('HIDDEN_NOT_ANSWERED', 'hidden');
357 } else {
358 $tpl->setVariable('HIDDEN_ANSWERED', 'hidden');
359 }
360
361 $tpl->setVariable('SRC_ANSWERED', ilUtil::getImagePath('answered.svg'));
362 $tpl->setVariable('SRC_NOT_ANSWERED', ilUtil::getImagePath('answered_not.svg'));
363 $tpl->setVariable('TXT_ANSWERED', $this->lng->txt('tst_answer_status_answered'));
364 $tpl->setVariable('TXT_NOT_ANSWERED', $this->lng->txt('tst_answer_status_not_answered'));
365 $tpl->setVariable('TXT_EDITING', $this->lng->txt('tst_answer_status_editing'));
366
367 return $tpl->get();
368 }
369 // fau.
370
371 public function getHTML(): string
372 {
373 $headerBlock = $this->buildQuestionPositionString();
374
375 switch ($this->getHeaderMode()) {
376 case 1:
377
378 $headerBlock .= " - " . $this->getQuestionTitle();
379 $headerBlock .= $this->buildQuestionPostponedString();
380 $headerBlock .= $this->buildQuestionObligatoryString();
381 break;
382
383 case 2:
384
385 $headerBlock .= $this->buildQuestionPostponedString();
386 $headerBlock .= $this->buildQuestionObligatoryString();
387 break;
388
389 case 0:
390 default:
391
392 $headerBlock .= " - " . $this->getQuestionTitle();
393 $headerBlock .= $this->buildQuestionPostponedString();
394// fau: testNav - put the points in parentheses here, not in building the string
395 $headerBlock .= ' (' . $this->buildQuestionPointsString() . ')';
396// fau.
397 $headerBlock .= $this->buildQuestionObligatoryString();
398 }
399
400 $headerBlock .= $this->buildQuestionRelatedObjectivesString();
401
402 return $headerBlock;
403 }
404}
language handling
special template class to simplify handling of ITX/PEAR
getPresentationTitle()
Get the presentation title of the question This is shown above the title line in a test run.
getQuestionInfoHTML()
Get the additional question info and answering status This is shown below the title line in a test ru...
getHTML()
Get the HTML representation of the header block.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41