53 $this->ui_factory =
$DIC[
'ui.factory'];
54 $this->ui_renderer =
$DIC[
'ui.renderer'];
85 $this->list_tpl =
new ilTemplate(
'tpl.prop_nested_ordering_list.html',
true,
true,
'components/ILIAS/TestQuestionPool');
102 $elementList->completeContentsFromElementList(
103 $question->getOrderingElementList()
186 $icon_name =
'standard/icon_not_ok.svg';
187 $label = $this->
lng->txt(
"answer_is_wrong");
188 if ($correctness ===
'correct') {
189 $icon_name =
'standard/icon_ok.svg';
190 $label = $this->
lng->txt(
"answer_is_right");
193 $icon = $this->ui_factory->symbol()->icon()->custom(
197 return $this->ui_renderer->render($icon);
202 return new ilTemplate(
'tpl.prop_ass_nested_order_elem.html',
true,
true,
'components/ILIAS/TestQuestionPool');
218 string $content_post_var,
219 string $position_post_var,
220 string $indentation_post_var
228 $tpl->setCurrentBlock(
'item_text');
230 $tpl->parseCurrentBlock();
236 $tpl->setCurrentBlock(
'item_image');
239 $tpl->parseCurrentBlock();
244 $correctness =
'not_correct';
246 $correctness =
'correct';
248 $tpl->setCurrentBlock(
'correctness_icon');
251 $tpl->parseCurrentBlock();
254 $tpl->setCurrentBlock(
'item');
255 $tpl->setVariable(
'ITEM_CONTENT_POSTVAR', $content_post_var);
257 $tpl->setVariable(
'ITEM_POSITION_POSTVAR', $position_post_var);
258 $tpl->setVariable(
'ITEM_POSITION', $element[
'ordering_position']);
259 $tpl->setVariable(
'ITEM_INDENTATION_POSTVAR', $indentation_post_var);
260 $tpl->setVariable(
'ITEM_INDENTATION', $element[
'ordering_indentation']);
261 $tpl->parseCurrentBlock();
268 if (!is_array(
$data)) {
272 if (!isset(
$data[$this->getPostVar()])) {
276 if (!count(
$data[$this->getPostVar()])) {
283 private function renderListItem(array $value,
string $identifier,
string $children): string
285 $list_item_tpl =
new ilTemplate(
'tpl.prop_nested_ordering_list_item.html',
true,
true,
'components/ILIAS/TestQuestionPool');
286 $content_post_var = $this->getMultiValuePostVarSubField($identifier, self::POSTVAR_CONTENT);
287 $position_post_var = $this->getMultiValuePostVarSubField($identifier, self::POSTVAR_POSITION);
288 $indentation_post_var = $this->getMultiValuePostVarSubField($identifier, self::POSTVAR_INDENTATION);
290 $list_item_tpl->setVariable(
'LIST_ITEM_VALUE', $this->getItemHtml(
295 $indentation_post_var
298 if ($this->nesting_enabled) {
299 $list_item_tpl->setCurrentBlock(
'nested_list');
300 $list_item_tpl->setVariable(
'SUB_LIST', $children);
301 $list_item_tpl->parseCurrentBlock();
303 return $list_item_tpl->get();
308 $this->initListTemplate();
310 $values = $this->addIdentifierToValues($this->getIdentifiedMultiValues());
311 if ($this->nesting_enabled) {
312 $values = $this->buildHierarchicalTreeFromDBValues($values);
315 $this->list_tpl->setVariable(
317 $this->buildHTMLView(
319 static fn(array
$a, array
$b):
int =>
$a[
'ordering_position'] -
$b[
'ordering_position']
323 return $this->list_tpl->get();
328 foreach (array_keys($values) as $k) {
336 $values_with_parent = [];
338 foreach ($values as $k => $v) {
342 if ($v[
'ordering_indentation'] > 0) {
343 $v[
'parent'] = $levels_array[$v[
'ordering_indentation'] - 1];
345 $levels_array[$v[
'ordering_indentation']] = $k;
346 $values_with_parent[$k] = $v;
351 static fn(array
$a, array
$b):
int =>
$b[
'ordering_indentation'] -
$a[
'ordering_indentation']
354 foreach (array_keys($values_with_parent) as $k) {
355 $v = $values_with_parent[$k];
356 if ($v[
'parent'] !==
null) {
357 $values_with_parent[$v[
'parent']][
'children'][$k] = $v;
363 static fn(array $v):
bool => $v[
'ordering_indentation'] === 0
367 private function buildHTMLView(array $array, \Closure $sort_closure): string
369 usort($array, $sort_closure);
372 function (
string $c, array $v) use ($sort_closure):
string {
374 if ($this->nesting_enabled && $v[
'children'] !== []) {
375 $children = $this->buildHTMLView($v[
'children'], $sort_closure);
377 $c .= $this->renderListItem($v, $v[
'identifier'], $children);
384 public function render(
string $a_mode =
''): string
386 if (!$this->styling_disabled) {
387 $this->getGlobalTpl()->addCss(
'assets/css/content.css');
390 if ($this->interaction_enabled) {
391 $this->initializePlayerJS();
394 return $this->renderMainList();
404 return $this->render();
409 $this->getGlobalTpl()->addJavascript(
'assets/js/orderingvertical.js');
410 $this->getGlobalTpl()->addOnLoadCode(
411 'il.test.orderingvertical.init(document.querySelector("#nestable_ordering"));'
Builds a Color from either hex- or rgb values.
const F_NESTED_IDENTIFIER_PREFIX
static buildInstance(int $question_id, array $elements=[])
getRandomIdentifierIndexedElements()
special template class to simplify handling of ITX/PEAR
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
An entity that renders components to a string output.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples