ILIAS  release_8 Revision v8.24
class.ilMultipleNestedOrderingElementsInputGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 public const HTML_LIST_TAG_UL = 'ul';
26 public const HTML_LIST_TAG_OL = 'ol';
27
28 public const CSS_LIST_CLASS = 'dd-list';
29 public const CSS_ITEM_CLASS = 'dd-item';
30 public const CSS_HANDLE_CLASS = 'il-dd-handle';
31
32 public const POSTVAR_SUBFIELD_NEST_ELEM = 'content';
33 public const POSTVAR_SUBFIELD_NEST_INDENT = 'indentation';
34
35 public const DEFAULT_INSTANCE_ID = 'default';
36
38
39 protected $interactionEnabled = true;
40
41 protected $nestingEnabled = true;
42
43 protected $stylingDisabled = false;
44
45 protected $listTpl = null;
46
48
50
52
54
55 public function __construct($a_title = '', $a_postvar = '')
56 {
57 parent::__construct($a_title, $a_postvar);
58
60 $this->addFormValuesManipulator($manipulator);
61 }
62
63 public function setInstanceId($instanceId): void
64 {
65 $this->instanceId = $instanceId;
66 }
67
68 public function getInstanceId(): string
69 {
70 return $this->instanceId;
71 }
72
74 {
75 $this->interactionEnabled = $interactionEnabled;
76 }
77
78 public function isInteractionEnabled(): bool
79 {
81 }
82
83 public function isNestingEnabled(): bool
84 {
86 }
87
88 public function setNestingEnabled($nestingEnabled): void
89 {
90 $this->nestingEnabled = $nestingEnabled;
91 }
92
93 public function isStylingDisabled(): bool
94 {
96 }
97
98 public function setStylingDisabled($stylingDisabled): void
99 {
100 $this->stylingDisabled = $stylingDisabled;
101 }
102
103 protected function isStylingEnabled(): bool
104 {
105 return !$this->isStylingDisabled();
106 }
107
111 public function getCssListClass(): string
112 {
113 return $this->cssListClass;
114 }
115
119 public function setCssListClass($cssListClass): void
120 {
121 $this->cssListClass = $cssListClass;
122 }
123
127 public function getCssItemClass(): string
128 {
129 return $this->cssItemClass;
130 }
131
135 public function getCssHandleClass(): string
136 {
138 }
139
143 public function setCssHandleClass($cssHandleClass): void
144 {
145 $this->cssHandleClass = $cssHandleClass;
146 }
147
151 public function setCssItemClass($cssItemClass): void
152 {
153 $this->cssItemClass = $cssItemClass;
154 }
155
159 public function getHtmlListTag(): string
160 {
161 return $this->htmlListTag;
162 }
163
167 public function setHtmlListTag($htmlListTag): void
168 {
169 $this->htmlListTag = $htmlListTag;
170 }
171
172 protected function getGlobalTpl()
173 {
174 return isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['tpl'] : $GLOBALS['tpl'];
175 }
176
177 public function getListTpl()
178 {
179 return $this->listTpl;
180 }
181
182 public function setListTpl($listTpl): void
183 {
184 $this->listTpl = $listTpl;
185 }
186
187 protected function initListTemplate(): void
188 {
189 $this->setListTpl(
190 new ilTemplate('tpl.prop_nested_ordering_list.html', true, true, 'Modules/TestQuestionPool')
191 );
192 }
193
194 protected function fetchListHtml(): string
195 {
196 return $this->getListTpl()->get();
197 }
198
199 protected function renderListContainer(): void
200 {
201 $this->getListTpl()->setCurrentBlock('list_container');
202 $this->getListTpl()->setVariable('INSTANCE_ID', $this->getInstanceId());
203 $this->getListTpl()->parseCurrentBlock();
204 }
205
206 protected function renderListSnippet(): void
207 {
208 $this->getListTpl()->setCurrentBlock('list_snippet');
209 $this->getListTpl()->parseCurrentBlock();
210 }
211
212 protected function renderListItem($value, $identifier, $position): void
213 {
214 $subPostVar = $this->getMultiValuePostVarSubField($identifier, self::POSTVAR_SUBFIELD_NEST_ELEM);
215 $subFieldId = $this->getMultiValueSubFieldId($identifier, self::POSTVAR_SUBFIELD_NEST_ELEM);
216
217 $this->getListTpl()->setCurrentBlock('item_value');
218
219 $this->getListTpl()->setVariable('ILC_HANDLE_CSS_CLASS', $this->getCssHandleClass());
220
221 $this->getListTpl()->setVariable('LIST_ITEM_VALUE', $this->getItemHtml(
222 $value,
223 $identifier,
224 $position,
225 $subPostVar,
226 $subFieldId
227 ));
228
229 $this->getListTpl()->parseCurrentBlock();
230
231 $this->renderListSnippet();
232 }
233
242 abstract protected function getItemHtml($value, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId);
243
244 protected function renderBeginListItem($identifier): void
245 {
246 $this->getListTpl()->setCurrentBlock('begin_list_item');
247 $this->getListTpl()->setVariable('LIST_ITEM_ID', $identifier);
248 $this->getListTpl()->setVariable('ILC_ITEM_CSS_CLASS', $this->getCssItemClass());
249 $this->getListTpl()->parseCurrentBlock();
250 $this->renderListSnippet();
251 }
252
253 protected function renderEndListItem(): void
254 {
255 $this->getListTpl()->setCurrentBlock('end_list_item');
256 $this->getListTpl()->touchBlock('end_list_item');
257 $this->getListTpl()->parseCurrentBlock();
258 $this->renderListSnippet();
259 }
260
261 protected function renderBeginSubList(): void
262 {
263 $this->getListTpl()->setCurrentBlock('begin_sublist');
264 $this->getListTpl()->setVariable('BEGIN_HTML_LIST_TAG', $this->getHtmlListTag());
265 $this->getListTpl()->setVariable('ILC_LIST_CSS_CLASS', $this->getCssListClass());
266 $this->getListTpl()->parseCurrentBlock();
267 $this->renderListSnippet();
268 }
269
270 protected function renderEndSubList(): void
271 {
272 $this->getListTpl()->setCurrentBlock('end_sublist');
273 $this->getListTpl()->setVariable('END_HTML_LIST_TAG', $this->getHtmlListTag());
274 $this->getListTpl()->parseCurrentBlock();
275 $this->renderListSnippet();
276 }
277
283 abstract protected function getCurrentIndentation($elementValues, $elementCounter): int;
284
290 abstract protected function getNextIndentation($elementValues, $elementCounter): int;
291
292 protected function renderMainList(): string
293 {
294 $this->initListTemplate();
295 $this->renderBeginSubList();
296
297
298 $values = array_values($this->getIdentifiedMultiValues());
299 $keys = array_keys($this->getIdentifiedMultiValues());
300 $prevIndent = 0;
301
302 foreach ($values as $counter => $value) {
303 $identifier = str_replace(assOrderingQuestionGUI::F_NESTED_IDENTIFIER_PREFIX, '', $keys[$counter]);
304
305 if ($this->isNestingEnabled()) {
306 $curIndent = $this->getCurrentIndentation($values, $counter);
307 $nextIndent = $this->getNextIndentation($values, $counter);
308 } else {
309 $curIndent = $nextIndent = 0;
310 }
311
312 if ($prevIndent == $curIndent) {
313 // pcn = Previous, Current, Next -> Depth
314 // pcn: 000, 001, 110, 220
315 if ($curIndent == $nextIndent) {
316 // (1) pcn: 000
317 // echo"(1)";
318 $this->renderBeginListItem($identifier);
319 $this->renderListItem($value, $identifier, $counter);
320 $this->renderEndListItem();
321 } elseif ($curIndent > $nextIndent) {
322 if ($prevIndent == $nextIndent) {
323 // wenn prev = cur ist und cur > next, wie soll prev = next sein !?
324
325 // (8) pcn: 110
326 // echo"(8)";
327 $this->renderBeginListItem($identifier);
328 $this->renderListItem($value, $identifier, $counter);
329 $this->renderEndListItem();
330 $this->renderEndSubList();
331 $this->renderEndListItem();
332 } elseif ($prevIndent > $nextIndent) {
333 // (12) pcn: 220
334 // echo"(12)";
335 $this->renderBeginListItem($identifier);
336 $this->renderListItem($value, $identifier, $counter);
337
338 for ($openlists = $nextIndent; $openlists < $curIndent; $openlists++) {
339 $this->renderEndListItem();
340 $this->renderEndSubList();
341 $this->renderEndListItem();
342 }
343 }
344 } elseif ($curIndent < $nextIndent) {
345 // (2) pcn: 001
346 // echo"(2)";
347 $this->renderBeginListItem($identifier);
348 $this->renderListItem($value, $identifier, $counter);
349 $this->renderBeginSubList();
350 }
351 } elseif ($prevIndent > $curIndent) {
352 if ($curIndent == $nextIndent) {
353 // (6) pcn: 100
354 // echo"(6)";
355 $this->renderBeginListItem($identifier);
356 $this->renderListItem($value, $identifier, $counter);
357 $this->renderEndListItem();
358 } elseif ($curIndent > $nextIndent) {
359 // (11) pcn: 210
360 // echo"(11)";
361 $this->renderBeginListItem($identifier);
362 $this->renderListItem($value, $identifier, $counter);
363 $this->renderEndListItem();
364 $this->renderEndSubList();
365 } elseif ($curIndent < $nextIndent) {
366 if ($prevIndent == $nextIndent) {
367 // (7) pcn: 101
368 // echo"(7)";
369 $this->renderBeginListItem($identifier);
370 $this->renderListItem($value, $identifier, $counter);
371 $this->renderBeginSubList();
372 } elseif ($prevIndent > $nextIndent) {
373 // (10) pcn: 201
374 // echo"(10)";
375 $this->renderBeginListItem($identifier);
376 $this->renderListItem($value, $identifier, $counter);
377 for ($openlists = $nextIndent; $openlists < $curIndent; $openlists++) {
378 $this->renderEndSubList();
379 }
380 $this->renderBeginSubList();
381 }
382 }
383 } elseif ($prevIndent < $curIndent) {
384 if ($curIndent == $nextIndent) {
385 // (4) pcn: 011
386 // echo"(4)";
387 $this->renderBeginListItem($identifier);
388 $this->renderListItem($value, $identifier, $counter);
389 $this->renderEndListItem();
390 } elseif ($curIndent > $nextIndent) {
391 if ($prevIndent == $nextIndent) {
392 // (3) pcn: 010,
393 // echo"(3)";
394 $this->renderBeginListItem($identifier);
395 $this->renderListItem($value, $identifier, $counter);
396 $this->renderEndListItem();
397 $this->renderEndSubList();
398 $this->renderEndListItem();
399 } elseif ($prevIndent > $nextIndent) {
400 // (9) pcn: 120
401 // echo"(9)";
402 $this->renderBeginListItem($identifier);
403 $this->renderListItem($value, $identifier, $counter);
404 for ($openlists = $nextIndent; $openlists < $curIndent; $openlists++) {
405 $this->renderEndListItem();
406 $this->renderEndSubList();
407 }
408 }
409 } elseif ($curIndent < $nextIndent) {
410 // (5) pcn: 012
411 // echo"(5)";
412 $this->renderBeginListItem($identifier);
413 $this->renderListItem($value, $identifier, $counter);
414 $this->renderBeginSubList();
415 }
416 }
417
418 $prevIndent = $curIndent;
419 }
420
421 $this->renderEndSubList();
422 $this->renderListContainer();
423
424 return $this->fetchListHtml();
425 }
426
427 protected function renderJsInit(): void
428 {
429 $config = [];
430
431 if (!$this->isNestingEnabled()) {
432 $config['maxDepth'] = 1;
433 }
434
435 $config['listNodeName'] = $this->getHtmlListTag();
436 $config['listClass'] = $this->getCssListClass();
437 $config['itemClass'] = $this->getCssItemClass();
438 $config['handleClass'] = $this->getCssHandleClass();
439
440 $this->global_tpl->addJavaScript('Modules/TestQuestionPool/templates/default/nested_ordering.js');
441 $this->global_tpl->addOnLoadCode("nested_ordering_input.init('"
442 . $this->getInstanceId() . "', '"
443 . $this->getPostVarSubField('indentation') . "', "
444 . json_encode($config)
445 . ')');
446 }
447
448 public function render(string $a_mode = ""): string
449 {
450 if ($this->isStylingEnabled()) {
451 $this->getGlobalTpl()->addCss('Services/Form/css/nested_ordering.css');
452 }
453
454 if ($this->isInteractionEnabled()) {
457
458 $this->getGlobalTpl()->addJavaScript('./node_modules/nestable2/dist/jquery.nestable.min.js');
459 $this->renderJsInit();
460
461 return $this->renderMainList();
462 }
463
464 return $this->renderMainList();
465 }
466
467 public function onCheckInput(): bool
468 {
469 return true;
470 }
471
472 public function getHTML(): string
473 {
474 return $this->render();
475 }
476}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addFormValuesManipulator(ilFormValuesManipulator $manipulator)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getNextIndentation($elementValues, $elementCounter)
getCurrentIndentation($elementValues, $elementCounter)
getItemHtml($value, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId)
special template class to simplify handling of ITX/PEAR
static initjQueryUI(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components....
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
$keys
Definition: metadata.php:204
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc