ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
expandable2.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
33function expandable2(): string
34{
35 global $DIC;
36 $f = $DIC->ui()->factory();
37 $renderer = $DIC->ui()->renderer();
38
39 $getDataNode = function (string $label, array $children = []) {
40 return new class ($label, $children) {
41 protected string $label = '';
42 protected array $children = [];
43
44 public function __construct(string $label, array $children = [])
45 {
46 $this->label = $label;
47 $this->children = $children;
48 }
49
50 public function getLabel(): string
51 {
52 return $this->label;
53 }
54
55 public function getChildren(): array
56 {
57 return $this->children;
58 }
59 };
60 };
61
62 $n11 = $getDataNode('1.1');
63 $n12 = $getDataNode('1.2', [$getDataNode('1.2.1')]);
64 $n1 = $getDataNode('1', [$n11, $n12]);
65 $data = [$n1];
66
67 $recursion = new class () implements \ILIAS\UI\Component\Tree\TreeRecursion {
68 public function getChildren($record, $environment = null): array
69 {
70 return $record->getChildren();
71 }
72
73 public function build(
74 \ILIAS\UI\Component\Tree\Node\Factory $factory,
75 $record,
76 $environment = null
78 return $factory->simple($record->getLabel());
79 }
80 };
81
82 $tree = $f->tree()->expandable("Label", $recursion)
83 ->withData($data);
84
85 return $renderer->render($tree);
86}
$renderer
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Definition: UI.php:24
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
This describes a Tree Node.
Definition: Node.php:31
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.