ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
expandable2.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
33 function 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
77  ): \ILIAS\UI\Component\Tree\Node\Node {
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
Interface Observer Contains several chained tasks and infos about them.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
expandable2()
description: > Example for rendering an expandable tree.
Definition: expandable2.php:33