ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_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 
43  protected $thumbnailFilenamePrefix = self::DEFAULT_THUMBNAIL_PREFIX;
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 
67  true => self::CORRECTNESS_LNGVAR_TRUE, false => self::CORRECTNESS_LNGVAR_FALSE
68  );
69 
73  protected $showCorrectnessIconsEnabled = false;
74 
78  protected $correctnessTrueElementList = null;
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  return parent::getInstanceId();
138  }
139 
140  return $this->getContext() . '_' . $this->getUniquePrefix();
141  }
142 
146  public function getContext()
147  {
148  return $this->context;
149  }
150 
154  public function setContext($context)
155  {
156  $this->context = $context;
157  }
158 
162  public function getUniquePrefix()
163  {
164  return $this->uniquePrefix;
165  }
166 
171  {
172  $this->uniquePrefix = $uniquePrefix;
173  }
174 
179  {
180  $this->orderingType = $orderingType;
181  }
182 
186  public function getOrderingType()
187  {
188  return $this->orderingType;
189  }
190 
195  {
196  $this->elementImagePath = $elementImagePath;
197  }
198 
202  public function getElementImagePath()
203  {
205  }
206 
211  {
212  $this->thumbnailFilenamePrefix = $thumbnailFilenamePrefix;
213  }
214 
218  public function getThumbPrefix()
219  {
221  }
222 
227  {
228  $this->showCorrectnessIconsEnabled = $showCorrectnessIconsEnabled;
229  }
230 
235  {
237  }
238 
243  public function getCorrectnessIconFilename($correctness)
244  {
245  return $this->correctnessIcons[(bool) $correctness];
246  }
247 
252  public function setCorrectnessIconFilename($correctness, $iconFilename)
253  {
254  $this->correctnessIcons[(bool) $correctness] = $iconFilename;
255  }
256 
261  public function getCorrectnessLangVar($correctness)
262  {
263  return $this->correctnessLngVars[(bool) $correctness];
264  }
265 
270  public function setCorrectnessLangVar($correctness, $langVar)
271  {
272  $this->correctnessLngVars[(bool) $correctness] = $langVar;
273  }
274 
279  public function getCorrectnessText($correctness)
280  {
281  $lng = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['lng'] : $GLOBALS['lng'];
282  return $lng->txt($this->correctnessLngVars[(bool) $correctness]);
283  }
284 
289  {
291  }
292 
297  {
298  $this->correctnessTrueElementList = $correctnessTrueElementList;
299  }
300 
305  protected function getCorrectness($identifier)
306  {
307  return $this->getCorrectnessTrueElementList()->elementExistByRandomIdentifier($identifier);
308  }
309 
313  protected function getItemTemplate()
314  {
315  return new ilTemplate('tpl.prop_ass_nested_order_elem.html', true, true, 'Modules/TestQuestionPool');
316  }
317 
322  protected function getThumbnailFilename($element)
323  {
324  return $this->getThumbPrefix() . $element['content'];
325  }
326 
331  protected function getThumbnailSource($element)
332  {
333  return $this->getElementImagePath() . $this->getThumbnailFilename($element);
334  }
335 
344  protected function getItemHtml($element, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId)
345  {
346  $tpl = $this->getItemTemplate();
347 
348  switch ($this->getOrderingType()) {
349  case OQ_TERMS:
350  case OQ_NESTED_TERMS:
351 
352  $tpl->setCurrentBlock('item_text');
353  $tpl->setVariable("ITEM_CONTENT", ilUtil::prepareFormOutput($element['content']));
354  $tpl->parseCurrentBlock();
355  break;
356 
357  case OQ_PICTURES:
358  case OQ_NESTED_PICTURES:
359 
360  $tpl->setCurrentBlock('item_image');
361  $tpl->setVariable("ITEM_SOURCE", $this->getThumbnailSource($element));
362  $tpl->setVariable("ITEM_CONTENT", $this->getThumbnailFilename($element));
363  $tpl->parseCurrentBlock();
364  break;
365  }
366 
367  if ($this->isShowCorrectnessIconsEnabled()) {
368  $tpl->setCurrentBlock('correctness_icon');
369  $tpl->setVariable("ICON_SRC", $this->getCorrectnessIconFilename($this->getCorrectness($identifier)));
370  $tpl->setVariable("ICON_TEXT", $this->getCorrectnessText($this->getCorrectness($identifier)));
371  $tpl->parseCurrentBlock();
372  }
373 
374  $tpl->setCurrentBlock('item');
375  $tpl->setVariable("ITEM_ID", $itemSubFieldId);
376  $tpl->setVariable("ITEM_POSTVAR", $itemSubFieldPostVar);
377  $tpl->setVariable("ITEM_CONTENT", ilUtil::prepareFormOutput($element['content']));
378  $tpl->parseCurrentBlock();
379 
380  return $tpl->get();
381  }
382 
388  protected function getCurrentIndentation($elementValues, $elementCounter)
389  {
390  if (!isset($elementValues[$elementCounter])) {
391  return 0;
392  }
393 
394  return $elementValues[$elementCounter]['ordering_indentation'];
395  }
396 
402  protected function getNextIndentation($elementValues, $elementCounter)
403  {
404  if (!isset($elementValues[$elementCounter + 1])) {
405  return 0;
406  }
407 
408  return $elementValues[$elementCounter + 1]['ordering_indentation'];
409  }
410 
411  public function isPostSubmit($data)
412  {
413  if (!is_array($data)) {
414  return false;
415  }
416 
417  if (!isset($data[$this->getPostVar()])) {
418  return false;
419  }
420 
421  if (!count($data[$this->getPostVar()])) {
422  return false;
423  }
424 
425  return true;
426  }
427 }
getId()
Gets the id of the assQuestion object.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getItemHtml($element, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId)
__construct(ilAssOrderingFormValuesObjectsConverter $converter, $postVar)
ilAssNestedOrderingElementsInputGUI constructor.
$tpl
Definition: ilias.php:10
Abstract basic class which is to be extended by the concrete assessment question type classes...
getPostVar()
Get Post Variable.
const OQ_NESTED_TERMS
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static buildInstance($questionId, $orderingElements=array())
setCorrectnessTrueElementList(ilAssOrderingElementList $correctnessTrueElementList)
const OQ_PICTURES
Ordering question constants.
special template class to simplify handling of ITX/PEAR
Create styles array
The data for the language used.
const OQ_TERMS
const OQ_NESTED_PICTURES
addFormValuesManipulator(ilFormValuesManipulator $manipulator)