ILIAS  release_8 Revision v8.23
expandable2.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
7 function expandable2(): string
8 {
9  global $DIC;
10  $f = $DIC->ui()->factory();
11  $renderer = $DIC->ui()->renderer();
12 
13  $getDataNode = function (string $label, array $children = []) {
14  return new class ($label, $children) {
15  protected string $label = '';
16  protected array$children = [];
17 
18  public function __construct(string $label, array $children = [])
19  {
20  $this->label = $label;
21  $this->children = $children;
22  }
23 
24  public function getLabel(): string
25  {
26  return $this->label;
27  }
28 
29  public function getChildren(): array
30  {
31  return $this->children;
32  }
33  };
34  };
35 
36  $n11 = $getDataNode('1.1');
37  $n12 = $getDataNode('1.2', [$getDataNode('1.2.1')]);
38  $n1 = $getDataNode('1', [$n11, $n12]);
39  $data = [$n1];
40 
41  $recursion = new class () implements \ILIAS\UI\Component\Tree\TreeRecursion {
42  public function getChildren($record, $environment = null): array
43  {
44  return $record->getChildren();
45  }
46 
47  public function build(
48  \ILIAS\UI\Component\Tree\Node\Factory $factory,
49  $record,
50  $environment = null
52  return $factory->simple($record->getLabel());
53  }
54  };
55 
56  $tree = $f->tree()->expandable("Label", $recursion)
57  ->withData($data);
58 
59  return $renderer->render($tree);
60 }
Class Factory.
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes a Tree Node.
Definition: Node.php:30
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
$factory
Definition: metadata.php:75