ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
4require_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
38
42 protected $questionCount;
43
48
53
58
59// fau: testNav - answer status variable
64// fau.
65
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 {
102 }
103
108 {
109 $this->questionTitle = $questionTitle;
110 }
111
115 public function getQuestionPoints()
116 {
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 {
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 {
231 return '';
232 }
233
234 if( $this->getQuestionCount() )
235 {
236 return sprintf($this->lng->txt("tst_position"), $this->getQuestionPosition(), $this->getQuestionCount());
237 }
238
239 return sprintf($this->lng->txt("tst_position_without_total"), $this->getQuestionPosition());
240 }
241
242// fau: testNav - remove HTML from building strings (is now in tpl.tst_question_info.html)
243 protected function buildQuestionPointsString()
244 {
245 if( $this->getQuestionPoints() == 1 )
246 {
247 return "{$this->getQuestionPoints()} {$this->lng->txt('point')}";
248 }
249
250 return "{$this->getQuestionPoints()} {$this->lng->txt('points')}";
251 }
252
253 protected function buildQuestionPostponedString()
254 {
255 if( $this->isQuestionPostponed() )
256 {
257 return $this->lng->txt("postponed");
258 }
259
260 return '';
261 }
262
263 protected function buildQuestionObligatoryString()
264 {
265 if( $this->isQuestionObligatory() )
266 {
267 return $this->lng->txt("tst_you_have_to_answer_this_question");
268 }
269
270 return '';
271 }
272
274 {
275 if( strlen($this->getQuestionRelatedObjectives()) )
276 {
277 $label = $this->lng->txt('tst_res_lo_objectives_header');
278 return $label.': '.$this->getQuestionRelatedObjectives();
279 }
280
281 return '';
282 }
283// fau.
284
285
286// fau: testNav - split generation of presentation title and question info
287
293 public function getPresentationTitle()
294 {
295 switch( $this->getHeaderMode() )
296 {
297 case 2: // neither titles nor points => show position as title
298 return $this->buildQuestionPositionString();
299 break;
300
301 case 0: // titles and points => show title here
302 case 1: // only titles => show title here
303 default:
304 return $this->getQuestionTitle();
305 }
306 }
307
308
314 public function getQuestionInfoHTML()
315 {
316 $tpl = new ilTemplate('tpl.tst_question_info.html', true, true, 'Modules/Test');
317
318 // position and/or points
319 switch( $this->getHeaderMode() )
320 {
321 case 1: // only titles => show position here
323 break;
324
325 case 2: // neither titles nor points => position is separate title, show nothing here
326 $text = '';
327 break;
328
329 case 0: // titles and points => show position and points here
330 default:
331 $text = $this->buildQuestionPositionString() . ' (' . $this->buildQuestionPointsString() . ')';
332 }
333 if ($this->isQuestionPostponed())
334 {
335 $text .= ($text ? ', ' : '') . $this->buildQuestionPostponedString();
336 }
337
338 $tpl->setVariable('TXT_POSITION_POINTS',$text);
339
340 // obligatory
341 if ($this->isQuestionObligatory() && !$this->isQuestionAnswered())
342 {
343 $tpl->setVariable('TXT_OBLIGATORY', $this->buildQuestionObligatoryString());
344 }
345
346 // objectives
347 if (strlen($this->getQuestionRelatedObjectives()) )
348 {
349 $tpl->setVariable('TXT_OBJECTIVES', $this->buildQuestionRelatedObjectivesString());
350 }
351
352 // answer status
353 if ($this->isQuestionAnswered())
354 {
355 $tpl->setVariable('HIDDEN_NOT_ANSWERED', 'hidden');
356 }
357 else
358 {
359 $tpl->setVariable('HIDDEN_ANSWERED', 'hidden');
360 }
361
362 $tpl->setVariable('SRC_ANSWERED', ilUtil::getImagePath('answered.svg'));
363 $tpl->setVariable('SRC_NOT_ANSWERED', ilUtil::getImagePath('answered_not.svg'));
364 $tpl->setVariable('TXT_ANSWERED', $this->lng->txt('tst_answer_status_answered'));
365 $tpl->setVariable('TXT_NOT_ANSWERED', $this->lng->txt('tst_answer_status_not_answered'));
366 $tpl->setVariable('TXT_EDITING', $this->lng->txt('tst_answer_status_editing'));
367
368 return $tpl->get();
369 }
370// fau.
371
372 public function getHTML()
373 {
374 $headerBlock = $this->buildQuestionPositionString();
375
376 switch( $this->getHeaderMode() )
377 {
378 case 1:
379
380 $headerBlock .= " - ".$this->getQuestionTitle();
381 $headerBlock .= $this->buildQuestionPostponedString();
382 $headerBlock .= $this->buildQuestionObligatoryString();
383 break;
384
385 case 2:
386
387 $headerBlock .= $this->buildQuestionPostponedString();
388 $headerBlock .= $this->buildQuestionObligatoryString();
389 break;
390
391 case 0:
392 default:
393
394 $headerBlock .= " - ".$this->getQuestionTitle();
395 $headerBlock .= $this->buildQuestionPostponedString();
396// fau: testNav - put the points in parentheses here, not in building the string
397 $headerBlock .= ' ('.$this->buildQuestionPointsString().')';
398// fau.
399 $headerBlock .= $this->buildQuestionObligatoryString();
400 }
401
402 $headerBlock .= $this->buildQuestionRelatedObjectivesString();
403
404 return $headerBlock;
405 }
406}
sprintf('%.4f', $callTime)
global $tpl
Definition: ilias.php:8
An exception for terminatinating execution or to throw for unit testing.
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($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$text