ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
KSDocumentationTreeRecursion.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
29{
30 protected Entries $entries;
31 protected URI $parent_uri;
33
34 public function __construct(Entries $entries, URI $parent_uri, string $current_opened_entry_id)
35 {
36 $this->entries = $entries;
37 $this->parent_uri = $parent_uri;
38 $this->current_node = $entries->getRootEntry();
39 if ($current_opened_entry_id) {
40 $this->current_node = $entries->getEntryById($current_opened_entry_id);
41 }
42 }
47 public function getChildren($record, $environment = null): array
48 {
49 $entries = $this->entries->getChildrenOfEntry($record->getId());
50 usort($entries, static fn(Entry $a, Entry $b): int => ilStr::strCmp($a->getTitle(), $b->getTitle()));
51 return $entries;
52 }
53
54 public function build(
55 \ILIAS\UI\Component\Tree\Node\Factory $factory,
56 $record,
57 $environment = null
58 ): \ILIAS\UI\Component\Tree\Node\Node {
62 $is_expanded = ($this->entries->isParentOfEntry($record->getId(), $this->current_node->getId())) ||
63 ($record == $this->entries->getRootEntry());
64 $is_highlited = $this->current_node->getId() == $record->getId();
65
66 return $factory->simple($record->getTitle())
67 ->withLink($this->getNodeUri($record))
68 ->withExpanded($is_expanded)
69 ->withHighlighted($is_highlited);
70 }
71
72 protected function getNodeUri(Entry $a_node): URI
73 {
74 return $this->parent_uri->withParameter('node_id', $a_node->getId());
75 }
76}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
withParameter(string $key, $value)
Get URI with modified parameters.
Definition: URI.php:387
Container storing a list of UI Component Entries, can act as Iterator, countable and is serializable.
Stores Information of UI Components parsed from YAML, examples and less files.
Tree Recursion, putting Entries into a Tree.
__construct(Entries $entries, URI $parent_uri, string $current_opened_entry_id)
getChildren($record, $environment=null)
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
Interface for mapping data-structures to the Tree.
build(Node\Factory $factory, $record, $environment=null)
Build and return a Node.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples