ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestQuestionHeaderBlockBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
32  protected $lng;
33 
37  protected $headerMode;
38 
42  protected $questionTitle;
43 
47  protected $questionPoints;
48 
52  protected $questionPosition;
53 
57  protected $questionCount;
58 
62  protected $questionPostponed;
63 
68 
73 
74  // fau: testNav - answer status variable
78  protected $questionAnswered;
79  // fau.
80 
81  public function __construct(ilLanguage $lng)
82  {
83  $this->lng = $lng;
84 
85  $this->headerMode = null;
86  $this->questionTitle = '';
87  $this->questionPoints = 0.0;
88  $this->questionPosition = 0;
89  $this->questionCount = 0;
90  $this->questionPostponed = false;
91  $this->questionObligatory = false;
92  $this->questionRelatedObjectives = '';
93  }
94 
98  public function getHeaderMode(): ?int
99  {
100  return $this->headerMode;
101  }
102 
106  public function setHeaderMode($headerMode)
107  {
108  $this->headerMode = $headerMode;
109  }
110 
114  public function getQuestionTitle(): string
115  {
116  return $this->questionTitle;
117  }
118 
123  {
124  $this->questionTitle = $questionTitle;
125  }
126 
130  public function getQuestionPoints(): float
131  {
132  return $this->questionPoints;
133  }
134 
139  {
140  $this->questionPoints = $questionPoints;
141  }
142 
143  // fau: testNav - setter for question answered
148  {
149  $this->questionAnswered = $questionAnswered;
150  }
151  // fau.
155  public function getQuestionPosition(): int
156  {
158  }
159 
164  {
165  $this->questionPosition = $questionPosition;
166  }
167 
171  public function getQuestionCount(): int
172  {
173  return $this->questionCount;
174  }
175 
180  {
181  $this->questionCount = $questionCount;
182  }
183 
187  public function isQuestionPostponed(): bool
188  {
190  }
191 
192  // fau: testNav - get question answered status
196  public function isQuestionAnswered(): ?bool
197  {
199  }
200  // fau.
201 
206  {
207  $this->questionPostponed = $questionPostponed;
208  }
209 
213  public function isQuestionObligatory(): bool
214  {
216  }
217 
222  {
223  $this->questionObligatory = $questionObligatory;
224  }
225 
229  public function getQuestionRelatedObjectives(): string
230  {
232  }
233 
238  {
239  $this->questionRelatedObjectives = $questionRelatedObjectives;
240  }
241 
242  protected function buildQuestionPositionString(): string
243  {
244  if (!$this->getQuestionPosition()) {
245  return '';
246  }
247 
248  if ($this->getQuestionCount()) {
249  return sprintf($this->lng->txt("tst_position"), $this->getQuestionPosition(), $this->getQuestionCount());
250  }
251 
252  return sprintf($this->lng->txt("tst_position_without_total"), $this->getQuestionPosition());
253  }
254 
255  // fau: testNav - remove HTML from building strings (is now in tpl.tst_question_info.html)
256  protected function buildQuestionPointsString(): string
257  {
258  if ($this->getQuestionPoints() == 1) {
259  return "{$this->getQuestionPoints()} {$this->lng->txt('point')}";
260  }
261 
262  return "{$this->getQuestionPoints()} {$this->lng->txt('points')}";
263  }
264 
265  protected function buildQuestionPostponedString(): string
266  {
267  if ($this->isQuestionPostponed()) {
268  return $this->lng->txt("postponed");
269  }
270 
271  return '';
272  }
273 
274  protected function buildQuestionObligatoryString(): string
275  {
276  if ($this->isQuestionObligatory()) {
277  return $this->lng->txt("tst_you_have_to_answer_this_question");
278  }
279 
280  return '';
281  }
282 
283  protected function buildQuestionRelatedObjectivesString(): string
284  {
285  if (strlen($this->getQuestionRelatedObjectives())) {
286  $label = $this->lng->txt('tst_res_lo_objectives_header');
287  return $label . ': ' . $this->getQuestionRelatedObjectives();
288  }
289 
290  return '';
291  }
292  // fau.
293 
294 
295  // fau: testNav - split generation of presentation title and question info
296 
302  public function getPresentationTitle(): string
303  {
304  switch ($this->getHeaderMode()) {
305  case 3: // only points => show no title here
306  return $this->buildQuestionPointsString();
307  break;
308  case 2: // neither titles nor points => show position as title
309  return $this->buildQuestionPositionString();
310  break;
311 
312  case 0: // titles and points => show title here
313  case 1: // only titles => show title here
314  default:
315  return $this->getQuestionTitle();
316  }
317  }
318 
319 
325  public function getQuestionInfoHTML(): string
326  {
327  $tpl = new ilTemplate('tpl.tst_question_info.html', true, true, 'Modules/Test');
328 
329  // position and/or points
330  switch ($this->getHeaderMode()) {
331  case 1: // only titles => show position here
332  $text = $this->buildQuestionPositionString();
333  break;
334 
335  case 3: // only points => show nothing here
336  $text = $this->buildQuestionPositionString();
337  break;
338  case 2: // neither titles nor points => position is separate title, show nothing here
339  $text = '';
340  break;
341 
342  case 0: // titles and points => show position and points here
343  default:
344  $text = $this->buildQuestionPositionString() . ' (' . $this->buildQuestionPointsString() . ')';
345  }
346  if ($this->isQuestionPostponed()) {
347  $text .= ($text ? ', ' : '') . $this->buildQuestionPostponedString();
348  }
349 
350  $tpl->setVariable('TXT_POSITION_POINTS', $text);
351 
352  // obligatory
353  if ($this->isQuestionObligatory() && !$this->isQuestionAnswered()) {
354  $tpl->setVariable('TXT_OBLIGATORY', $this->buildQuestionObligatoryString());
355  }
356 
357  // objectives
358  if (strlen($this->getQuestionRelatedObjectives())) {
359  $tpl->setVariable('TXT_OBJECTIVES', $this->buildQuestionRelatedObjectivesString());
360  }
361 
362  // answer status
363  if ($this->isQuestionAnswered()) {
364  $tpl->setVariable('HIDDEN_NOT_ANSWERED', 'hidden');
365  } else {
366  $tpl->setVariable('HIDDEN_ANSWERED', 'hidden');
367  }
368 
369  $tpl->setVariable('SRC_ANSWERED', ilUtil::getImagePath('object/answered.svg'));
370  $tpl->setVariable('SRC_NOT_ANSWERED', ilUtil::getImagePath('object/answered_not.svg'));
371  $tpl->setVariable('TXT_ANSWERED', $this->lng->txt('tst_answer_status_answered'));
372  $tpl->setVariable('TXT_NOT_ANSWERED', $this->lng->txt('tst_answer_status_not_answered'));
373  $tpl->setVariable('TXT_EDITING', $this->lng->txt('tst_answer_status_editing'));
374 
375  return $tpl->get();
376  }
377  // fau.
378 
379  public function getHTML(): string
380  {
381  $headerBlock = $this->buildQuestionPositionString();
382 
383  switch ($this->getHeaderMode()) {
384  case 1:
385 
386  $headerBlock .= " - " . $this->getQuestionTitle();
387  $headerBlock .= $this->buildQuestionPostponedString();
388  $headerBlock .= $this->buildQuestionObligatoryString();
389  break;
390 
391  case 2:
392 
393  $headerBlock .= $this->buildQuestionPostponedString();
394  $headerBlock .= $this->buildQuestionObligatoryString();
395  break;
396 
397  case 0:
398  default:
399 
400  $headerBlock .= " - " . $this->getQuestionTitle();
401  $headerBlock .= $this->buildQuestionPostponedString();
402  // fau: testNav - put the points in parentheses here, not in building the string
403  $headerBlock .= ' (' . $this->buildQuestionPointsString() . ')';
404  // fau.
405  $headerBlock .= $this->buildQuestionObligatoryString();
406  }
407 
408  $headerBlock .= $this->buildQuestionRelatedObjectivesString();
409 
410  return $headerBlock;
411  }
412 }
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)
getQuestionInfoHTML()
Get the additional question info and answering status This is shown below the title line in a test ru...
getPresentationTitle()
Get the presentation title of the question This is shown above the title line in a test run...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...