ILIAS  release_7 Revision v7.30-3-g800a261c036
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 
22  const DEFAULT_THUMBNAIL_PREFIX = 'thumb.';
23 
27  protected $context = null;
28 
32  protected $uniquePrefix = null;
33 
37  protected $orderingType = null;
38 
42  protected $thumbnailFilenamePrefix = self::DEFAULT_THUMBNAIL_PREFIX;
43 
47  protected $elementImagePath = null;
48 
52  protected $showCorrectnessIconsEnabled = false;
53 
57  protected $correctnessTrueElementList = null;
58 
65  public function __construct(ilAssOrderingFormValuesObjectsConverter $converter, $postVar)
66  {
67  require_once 'Modules/TestQuestionPool/classes/forms/class.ilAssOrderingDefaultElementFallback.php';
68  $manipulator = new ilAssOrderingDefaultElementFallback();
69  $this->addFormValuesManipulator($manipulator);
70 
71  parent::__construct('', $postVar);
72 
73  $this->addFormValuesManipulator($converter);
74 
75  $this->setHtmlListTag(parent::HTML_LIST_TAG_UL);
76  $this->setCssListClass($this->getCssListClass() . ' ' . self::ILC_CSS_CLASS_LIST);
77  $this->setCssItemClass($this->getCssItemClass() . ' ' . self::ILC_CSS_CLASS_ITEM);
78  $this->setCssHandleClass($this->getCssHandleClass());
79  }
80 
84  public function setElementList(ilAssOrderingElementList $elementList)
85  {
87  }
88 
93  public function getElementList($questionId)
94  {
95  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssOrderingElementList.php';
97  }
98 
102  public function prepareReprintable(assQuestion $question)
103  {
104  $elementList = $this->getElementList($question->getId());
105 
106  $elementList->completeContentsFromElementList(
107  $question->getOrderingElementList()
108  );
109 
110  $this->setElementList($elementList);
111  }
112 
113  public function getInstanceId()
114  {
115  if (!$this->getContext() || !$this->getUniquePrefix()) {
116  return parent::getInstanceId();
117  }
118 
119  return $this->getContext() . '_' . $this->getUniquePrefix();
120  }
121 
125  public function getContext()
126  {
127  return $this->context;
128  }
129 
133  public function setContext($context)
134  {
135  $this->context = $context;
136  }
137 
141  public function getUniquePrefix()
142  {
143  return $this->uniquePrefix;
144  }
145 
150  {
151  $this->uniquePrefix = $uniquePrefix;
152  }
153 
158  {
159  $this->orderingType = $orderingType;
160  }
161 
165  public function getOrderingType()
166  {
167  return $this->orderingType;
168  }
169 
174  {
175  $this->elementImagePath = $elementImagePath;
176  }
177 
181  public function getElementImagePath()
182  {
184  }
185 
190  {
191  $this->thumbnailFilenamePrefix = $thumbnailFilenamePrefix;
192  }
193 
197  public function getThumbPrefix()
198  {
200  }
201 
206  {
207  $this->showCorrectnessIconsEnabled = $showCorrectnessIconsEnabled;
208  }
209 
214  {
216  }
217 
222  public function getCorrectnessIconFilename($correctness)
223  {
224  if((bool) $correctness){
225  return ilUtil::getImagePath('icon_ok.svg');
226  }
227  return ilUtil::getImagePath('icon_not_ok.svg');
228  }
229 
234  public function getCorrectnessText($correctness)
235  {
236  global $DIC; /* @var ILIAS\DI\Container $DIC */
237  $lng = $DIC['lng'];
238  if ((bool) $correctness){
239  return $lng->txt('answer_is_right');
240  }
241  return $lng->txt('answer_is_wrong');
242 
243  }
244 
249  {
251  }
252 
257  {
258  $this->correctnessTrueElementList = $correctnessTrueElementList;
259  }
260 
265  protected function getCorrectness($identifier)
266  {
267  return $this->getCorrectnessTrueElementList()->elementExistByRandomIdentifier($identifier);
268  }
269 
273  protected function getItemTemplate()
274  {
275  return new ilTemplate('tpl.prop_ass_nested_order_elem.html', true, true, 'Modules/TestQuestionPool');
276  }
277 
282  protected function getThumbnailFilename($element)
283  {
284  return $this->getThumbPrefix() . $element['content'];
285  }
286 
291  protected function getThumbnailSource($element)
292  {
293  return $this->getElementImagePath() . $this->getThumbnailFilename($element);
294  }
295 
304  protected function getItemHtml($element, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId)
305  {
306  $tpl = $this->getItemTemplate();
307 
308  switch ($this->getOrderingType()) {
311 
312  $tpl->setCurrentBlock('item_text');
313  $tpl->setVariable("ITEM_CONTENT", ilUtil::prepareFormOutput($element['content']));
314  $tpl->parseCurrentBlock();
315  break;
316 
319 
320  $tpl->setCurrentBlock('item_image');
321  $tpl->setVariable("ITEM_SOURCE", $this->getThumbnailSource($element));
322  $tpl->setVariable("ITEM_CONTENT", $this->getThumbnailFilename($element));
323  $tpl->parseCurrentBlock();
324  break;
325  }
326 
327  if ($this->isShowCorrectnessIconsEnabled()) {
328  $tpl->setCurrentBlock('correctness_icon');
329  $correctness = $this->getCorrectness($element['random_id']);
330  $tpl->setVariable("ICON_SRC", $this->getCorrectnessIconFilename($correctness));
331  $tpl->setVariable("ICON_TEXT", $this->getCorrectnessText($correctness));
332  $tpl->parseCurrentBlock();
333  }
334 
335  $tpl->setCurrentBlock('item');
336  $tpl->setVariable("ITEM_ID", $itemSubFieldId);
337  $tpl->setVariable("ITEM_POSTVAR", $itemSubFieldPostVar);
338  $tpl->setVariable("ITEM_CONTENT", ilUtil::prepareFormOutput($element['content']));
339  $tpl->parseCurrentBlock();
340 
341  return $tpl->get();
342  }
343 
349  protected function getCurrentIndentation($elementValues, $elementCounter)
350  {
351  if (!isset($elementValues[$elementCounter])) {
352  return 0;
353  }
354 
355  return $elementValues[$elementCounter]['ordering_indentation'];
356  }
357 
363  protected function getNextIndentation($elementValues, $elementCounter)
364  {
365  if (!isset($elementValues[$elementCounter + 1])) {
366  return 0;
367  }
368 
369  return $elementValues[$elementCounter + 1]['ordering_indentation'];
370  }
371 
372  public function isPostSubmit($data)
373  {
374  if (!is_array($data)) {
375  return false;
376  }
377 
378  if (!isset($data[$this->getPostVar()])) {
379  return false;
380  }
381 
382  if (!count($data[$this->getPostVar()])) {
383  return false;
384  }
385 
386  return true;
387  }
388 }
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)
$data
Definition: storeScorm.php:23
__construct(ilAssOrderingFormValuesObjectsConverter $converter, $postVar)
ilAssNestedOrderingElementsInputGUI constructor.
Abstract basic class which is to be extended by the concrete assessment question type classes...
getPostVar()
Get Post Variable.
static buildInstance(int $question_id, array $elements=[])
setCorrectnessTrueElementList(ilAssOrderingElementList $correctnessTrueElementList)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
addFormValuesManipulator(ilFormValuesManipulator $manipulator)