ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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  {
113  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssOrderingElementList.php';
115  }
116 
120  public function prepareReprintable(assQuestion $question): void
121  {
122  $elementList = $this->getElementList($question->getId());
123 
124  $elementList->completeContentsFromElementList(
125  $question->getOrderingElementList()
126  );
127 
128  $this->setElementList($elementList);
129  }
130 
131  public function getInstanceId(): string
132  {
133  if (!$this->getContext() || !$this->getUniquePrefix()) {
134  return parent::getInstanceId();
135  }
136 
137  return $this->getContext() . '_' . $this->getUniquePrefix();
138  }
139 
143  public function getContext(): ?string
144  {
145  return $this->context;
146  }
147 
151  public function setContext($context): void
152  {
153  $this->context = $context;
154  }
155 
159  public function getUniquePrefix()
160  {
161  return $this->uniquePrefix;
162  }
163 
167  public function setUniquePrefix($uniquePrefix): void
168  {
169  $this->uniquePrefix = $uniquePrefix;
170  }
171 
175  public function setOrderingType($orderingType): void
176  {
177  $this->orderingType = $orderingType;
178  }
179 
183  public function getOrderingType()
184  {
185  return $this->orderingType;
186  }
187 
191  public function setElementImagePath($elementImagePath): void
192  {
193  $this->elementImagePath = $elementImagePath;
194  }
195 
199  public function getElementImagePath(): ?string
200  {
202  }
203 
208  {
209  $this->thumbnailFilenamePrefix = $thumbnailFilenamePrefix;
210  }
211 
215  public function getThumbPrefix(): string
216  {
218  }
219 
224  {
225  $this->showCorrectnessIconsEnabled = $showCorrectnessIconsEnabled;
226  }
227 
231  public function isShowCorrectnessIconsEnabled(): bool
232  {
234  }
235 
240  {
242  }
243 
248  {
249  $this->correctnessTrueElementList = $correctnessTrueElementList;
250  }
251 
256  protected function getCorrectness($identifier): bool
257  {
258  return $this->getCorrectnessTrueElementList()->elementExistByRandomIdentifier($identifier);
259  }
260 
261  private function getCorrectnessIcon($correctness): string
262  {
263  $icon_name = 'icon_not_ok.svg';
264  $label = $this->lng->txt("answer_is_wrong");
265  if ($correctness === 'correct') {
266  $icon_name = 'icon_ok.svg';
267  $label = $this->lng->txt("answer_is_right");
268  }
269  $path = ilUtil::getImagePath($icon_name);
270  $icon = $this->ui->factory()->symbol()->icon()->custom(
271  $path,
272  $label
273  );
274  return $this->ui->renderer()->render($icon);
275  }
276 
280  protected function getItemTemplate(): ilTemplate
281  {
282  return new ilTemplate('tpl.prop_ass_nested_order_elem.html', true, true, 'Modules/TestQuestionPool');
283  }
284 
288  protected function getThumbnailFilename($element): string
289  {
290  return $this->getThumbPrefix() . $element['content'];
291  }
292 
296  protected function getThumbnailSource($element): string
297  {
298  return $this->getElementImagePath() . $this->getThumbnailFilename($element);
299  }
300 
309  protected function getItemHtml($element, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId): string
310  {
311  $tpl = $this->getItemTemplate();
312 
313  switch ($this->getOrderingType()) {
316 
317  $tpl->setCurrentBlock('item_text');
318  $tpl->setVariable("ITEM_CONTENT", ilLegacyFormElementsUtil::prepareFormOutput($element['content']));
319  $tpl->parseCurrentBlock();
320  break;
321 
324 
325  $tpl->setCurrentBlock('item_image');
326  $tpl->setVariable("ITEM_SOURCE", $this->getThumbnailSource($element));
327  $tpl->setVariable("ITEM_CONTENT", $this->getThumbnailFilename($element));
328  $tpl->parseCurrentBlock();
329  break;
330  }
331 
332  if ($this->isShowCorrectnessIconsEnabled()) {
333  $correctness = 'not_correct';
334  if ($this->getCorrectness($identifier)) {
335  $correctness = 'correct';
336  }
337  $tpl->setCurrentBlock('correctness_icon');
338 
339  $tpl->setVariable("ICON_OK", $this->getCorrectnessIcon($correctness));
340  $tpl->parseCurrentBlock();
341  }
342 
343  $tpl->setCurrentBlock('item');
344  $tpl->setVariable("ITEM_ID", $itemSubFieldId);
345  $tpl->setVariable("ITEM_POSTVAR", $itemSubFieldPostVar);
346  $tpl->setVariable("ITEM_CONTENT", ilLegacyFormElementsUtil::prepareFormOutput($element['content']));
347  $tpl->parseCurrentBlock();
348 
349  return $tpl->get();
350  }
351 
357  protected function getCurrentIndentation($elementValues, $elementCounter): int
358  {
359  if (!isset($elementValues[$elementCounter])) {
360  return 0;
361  }
362 
363  return $elementValues[$elementCounter]['ordering_indentation'];
364  }
365 
371  protected function getNextIndentation($elementValues, $elementCounter): int
372  {
373  if (!isset($elementValues[$elementCounter + 1])) {
374  return 0;
375  }
376 
377  return $elementValues[$elementCounter + 1]['ordering_indentation'];
378  }
379 
380  public function isPostSubmit($data): bool
381  {
382  if (!is_array($data)) {
383  return false;
384  }
385 
386  if (!isset($data[$this->getPostVar()])) {
387  return false;
388  }
389 
390  if (!count($data[$this->getPostVar()])) {
391  return false;
392  }
393 
394  return true;
395  }
396 }
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__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)