ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Renderer.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
4/* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
5
7
9use ILIAS\UI\Renderer as RendererInterface;
13
15{
19 public function render(Component\Component $component, RendererInterface $default_renderer)
20 {
21 $this->checkComponent($component);
22
23 $tpl_name = "tpl.tree.html";
24 $tpl = $this->getTemplate($tpl_name, true, true);
25
26 $tpl->setVariable("ARIA_LABEL", $component->getLabel());
27
28 $recursion =
29 $environment = $component->getEnvironment();
30
31 $nodes = [];
32 foreach ($component->getData() as $record) {
33 $nodes[] = $this->buildNode(
34 $component->getRecursion(),
35 $record,
36 $component->getEnvironment()
37 );
38 }
39
40 $nodes_html = $default_renderer->render($nodes);
41 $tpl->setVariable('NODES', $nodes_html);
42
43 $highlight_node_on_click = $component->getHighlightOnNodeClick();
44 $component = $component->withAdditionalOnLoadCode(
45 function ($id) use ($highlight_node_on_click) {
46 return "il.UI.tree.init('$id', $highlight_node_on_click)";
47 }
48 );
49
50 $id = $this->bindJavaScript($component);
51 $tpl->setVariable("ID", $id);
52
53
54 return $tpl->get();
55 }
56
65 protected function buildNode(
66 Tree\TreeRecursion $recursion,
67 $record,
68 $environment
69 ) : Tree\Node\Node {
70 $node = $recursion->build(
71 $this->getUIFactory()->tree()->node(),
72 $record,
73 $environment
74 );
75
76 foreach ($recursion->getChildren($record, $environment) as $sub_record) {
77 $node = $node->withAdditionalSubnode(
78 $this->buildNode($recursion, $sub_record, $environment)
79 );
80 }
81
82 return $node;
83 }
84
88 public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
89 {
90 parent::registerResources($registry);
91 $registry->register('./src/UI/templates/js/Tree/tree.js');
92 }
93
97 protected function getComponentInterfaceName()
98 {
99 return array(
100 Tree\Expandable::class
101 );
102 }
103}
An exception for terminatinating execution or to throw for unit testing.
getComponentInterfaceName()
Get the name of the component-interface this renderer is supposed to render.ATTENTION: Fully qualifie...
Definition: Renderer.php:97
buildNode(Tree\TreeRecursion $recursion, $record, $environment)
Trigger TreeRecursion::build and recurse into hierarchy by checking for further children of the recor...
Definition: Renderer.php:65
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:88
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:19
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
checkComponent(Component $component)
Check if a given component fits this renderer and throw \LogicError if that is not the case.
A component is the most general form of an entity in the UI.
Definition: Component.php:14
Interface for mapping data-structures to the Tree.
This describes a Tree Control.
Definition: Tree.php:14
An entity that renders components to a string output.
Definition: Renderer.php:15
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl