ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilAssNestedOrderingElementsInputGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
29  public const CONTEXT_QUESTION_PREVIEW = 'QuestionPreview';
30  public const CONTEXT_CORRECT_SOLUTION_PRESENTATION = 'CorrectSolutionPresent';
31  public const CONTEXT_USER_SOLUTION_PRESENTATION = 'UserSolutionPresent';
32  public const CONTEXT_USER_SOLUTION_SUBMISSION = 'UserSolutionSubmit';
33 
34  public const ILC_CSS_CLASS_LIST = 'ilc_qordul_OrderList';
35  public const ILC_CSS_CLASS_ITEM = 'ilc_qordli_OrderListItem';
36 
37  public const DEFAULT_THUMBNAIL_PREFIX = 'thumb.';
38 
42  protected $context = null;
43 
47  protected $uniquePrefix = null;
48 
52  protected $orderingType = null;
53 
57  protected $thumbnailFilenamePrefix = self::DEFAULT_THUMBNAIL_PREFIX;
58 
62  protected $elementImagePath = null;
63 
67  protected $showCorrectnessIconsEnabled = false;
68 
72  protected $correctnessTrueElementList = null;
73 
74  private UIServices $ui;
75 
82  public function __construct(ilAssOrderingFormValuesObjectsConverter $converter, $postVar)
83  {
84  global $DIC;
85  $this->ui = $DIC->ui();
86  $manipulator = new ilAssOrderingDefaultElementFallback();
87  $this->addFormValuesManipulator($manipulator);
88 
89  parent::__construct('', $postVar);
90 
91  $this->addFormValuesManipulator($converter);
92 
93  $this->setHtmlListTag(parent::HTML_LIST_TAG_UL);
94  $this->setCssListClass($this->getCssListClass() . ' ' . self::ILC_CSS_CLASS_LIST);
95  $this->setCssItemClass($this->getCssItemClass() . ' ' . self::ILC_CSS_CLASS_ITEM);
96  $this->setCssHandleClass($this->getCssHandleClass());
97  }
98 
102  public function setElementList(ilAssOrderingElementList $elementList): void
103  {
105  }
106 
111  public function getElementList($questionId): ilAssOrderingElementList
112  {
114  }
115 
119  public function prepareReprintable(assQuestion $question): void
120  {
121  $elementList = $this->getElementList($question->getId());
122 
123  $elementList->completeContentsFromElementList(
124  $question->getOrderingElementList()
125  );
126 
127  $this->setElementList($elementList);
128  }
129 
130  public function getInstanceId(): string
131  {
132  if (!$this->getContext() || !$this->getUniquePrefix()) {
133  return parent::getInstanceId();
134  }
135 
136  return $this->getContext() . '_' . $this->getUniquePrefix();
137  }
138 
142  public function getContext(): ?string
143  {
144  return $this->context;
145  }
146 
150  public function setContext($context): void
151  {
152  $this->context = $context;
153  }
154 
158  public function getUniquePrefix()
159  {
160  return $this->uniquePrefix;
161  }
162 
166  public function setUniquePrefix($uniquePrefix): void
167  {
168  $this->uniquePrefix = $uniquePrefix;
169  }
170 
174  public function setOrderingType($orderingType): void
175  {
176  $this->orderingType = $orderingType;
177  }
178 
182  public function getOrderingType()
183  {
184  return $this->orderingType;
185  }
186 
190  public function setElementImagePath($elementImagePath): void
191  {
192  $this->elementImagePath = $elementImagePath;
193  }
194 
198  public function getElementImagePath(): ?string
199  {
201  }
202 
207  {
208  $this->thumbnailFilenamePrefix = $thumbnailFilenamePrefix;
209  }
210 
214  public function getThumbPrefix(): string
215  {
217  }
218 
223  {
224  $this->showCorrectnessIconsEnabled = $showCorrectnessIconsEnabled;
225  }
226 
230  public function isShowCorrectnessIconsEnabled(): bool
231  {
233  }
234 
239  {
241  }
242 
247  {
248  $this->correctnessTrueElementList = $correctnessTrueElementList;
249  }
250 
255  protected function getCorrectness($identifier): bool
256  {
257  return $this->getCorrectnessTrueElementList()->elementExistByRandomIdentifier($identifier);
258  }
259 
260  private function getCorrectnessIcon($correctness): string
261  {
262  $icon_name = 'standard/icon_not_ok.svg';
263  $label = $this->lng->txt("answer_is_wrong");
264  if ($correctness === 'correct') {
265  $icon_name = 'standard/icon_ok.svg';
266  $label = $this->lng->txt("answer_is_right");
267  }
268  $path = ilUtil::getImagePath($icon_name);
269  $icon = $this->ui->factory()->symbol()->icon()->custom(
270  $path,
271  $label
272  );
273  return $this->ui->renderer()->render($icon);
274  }
275 
279  protected function getItemTemplate(): ilTemplate
280  {
281  return new ilTemplate('tpl.prop_ass_nested_order_elem.html', true, true, 'Modules/TestQuestionPool');
282  }
283 
287  protected function getThumbnailFilename($element): string
288  {
289  return $this->getThumbPrefix() . $element['content'];
290  }
291 
295  protected function getThumbnailSource($element): string
296  {
297  return $this->getElementImagePath() . $this->getThumbnailFilename($element);
298  }
299 
308  protected function getItemHtml($element, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId): string
309  {
310  $tpl = $this->getItemTemplate();
311 
312  switch ($this->getOrderingType()) {
315 
316  $tpl->setCurrentBlock('item_text');
317  $tpl->setVariable("ITEM_CONTENT", ilLegacyFormElementsUtil::prepareFormOutput($element['content']));
318  $tpl->parseCurrentBlock();
319  break;
320 
323 
324  $tpl->setCurrentBlock('item_image');
325  $tpl->setVariable("ITEM_SOURCE", $this->getThumbnailSource($element));
326  $tpl->setVariable("ITEM_CONTENT", $this->getThumbnailFilename($element));
327  $tpl->parseCurrentBlock();
328  break;
329  }
330 
331  if ($this->isShowCorrectnessIconsEnabled()) {
332  $correctness = 'not_correct';
333  if ($this->getCorrectness($identifier)) {
334  $correctness = 'correct';
335  }
336  $tpl->setCurrentBlock('correctness_icon');
337 
338  $tpl->setVariable("ICON_OK", $this->getCorrectnessIcon($correctness));
339  $tpl->parseCurrentBlock();
340  }
341 
342  $tpl->setCurrentBlock('item');
343  $tpl->setVariable("ITEM_ID", $itemSubFieldId);
344  $tpl->setVariable("ITEM_POSTVAR", $itemSubFieldPostVar);
345  $tpl->setVariable("ITEM_CONTENT", ilLegacyFormElementsUtil::prepareFormOutput($element['content']));
346  $tpl->parseCurrentBlock();
347 
348  return $tpl->get();
349  }
350 
356  protected function getCurrentIndentation($elementValues, $elementCounter): int
357  {
358  if (!isset($elementValues[$elementCounter])) {
359  return 0;
360  }
361 
362  return $elementValues[$elementCounter]['ordering_indentation'];
363  }
364 
370  protected function getNextIndentation($elementValues, $elementCounter): int
371  {
372  if (!isset($elementValues[$elementCounter + 1])) {
373  return 0;
374  }
375 
376  return $elementValues[$elementCounter + 1]['ordering_indentation'];
377  }
378 
379  public function isPostSubmit($data): bool
380  {
381  if (!is_array($data)) {
382  return false;
383  }
384 
385  if (!isset($data[$this->getPostVar()])) {
386  return false;
387  }
388 
389  if (!count($data[$this->getPostVar()])) {
390  return false;
391  }
392 
393  return true;
394  }
395 }
getItemHtml($element, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId)
__construct(ilAssOrderingFormValuesObjectsConverter $converter, $postVar)
ilAssNestedOrderingElementsInputGUI constructor.
Abstract basic class which is to be extended by the concrete assessment question type classes...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static buildInstance(int $question_id, array $elements=[])
static prepareFormOutput($a_str, bool $a_strip=false)
$path
Definition: ltiservices.php:32
setCorrectnessTrueElementList(ilAssOrderingElementList $correctnessTrueElementList)
global $DIC
Definition: feed.php:28
Provides fluid interface to RBAC services.
Definition: UIServices.php:23
__construct(VocabulariesInterface $vocabularies)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addFormValuesManipulator(ilFormValuesManipulator $manipulator)