ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAssNestedOrderingElementsInputGUI.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 'Services/Form/classes/class.ilMultipleNestedOrderingElementsInputGUI.php';
5
13{
14 const CONTEXT_QUESTION_PREVIEW = 'QuestionPreview';
15 const CONTEXT_CORRECT_SOLUTION_PRESENTATION = 'CorrectSolutionPresent';
16 const CONTEXT_USER_SOLUTION_PRESENTATION = 'UserSolutionPresent';
17 const CONTEXT_USER_SOLUTION_SUBMISSION = 'UserSolutionSubmit';
18
19 const ILC_CSS_CLASS_LIST = 'ilc_qordul_OrderList';
20 const ILC_CSS_CLASS_ITEM = 'ilc_qordli_OrderListItem';
21 const ILC_CSS_CLASS_HANDLE = 'ilc_qanswer_Answer';
22
26 protected $context = null;
27
31 protected $uniquePrefix = null;
32
36 protected $orderingType = null;
37
38 const DEFAULT_THUMBNAIL_PREFIX = 'thumb.';
39
44
48 protected $elementImagePath = null;
49
50 const CORRECTNESS_ICON_TRUE = 'icon_ok.svg';
51 const CORRECTNESS_LNGVAR_TRUE = 'answer_is_right';
52
53 const CORRECTNESS_ICON_FALSE = 'icon_not_ok.svg';
54 const CORRECTNESS_LNGVAR_FALSE = 'answer_is_wrong';
55
59 protected $correctnessIcons = array(
60 true => self::CORRECTNESS_ICON_TRUE, false => self::CORRECTNESS_ICON_FALSE
61 );
62
66 protected $correctnessLngVars = array(
67 true => self::CORRECTNESS_LNGVAR_TRUE, false => self::CORRECTNESS_LNGVAR_FALSE
68 );
69
74
79
86 public function __construct(ilAssOrderingFormValuesObjectsConverter $converter, $postVar)
87 {
88 require_once 'Modules/TestQuestionPool/classes/forms/class.ilAssOrderingDefaultElementFallback.php';
89 $manipulator = new ilAssOrderingDefaultElementFallback();
90 $this->addFormValuesManipulator($manipulator);
91
92 parent::__construct('', $postVar);
93
94 $this->addFormValuesManipulator($converter);
95
96 $this->setHtmlListTag(parent::HTML_LIST_TAG_UL);
97 $this->setCssListClass($this->getCssListClass().' '.self::ILC_CSS_CLASS_LIST);
98 $this->setCssItemClass($this->getCssItemClass().' '.self::ILC_CSS_CLASS_ITEM);
99 $this->setCssHandleClass($this->getCssHandleClass().' '.self::ILC_CSS_CLASS_HANDLE);
100 }
101
105 public function setElementList(ilAssOrderingElementList $elementList)
106 {
108 }
109
114 public function getElementList($questionId)
115 {
116 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssOrderingElementList.php';
118 }
119
123 public function prepareReprintable(assQuestion $question)
124 {
125 $elementList = $this->getElementList($question->getId());
126
127 $elementList->completeContentsFromElementList(
128 $question->getOrderingElementList()
129 );
130
131 $this->setElementList($elementList);
132 }
133
134 public function getInstanceId()
135 {
136 if( !$this->getContext() || !$this->getUniquePrefix() )
137 {
138 return parent::getInstanceId();
139 }
140
141 return $this->getContext() . '_' . $this->getUniquePrefix();
142 }
143
147 public function getContext()
148 {
149 return $this->context;
150 }
151
155 public function setContext($context)
156 {
157 $this->context = $context;
158 }
159
163 public function getUniquePrefix()
164 {
165 return $this->uniquePrefix;
166 }
167
172 {
173 $this->uniquePrefix = $uniquePrefix;
174 }
175
180 {
181 $this->orderingType = $orderingType;
182 }
183
187 public function getOrderingType()
188 {
189 return $this->orderingType;
190 }
191
196 {
197 $this->elementImagePath = $elementImagePath;
198 }
199
203 public function getElementImagePath()
204 {
206 }
207
212 {
213 $this->thumbnailFilenamePrefix = $thumbnailFilenamePrefix;
214 }
215
219 public function getThumbPrefix()
220 {
222 }
223
228 {
229 $this->showCorrectnessIconsEnabled = $showCorrectnessIconsEnabled;
230 }
231
236 {
238 }
239
244 public function getCorrectnessIconFilename($correctness)
245 {
246 return $this->correctnessIcons[(bool)$correctness];
247 }
248
253 public function setCorrectnessIconFilename($correctness, $iconFilename)
254 {
255 $this->correctnessIcons[(bool)$correctness] = $iconFilename;
256 }
257
262 public function getCorrectnessLangVar($correctness)
263 {
264 return $this->correctnessLngVars[(bool)$correctness];
265 }
266
271 public function setCorrectnessLangVar($correctness, $langVar)
272 {
273 $this->correctnessLngVars[(bool)$correctness] = $langVar;
274 }
275
280 public function getCorrectnessText($correctness)
281 {
282 $lng = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['lng'] : $GLOBALS['lng'];
283 return $lng->txt( $this->correctnessLngVars[(bool)$correctness] );
284 }
285
290 {
292 }
293
298 {
299 $this->correctnessTrueElementList = $correctnessTrueElementList;
300 }
301
306 protected function getCorrectness($identifier)
307 {
308 return $this->getCorrectnessTrueElementList()->elementExistByRandomIdentifier($identifier);
309 }
310
314 protected function getItemTemplate()
315 {
316 return new ilTemplate('tpl.prop_ass_nested_order_elem.html', true, true, 'Modules/TestQuestionPool');
317 }
318
323 protected function getThumbnailFilename($element)
324 {
325 return $this->getThumbPrefix() . $element['content'];
326 }
327
332 protected function getThumbnailSource($element)
333 {
334 return $this->getElementImagePath() . $this->getThumbnailFilename($element);
335 }
336
345 protected function getItemHtml($element, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId)
346 {
347 $tpl = $this->getItemTemplate();
348
349 switch( $this->getOrderingType() )
350 {
351 case OQ_TERMS:
352 case OQ_NESTED_TERMS:
353
354 $tpl->setCurrentBlock('item_text');
355 $tpl->setVariable("ITEM_CONTENT", ilUtil::prepareFormOutput($element['content']));
356 $tpl->parseCurrentBlock();
357 break;
358
359 case OQ_PICTURES:
361
362 $tpl->setCurrentBlock('item_image');
363 $tpl->setVariable("ITEM_SOURCE", $this->getThumbnailSource($element));
364 $tpl->setVariable("ITEM_CONTENT", $this->getThumbnailFilename($element));
365 $tpl->parseCurrentBlock();
366 break;
367 }
368
369 if( $this->isShowCorrectnessIconsEnabled() )
370 {
371 $tpl->setCurrentBlock('correctness_icon');
372 $tpl->setVariable("ICON_SRC", $this->getCorrectnessIconFilename( $this->getCorrectness($identifier) ));
373 $tpl->setVariable("ICON_TEXT", $this->getCorrectnessText( $this->getCorrectness($identifier) ));
374 $tpl->parseCurrentBlock();
375 }
376
377 $tpl->setCurrentBlock('item');
378 $tpl->setVariable("ITEM_ID", $itemSubFieldId);
379 $tpl->setVariable("ITEM_POSTVAR", $itemSubFieldPostVar);
380 $tpl->setVariable("ITEM_CONTENT", ilUtil::prepareFormOutput($element['content']));
381 $tpl->parseCurrentBlock();
382
383 return $tpl->get();
384 }
385
391 protected function getCurrentIndentation($elementValues, $elementCounter)
392 {
393 if( !isset($elementValues[$elementCounter]) )
394 {
395 return 0;
396 }
397
398 return $elementValues[$elementCounter]['ordering_indentation'];
399 }
400
406 protected function getNextIndentation($elementValues, $elementCounter)
407 {
408 if( !isset($elementValues[$elementCounter + 1]) )
409 {
410 return 0;
411 }
412
413 return $elementValues[$elementCounter + 1]['ordering_indentation'];
414 }
415
416 public function isPostSubmit($data)
417 {
418 if( !is_array($data) )
419 {
420 return false;
421 }
422
423 if( !isset($data[$this->getPostVar()]) )
424 {
425 return false;
426 }
427
428 if( !count($data[$this->getPostVar()]) )
429 {
430 return false;
431 }
432
433 return true;
434 }
435
436}
global $tpl
Definition: ilias.php:8
An exception for terminatinating execution or to throw for unit testing.
Abstract basic class which is to be extended by the concrete assessment question type classes.
getId()
Gets the id of the assQuestion object.
setCorrectnessTrueElementList(ilAssOrderingElementList $correctnessTrueElementList)
getItemHtml($element, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId)
__construct(ilAssOrderingFormValuesObjectsConverter $converter, $postVar)
ilAssNestedOrderingElementsInputGUI constructor.
static buildInstance($questionId, $orderingElements=array())
getPostVar()
Get Post Variable.
addFormValuesManipulator(ilFormValuesManipulator $manipulator)
special template class to simplify handling of ITX/PEAR
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const OQ_NESTED_PICTURES
const OQ_TERMS
const OQ_NESTED_TERMS
const OQ_PICTURES
Ordering question constants.
global $lng
Definition: privfeed.php:17