ILIAS  release_7 Revision v7.30-3-g800a261c036
Renderer.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 
4 /* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
5 
7 
13 
15 {
19  public function render(Component\Component $component, RendererInterface $default_renderer)
20  {
21  $this->checkComponent($component);
22 
27  $tpl_name = "tpl.tree.html";
28  $tpl = $this->getTemplate($tpl_name, true, true);
29 
30  $tpl->setVariable("ARIA_LABEL", $component->getLabel());
31 
32  $recursion =
33  $environment = $component->getEnvironment();
34 
35  $nodes = [];
36  foreach ($component->getData() as $record) {
37  $nodes[] = $this->buildNode(
38  $component->getRecursion(),
39  $record,
40  $component->getEnvironment()
41  );
42  }
43 
44  $nodes_html = $default_renderer->render($nodes);
45 
46  if ($component->isSubTree()) {
47  return $nodes_html;
48  }
49 
50  $tpl->setVariable('NODES', $nodes_html);
51 
52  $highlight_node_on_click = $component->getHighlightOnNodeClick();
53  $component = $component->withAdditionalOnLoadCode(
54  function ($id) use ($highlight_node_on_click) {
55  return "il.UI.tree.init('$id', $highlight_node_on_click)";
56  }
57  );
58 
59  $id = $this->bindJavaScript($component);
60  $tpl->setVariable("ID", $id);
61 
62 
63  return $tpl->get();
64  }
65 
70  protected function buildNode(
71  Tree\TreeRecursion $recursion,
72  $record,
73  $environment
74  ) : Tree\Node\Node {
75  $node = $recursion->build(
76  $this->getUIFactory()->tree()->node(),
77  $record,
78  $environment
79  );
80 
81  foreach ($recursion->getChildren($record, $environment) as $sub_record) {
82  $node = $node->withAdditionalSubnode(
83  $this->buildNode($recursion, $sub_record, $environment)
84  );
85  }
86 
87  return $node;
88  }
89 
93  public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
94  {
95  parent::registerResources($registry);
96  $registry->register('./src/UI/templates/js/Tree/tree.js');
97  }
98 
102  protected function getComponentInterfaceName()
103  {
104  return array(
105  Tree\Expandable::class
106  );
107  }
108 }
Class Factory.
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
Class ChatMainBarProvider .
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:93
This describes a Tree Control.
Definition: Tree.php:13
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
Interface for mapping data-structures to the Tree.
buildNode(Tree\TreeRecursion $recursion, $record, $environment)
Trigger TreeRecursion::build and recurse into hierarchy by checking for further children of the recor...
Definition: Renderer.php:70
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
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.