ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ListingAdapterGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
29{
30 protected \ILIAS\DI\UIServices $ui;
31 protected array $nodes = [];
32 protected array $childs = [];
33 protected array $nr = [];
34 protected bool $auto_numbers = false;
35
36 public function __construct(
37 ) {
38 global $DIC;
39 $this->ui = $DIC->ui();
40 }
41
42 public function node(
43 \ILIAS\UI\Component\Component $component,
44 string $a_id,
45 string $a_parent = "0"
46 ): self {
47 $this->nodes[$a_id] = $component;
48 $this->childs[$a_parent][] = $a_id;
49 return $this;
50 }
51
52 public function autoNumbers(bool $auto): self
53 {
54 $this->auto_numbers = $auto;
55 return $this;
56 }
57
58 public function render(): string
59 {
60 $depth = 1;
61 $nr = [];
62 if (isset($this->childs[0]) && count($this->childs[0]) > 0) {
63 $items = [];
64 foreach ($this->childs[0] as $child) {
65 $items[] = $this->renderNode($child, $depth, $nr);
66 }
67 $listing = $this->ui->factory()->listing()->unordered($items);
68 return $this->ui->renderer()->render($listing);
69 }
70 return "";
71 }
72
73 public function getNumbers(): array
74 {
75 return $this->nr;
76 }
77
78 public function renderNode(
79 string $a_id,
80 int $depth,
81 array &$nr
82 ): string {
83 if (!isset($nr[$depth])) {
84 $nr[$depth] = 1;
85 } else {
86 $nr[$depth]++;
87 }
88
89 $nr_str = $sep = "";
90 if ($this->auto_numbers) {
91 for ($i = 1; $i <= $depth; $i++) {
92 $nr_str .= $sep . $nr[$i];
93 $sep = ".";
94 }
95 }
96 $html = $nr_str . " " . $this->ui->renderer()->render($this->nodes[$a_id]);
97 $this->nr[$a_id] = $nr_str;
98
99 if (isset($this->childs[$a_id]) && count($this->childs[$a_id]) > 0) {
100 $childs = [];
101 foreach ($this->childs[$a_id] as $child) {
102 $childs[] = $this->renderNode($child, $depth + 1, $nr);
103 }
104 $html .= $this->ui->renderer()->render(
105 $this->ui->factory()->listing()->unordered($childs)
106 );
107 }
108 unset($nr[$depth + 1]);
109
110 return $html;
111 }
112}
node(\ILIAS\UI\Component\Component $component, string $a_id, string $a_parent="0")
renderNode(string $a_id, int $depth, array &$nr)
Definition: UI.php:24
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26