ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestQuestionHeaderBlockBuilder.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/TestQuestionPool/interfaces/interface.ilQuestionHeaderBlockBuilder.php';
5 
13 {
17  protected $lng;
18 
22  protected $headerMode;
23 
27  protected $questionTitle;
28 
32  protected $questionPoints;
33 
37  protected $questionPosition;
38 
42  protected $questionCount;
43 
47  protected $questionPostponed;
48 
53 
58 
59  // fau: testNav - answer status variable
63  protected $questionAnswered;
64  // fau.
65 
66  public function __construct(ilLanguage $lng)
67  {
68  $this->lng = $lng;
69 
70  $this->headerMode = null;
71  $this->questionTitle = '';
72  $this->questionPoints = 0.0;
73  $this->questionPosition = 0;
74  $this->questionCount = 0;
75  $this->questionPostponed = false;
76  $this->questionObligatory = false;
77  $this->questionRelatedObjectives = '';
78  }
79 
83  public function getHeaderMode()
84  {
85  return $this->headerMode;
86  }
87 
91  public function setHeaderMode($headerMode)
92  {
93  $this->headerMode = $headerMode;
94  }
95 
99  public function getQuestionTitle()
100  {
101  return $this->questionTitle;
102  }
103 
108  {
109  $this->questionTitle = $questionTitle;
110  }
111 
115  public function getQuestionPoints()
116  {
117  return $this->questionPoints;
118  }
119 
124  {
125  $this->questionPoints = $questionPoints;
126  }
127 
128  // fau: testNav - setter for question answered
133  {
134  $this->questionAnswered = $questionAnswered;
135  }
136  // fau.
140  public function getQuestionPosition()
141  {
143  }
144 
149  {
150  $this->questionPosition = $questionPosition;
151  }
152 
156  public function getQuestionCount()
157  {
158  return $this->questionCount;
159  }
160 
165  {
166  $this->questionCount = $questionCount;
167  }
168 
172  public function isQuestionPostponed()
173  {
175  }
176 
177  // fau: testNav - get question answered status
181  public function isQuestionAnswered()
182  {
184  }
185  // fau.
186 
191  {
192  $this->questionPostponed = $questionPostponed;
193  }
194 
198  public function isQuestionObligatory()
199  {
201  }
202 
207  {
208  $this->questionObligatory = $questionObligatory;
209  }
210 
215  {
217  }
218 
223  {
224  $this->questionRelatedObjectives = $questionRelatedObjectives;
225  }
226 
227  protected function buildQuestionPositionString()
228  {
229  if (!$this->getQuestionPosition()) {
230  return '';
231  }
232 
233  if ($this->getQuestionCount()) {
234  return sprintf($this->lng->txt("tst_position"), $this->getQuestionPosition(), $this->getQuestionCount());
235  }
236 
237  return sprintf($this->lng->txt("tst_position_without_total"), $this->getQuestionPosition());
238  }
239 
240  // fau: testNav - remove HTML from building strings (is now in tpl.tst_question_info.html)
241  protected function buildQuestionPointsString()
242  {
243  if ($this->getQuestionPoints() == 1) {
244  return "{$this->getQuestionPoints()} {$this->lng->txt('point')}";
245  }
246 
247  return "{$this->getQuestionPoints()} {$this->lng->txt('points')}";
248  }
249 
250  protected function buildQuestionPostponedString()
251  {
252  if ($this->isQuestionPostponed()) {
253  return $this->lng->txt("postponed");
254  }
255 
256  return '';
257  }
258 
259  protected function buildQuestionObligatoryString()
260  {
261  if ($this->isQuestionObligatory()) {
262  return $this->lng->txt("tst_you_have_to_answer_this_question");
263  }
264 
265  return '';
266  }
267 
269  {
270  if (strlen($this->getQuestionRelatedObjectives())) {
271  $label = $this->lng->txt('tst_res_lo_objectives_header');
272  return $label . ': ' . $this->getQuestionRelatedObjectives();
273  }
274 
275  return '';
276  }
277  // fau.
278 
279 
280  // fau: testNav - split generation of presentation title and question info
281 
287  public function getPresentationTitle()
288  {
289  switch ($this->getHeaderMode()) {
290  case 2: // neither titles nor points => show position as title
291  return $this->buildQuestionPositionString();
292  break;
293 
294  case 0: // titles and points => show title here
295  case 1: // only titles => show title here
296  default:
297  return $this->getQuestionTitle();
298  }
299  }
300 
301 
307  public function getQuestionInfoHTML()
308  {
309  $tpl = new ilTemplate('tpl.tst_question_info.html', true, true, 'Modules/Test');
310 
311  // position and/or points
312  switch ($this->getHeaderMode()) {
313  case 1: // only titles => show position here
315  break;
316 
317  case 2: // neither titles nor points => position is separate title, show nothing here
318  $text = '';
319  break;
320 
321  case 0: // titles and points => show position and points here
322  default:
323  $text = $this->buildQuestionPositionString() . ' (' . $this->buildQuestionPointsString() . ')';
324  }
325  if ($this->isQuestionPostponed()) {
326  $text .= ($text ? ', ' : '') . $this->buildQuestionPostponedString();
327  }
328 
329  $tpl->setVariable('TXT_POSITION_POINTS', $text);
330 
331  // obligatory
332  if ($this->isQuestionObligatory() && !$this->isQuestionAnswered()) {
333  $tpl->setVariable('TXT_OBLIGATORY', $this->buildQuestionObligatoryString());
334  }
335 
336  // objectives
337  if (strlen($this->getQuestionRelatedObjectives())) {
338  $tpl->setVariable('TXT_OBJECTIVES', $this->buildQuestionRelatedObjectivesString());
339  }
340 
341  // answer status
342  if ($this->isQuestionAnswered()) {
343  $tpl->setVariable('HIDDEN_NOT_ANSWERED', 'hidden');
344  } else {
345  $tpl->setVariable('HIDDEN_ANSWERED', 'hidden');
346  }
347 
348  $tpl->setVariable('SRC_ANSWERED', ilUtil::getImagePath('answered.svg'));
349  $tpl->setVariable('SRC_NOT_ANSWERED', ilUtil::getImagePath('answered_not.svg'));
350  $tpl->setVariable('TXT_ANSWERED', $this->lng->txt('tst_answer_status_answered'));
351  $tpl->setVariable('TXT_NOT_ANSWERED', $this->lng->txt('tst_answer_status_not_answered'));
352  $tpl->setVariable('TXT_EDITING', $this->lng->txt('tst_answer_status_editing'));
353 
354  return $tpl->get();
355  }
356  // fau.
357 
358  public function getHTML()
359  {
360  $headerBlock = $this->buildQuestionPositionString();
361 
362  switch ($this->getHeaderMode()) {
363  case 1:
364 
365  $headerBlock .= " - " . $this->getQuestionTitle();
366  $headerBlock .= $this->buildQuestionPostponedString();
367  $headerBlock .= $this->buildQuestionObligatoryString();
368  break;
369 
370  case 2:
371 
372  $headerBlock .= $this->buildQuestionPostponedString();
373  $headerBlock .= $this->buildQuestionObligatoryString();
374  break;
375 
376  case 0:
377  default:
378 
379  $headerBlock .= " - " . $this->getQuestionTitle();
380  $headerBlock .= $this->buildQuestionPostponedString();
381 // fau: testNav - put the points in parentheses here, not in building the string
382  $headerBlock .= ' (' . $this->buildQuestionPointsString() . ')';
383 // fau.
384  $headerBlock .= $this->buildQuestionObligatoryString();
385  }
386 
387  $headerBlock .= $this->buildQuestionRelatedObjectivesString();
388 
389  return $headerBlock;
390  }
391 }
$tpl
Definition: ilias.php:10
getHTML()
Get the HTML representation of the header block.
getQuestionInfoHTML()
Get the additional question info and answering status This is shown below the title line in a test ru...
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
$text
Definition: errorreport.php:18
getPresentationTitle()
Get the presentation title of the question This is shown above the title line in a test run...
language handling