ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
66  protected $correctnessLngVars = array(
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  global $DIC; /* @var ILIAS\DI\Container $DIC */
282  $lng = $DIC['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  case OQ_TERMS:
351  case OQ_NESTED_TERMS:
352 
353  $tpl->setCurrentBlock('item_text');
354  $tpl->setVariable("ITEM_CONTENT", ilUtil::prepareFormOutput($element['content']));
355  $tpl->parseCurrentBlock();
356  break;
357 
358  case OQ_PICTURES:
359  case OQ_NESTED_PICTURES:
360 
361  $tpl->setCurrentBlock('item_image');
362  $tpl->setVariable("ITEM_SOURCE", $this->getThumbnailSource($element));
363  $tpl->setVariable("ITEM_CONTENT", $this->getThumbnailFilename($element));
364  $tpl->parseCurrentBlock();
365  break;
366  }
367 
368  if ($this->isShowCorrectnessIconsEnabled()) {
369  $tpl->setCurrentBlock('correctness_icon');
370  $tpl->setVariable("ICON_SRC", $this->getCorrectnessIconFilename($this->getCorrectness($identifier)));
371  $tpl->setVariable("ICON_TEXT", $this->getCorrectnessText($this->getCorrectness($identifier)));
372  $tpl->parseCurrentBlock();
373  }
374 
375  $tpl->setCurrentBlock('item');
376  $tpl->setVariable("ITEM_ID", $itemSubFieldId);
377  $tpl->setVariable("ITEM_POSTVAR", $itemSubFieldPostVar);
378  $tpl->setVariable("ITEM_CONTENT", ilUtil::prepareFormOutput($element['content']));
379  $tpl->parseCurrentBlock();
380 
381  return $tpl->get();
382  }
383 
389  protected function getCurrentIndentation($elementValues, $elementCounter)
390  {
391  if (!isset($elementValues[$elementCounter])) {
392  return 0;
393  }
394 
395  return $elementValues[$elementCounter]['ordering_indentation'];
396  }
397 
403  protected function getNextIndentation($elementValues, $elementCounter)
404  {
405  if (!isset($elementValues[$elementCounter + 1])) {
406  return 0;
407  }
408 
409  return $elementValues[$elementCounter + 1]['ordering_indentation'];
410  }
411 
412  public function isPostSubmit($data)
413  {
414  if (!is_array($data)) {
415  return false;
416  }
417 
418  if (!isset($data[$this->getPostVar()])) {
419  return false;
420  }
421 
422  if (!count($data[$this->getPostVar()])) {
423  return false;
424  }
425 
426  return true;
427  }
428 }
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.
global $DIC
Definition: saml.php:7
$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
static buildInstance($questionId, $orderingElements=array())
setCorrectnessTrueElementList(ilAssOrderingElementList $correctnessTrueElementList)
const OQ_PICTURES
Ordering question constants.
special template class to simplify handling of ITX/PEAR
const OQ_TERMS
const OQ_NESTED_PICTURES
addFormValuesManipulator(ilFormValuesManipulator $manipulator)
$data
Definition: bench.php:6