ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilNestedList.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected string $item_class = "il_Explorer";
26  protected array $list_class = array();
27  protected bool $auto_numbering = false;
28  protected array $nr = array();
29  protected array $nodes = [];
30  protected array $childs = [];
31 
32  public function __construct()
33  {
34  $this->list_class[0] = "il_Explorer";
35  $this->childs[0] = array();
36  }
37 
38  // Set li class
39  public function setItemClass(string $a_val): void
40  {
41  $this->item_class = $a_val;
42  }
43 
44  public function getItemClass(): string
45  {
46  return $this->item_class;
47  }
48 
49  // Set list class
50  public function setListClass(string $a_val, int $a_depth = 0): void
51  {
52  $this->list_class[$a_depth] = $a_val;
53  }
54 
55  public function getListClass(int $a_depth = 0): string
56  {
57  return $this->list_class[$a_depth] ?? "";
58  }
59 
60  public function addListNode(
61  string $a_content,
62  string $a_id,
63  $a_parent = 0
64  ): void {
65  $this->nodes[$a_id] = $a_content;
66  $this->childs[$a_parent][] = $a_id;
67  }
68 
69  public function setAutoNumbering(bool $a_val): void
70  {
71  $this->auto_numbering = $a_val;
72  }
73 
74  public function getAutoNumbering(): bool
75  {
76  return $this->auto_numbering;
77  }
78 
79  public function getNumbers(): array
80  {
81  return $this->nr;
82  }
83 
84  public function getHTML(): string
85  {
86  $tpl = new ilTemplate("tpl.nested_list.html", true, true, "Services/UIComponent/NestedList");
87 
88  $nr = array();
89  $depth = 1;
90  if (isset($this->childs[0]) && count($this->childs[0]) > 0) {
91  $this->listStart($tpl, $depth);
92  foreach ($this->childs[0] as $child) {
93  $this->renderNode($child, $tpl, $depth, $nr);
94  }
95  $this->listEnd($tpl);
96  }
97 
98  return $tpl->get();
99  }
100 
101  public function renderNode(
102  $a_id,
104  int $depth,
105  array &$nr
106  ): void {
107  if (!isset($nr[$depth])) {
108  $nr[$depth] = 1;
109  } else {
110  $nr[$depth]++;
111  }
112 
113  $nr_str = $sep = "";
114  if ($this->getAutoNumbering()) {
115  for ($i = 1; $i <= $depth; $i++) {
116  $nr_str .= $sep . $nr[$i];
117  $sep = ".";
118  }
119  }
120 
121  $this->listItemStart($tpl);
122  $tpl->setCurrentBlock("content");
123  $tpl->setVariable("CONTENT", $nr_str . " " . $this->nodes[$a_id]);
124  $this->nr[$a_id] = $nr_str;
125  //echo "<br>".$this->nodes[$a_id];
126  $tpl->parseCurrentBlock();
127  $tpl->touchBlock("tag");
128 
129  if (isset($this->childs[$a_id]) && count($this->childs[$a_id]) > 0) {
130  $this->listStart($tpl, $depth + 1);
131  foreach ($this->childs[$a_id] as $child) {
132  $this->renderNode($child, $tpl, $depth + 1, $nr);
133  }
134  $this->listEnd($tpl);
135  }
136  unset($nr[$depth + 1]);
137 
138  $this->listItemEnd($tpl);
139  }
140 
141  public function listItemStart(ilTemplate $tpl): void
142  {
143  if ($this->getItemClass() !== "") {
144  $tpl->setCurrentBlock("list_item_start");
145  $tpl->setVariable("LI_CLASS", ' class="' . $this->getItemClass() . '" ');
146  $tpl->parseCurrentBlock();
147  } else {
148  $tpl->touchBlock("list_item_start");
149  }
150  $tpl->touchBlock("tag");
151  }
152 
153  public function listItemEnd(ilTemplate $tpl): void
154  {
155  $tpl->touchBlock("list_item_end");
156  $tpl->touchBlock("tag");
157  }
158 
159  public function listStart(ilTemplate $tpl, int $depth): void
160  {
161  //echo "<br>listStart";
162 
163  $class = ($this->getListClass($depth) !== "")
164  ? $this->getListClass($depth)
165  : $this->getListClass();
166  //echo "-$class-";
167  if ($class !== "") {
168  $tpl->setCurrentBlock("list_start");
169  $tpl->setVariable("UL_CLASS", ' class="' . $class . '" ');
170  $tpl->parseCurrentBlock();
171  } else {
172  $tpl->touchBlock("list_start");
173  }
174  $tpl->touchBlock("tag");
175  }
176 
177  public function listEnd(ilTemplate $tpl): void
178  {
179  //echo "<br>listEnd";
180  $tpl->touchBlock("list_end");
181  $tpl->touchBlock("tag");
182  }
183 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
listItemStart(ilTemplate $tpl)
setListClass(string $a_val, int $a_depth=0)
renderNode( $a_id, ilTemplate $tpl, int $depth, array &$nr)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addListNode(string $a_content, string $a_id, $a_parent=0)
touchBlock(string $block)
setAutoNumbering(bool $a_val)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
listStart(ilTemplate $tpl, int $depth)
listItemEnd(ilTemplate $tpl)
listEnd(ilTemplate $tpl)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
getListClass(int $a_depth=0)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41
setItemClass(string $a_val)