52 $this->ui_factory =
$DIC[
'ui.factory'];
53 $this->ui_renderer =
$DIC[
'ui.renderer'];
79 $this->list_tpl =
new ilTemplate(
'tpl.prop_nested_ordering_list.html',
true,
true,
'components/ILIAS/TestQuestionPool');
96 $elementList->completeContentsFromElementList(
97 $question->getOrderingElementList()
180 $icon_name =
'standard/icon_not_ok.svg';
181 $label = $this->
lng->txt(
"answer_is_wrong");
182 if ($correctness ===
'correct') {
183 $icon_name =
'standard/icon_ok.svg';
184 $label = $this->
lng->txt(
"answer_is_right");
187 $icon = $this->ui_factory->symbol()->icon()->custom(
191 return $this->ui_renderer->render($icon);
196 return new ilTemplate(
'tpl.prop_ass_nested_order_elem.html',
true,
true,
'components/ILIAS/TestQuestionPool');
212 string $content_post_var,
213 string $position_post_var,
214 string $indentation_post_var
222 $tpl->setCurrentBlock(
'item_text');
224 $tpl->parseCurrentBlock();
230 $tpl->setCurrentBlock(
'item_image');
233 $tpl->parseCurrentBlock();
238 $correctness =
'not_correct';
240 $correctness =
'correct';
242 $tpl->setCurrentBlock(
'correctness_icon');
245 $tpl->parseCurrentBlock();
248 $tpl->setCurrentBlock(
'item');
249 $tpl->setVariable(
'ITEM_CONTENT_POSTVAR', $content_post_var);
251 $tpl->setVariable(
'ITEM_POSITION_POSTVAR', $position_post_var);
252 $tpl->setVariable(
'ITEM_POSITION', $element[
'ordering_position']);
253 $tpl->setVariable(
'ITEM_INDENTATION_POSTVAR', $indentation_post_var);
254 $tpl->setVariable(
'ITEM_INDENTATION', $element[
'ordering_indentation']);
255 $tpl->parseCurrentBlock();
262 if (!is_array(
$data)) {
266 if (!isset(
$data[$this->getPostVar()])) {
270 if (!count(
$data[$this->getPostVar()])) {
277 private function renderListItem(array $value,
string $identifier,
string $children): string
279 $list_item_tpl =
new ilTemplate(
'tpl.prop_nested_ordering_list_item.html',
true,
true,
'components/ILIAS/TestQuestionPool');
280 $content_post_var = $this->getMultiValuePostVarSubField($identifier, self::POSTVAR_CONTENT);
281 $position_post_var = $this->getMultiValuePostVarSubField($identifier, self::POSTVAR_POSITION);
282 $indentation_post_var = $this->getMultiValuePostVarSubField($identifier, self::POSTVAR_INDENTATION);
284 $list_item_tpl->setVariable(
'LIST_ITEM_VALUE', $this->getItemHtml(
289 $indentation_post_var
292 if ($this->nesting_enabled) {
293 $list_item_tpl->setCurrentBlock(
'nested_list');
294 $list_item_tpl->setVariable(
'SUB_LIST', $children);
295 $list_item_tpl->parseCurrentBlock();
297 return $list_item_tpl->get();
302 $this->initListTemplate();
304 $values = $this->addIdentifierToValues($this->getIdentifiedMultiValues());
305 if ($this->nesting_enabled) {
306 $values = $this->buildHierarchicalTreeFromDBValues($values);
309 $this->list_tpl->setVariable(
311 $this->buildHTMLView(
313 static fn(array
$a, array
$b):
int =>
$a[
'ordering_position'] -
$b[
'ordering_position']
317 return $this->list_tpl->get();
322 foreach (array_keys($values) as $k) {
330 $values_with_parent = [];
332 foreach ($values as $k => $v) {
336 if ($v[
'ordering_indentation'] > 0) {
337 $v[
'parent'] = $levels_array[$v[
'ordering_indentation'] - 1];
339 $levels_array[$v[
'ordering_indentation']] = $k;
340 $values_with_parent[$k] = $v;
345 static fn(array
$a, array
$b):
int =>
$b[
'ordering_indentation'] -
$a[
'ordering_indentation']
348 foreach (array_keys($values_with_parent) as $k) {
349 $v = $values_with_parent[$k];
350 if ($v[
'parent'] !==
null) {
351 $values_with_parent[$v[
'parent']][
'children'][$k] = $v;
357 static fn(array $v):
bool => $v[
'ordering_indentation'] === 0
361 private function buildHTMLView(array $array, \Closure $sort_closure): string
363 usort($array, $sort_closure);
366 function (
string $c, array $v) use ($sort_closure):
string {
368 if ($this->nesting_enabled && $v[
'children'] !== []) {
369 $children = $this->buildHTMLView($v[
'children'], $sort_closure);
371 $c .= $this->renderListItem($v, $v[
'identifier'], $children);
378 public function render(
string $a_mode =
''): string
380 if ($this->interaction_enabled) {
381 $this->initializePlayerJS();
384 return $this->renderMainList();
394 return $this->render();
399 $this->getGlobalTpl()->addJavascript(
'assets/js/orderingvertical.js');
400 $this->getGlobalTpl()->addOnLoadCode(
401 '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