ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilTestQuestionHeaderBlockBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  protected ?int $header_mode = null;
27  protected string $question_title = '';
28  protected float $question_points = 0.0;
29  protected int $question_position = 0;
30  protected int $question_count = 0;
31  protected bool $question_postponed = false;
32  protected string $question_related_objectives = '';
33  protected ?bool $question_answered = null;
34 
35  public function __construct(
36  private readonly ilLanguage $lng
37  ) {
38  }
39 
40  public function getHeaderMode(): ?int
41  {
42  return $this->header_mode;
43  }
44 
45  public function setHeaderMode(int $header_mode): void
46  {
47  $this->header_mode = $header_mode;
48  }
49 
50  public function getQuestionTitle(): string
51  {
52  return $this->question_title;
53  }
54 
55  public function setQuestionTitle(string $question_title): void
56  {
57  $this->question_title = $question_title;
58  }
59 
60  public function getQuestionPoints(): float
61  {
63  }
64 
65  public function setQuestionPoints(float $question_points): void
66  {
67  $this->question_points = $question_points;
68  }
69 
70  public function setQuestionAnswered(bool $question_answered): void
71  {
72  $this->question_answered = $question_answered;
73  }
74 
75  public function getQuestionPosition(): int
76  {
78  }
79 
80  public function setQuestionPosition(int $question_position): void
81  {
82  $this->question_position = $question_position;
83  }
84 
85  public function getQuestionCount(): int
86  {
87  return $this->question_count;
88  }
89 
90  public function setQuestionCount(int $question_count): void
91  {
92  $this->question_count = $question_count;
93  }
94 
95  public function isQuestionPostponed(): bool
96  {
98  }
99 
100  public function isQuestionAnswered(): ?bool
101  {
103  }
104 
105  public function setQuestionPostponed(bool $question_postponed): void
106  {
107  $this->question_postponed = $question_postponed;
108  }
109 
110  public function getQuestionRelatedObjectives(): string
111  {
113  }
114 
115  public function setQuestionRelatedObjectives(string $question_related_objectives): void
116  {
117  $this->question_related_objectives = $question_related_objectives;
118  }
119 
120  protected function buildQuestionPositionString(): string
121  {
122  if (!$this->getQuestionPosition()) {
123  return '';
124  }
125 
126  if ($this->getQuestionCount()) {
127  return sprintf($this->lng->txt('tst_position'), $this->getQuestionPosition(), $this->getQuestionCount());
128  }
129 
130  return sprintf($this->lng->txt('tst_position_without_total'), $this->getQuestionPosition());
131  }
132 
133  protected function buildQuestionPointsString(): string
134  {
135  if ($this->getQuestionPoints() == 1) {
136  return "{$this->getQuestionPoints()} {$this->lng->txt('point')}";
137  }
138 
139  return "{$this->getQuestionPoints()} {$this->lng->txt('points')}";
140  }
141 
142  protected function buildQuestionPostponedString(): string
143  {
144  if ($this->isQuestionPostponed()) {
145  return $this->lng->txt('postponed');
146  }
147 
148  return '';
149  }
150 
151  protected function buildQuestionRelatedObjectivesString(): string
152  {
153  if (strlen($this->getQuestionRelatedObjectives())) {
154  $label = $this->lng->txt('tst_res_lo_objectives_header');
155  return $label . ': ' . $this->getQuestionRelatedObjectives();
156  }
157 
158  return '';
159  }
160 
161  public function getPresentationTitle(): string
162  {
163  switch ($this->getHeaderMode()) {
164  case 3: // only points => show no title here
165  return $this->buildQuestionPointsString();
166  break;
167  case 2: // neither titles nor points => show position as title
168  return $this->buildQuestionPositionString();
169  break;
170 
171  case 0: // titles and points => show title here
172  case 1: // only titles => show title here
173  default:
174  return $this->getQuestionTitle();
175  }
176  }
177 
178  public function getQuestionInfoHTML(): string
179  {
180  $tpl = new ilTemplate('tpl.tst_question_info.html', true, true, 'components/ILIAS/Test');
181 
182  // position and/or points
183  switch ($this->getHeaderMode()) {
184  case 1: // only titles => show position here
185  $text = $this->buildQuestionPositionString();
186  break;
187 
188  case 3: // only points => show nothing here
189  $text = $this->buildQuestionPositionString();
190  break;
191  case 2: // neither titles nor points => position is separate title, show nothing here
192  $text = '';
193  break;
194 
195  case 0: // titles and points => show position and points here
196  default:
197  $text = $this->buildQuestionPositionString() . ' (' . $this->buildQuestionPointsString() . ')';
198  }
199  if ($this->isQuestionPostponed()) {
200  $text .= ($text ? ', ' : '') . $this->buildQuestionPostponedString();
201  }
202 
203  $tpl->setVariable('TXT_POSITION_POINTS', $text);
204 
205  if (strlen($this->getQuestionRelatedObjectives())) {
206  $tpl->setVariable('TXT_OBJECTIVES', $this->buildQuestionRelatedObjectivesString());
207  }
208 
209  if ($this->isQuestionAnswered()) {
210  $tpl->setVariable('HIDDEN_NOT_ANSWERED', 'hidden');
211  } else {
212  $tpl->setVariable('HIDDEN_ANSWERED', 'hidden');
213  }
214 
215  $tpl->setVariable('SRC_ANSWERED', ilUtil::getImagePath('object/answered.svg'));
216  $tpl->setVariable('SRC_NOT_ANSWERED', ilUtil::getImagePath('object/answered_not.svg'));
217  $tpl->setVariable('TXT_ANSWERED', $this->lng->txt('tst_answer_status_answered'));
218  $tpl->setVariable('TXT_NOT_ANSWERED', $this->lng->txt('tst_answer_status_not_answered'));
219  $tpl->setVariable('TXT_EDITING', $this->lng->txt('tst_answer_status_editing'));
220 
221  return $tpl->get();
222  }
223 
224  public function getHTML(): string
225  {
226  $header_block = $this->buildQuestionPositionString();
227 
228  switch ($this->getHeaderMode()) {
229  case 1:
230  $header_block .= " - " . $this->getQuestionTitle();
231  $header_block .= $this->buildQuestionPostponedString();
232  break;
233 
234  case 2:
235  $header_block .= $this->buildQuestionPostponedString();
236  break;
237 
238  case 0:
239  default:
240 
241  $header_block .= " - " . $this->getQuestionTitle();
242  $header_block .= $this->buildQuestionPostponedString();
243  $header_block .= ' (' . $this->buildQuestionPointsString() . ')';
244  }
245 
246  $header_block .= $this->buildQuestionRelatedObjectivesString();
247 
248  return $header_block;
249  }
250 }
setQuestionRelatedObjectives(string $question_related_objectives)
getHTML()
Get the HTML representation of the header block.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getImagePath(string $image_name, 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...
global $lng
Definition: privfeed.php:31