ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
28 
30 {
34  public function render(Component\Component $component, RendererInterface $default_renderer): string
35  {
36  $this->checkComponent($component);
37 
42  $tpl_name = "tpl.tree.html";
43  $tpl = $this->getTemplate($tpl_name, true, true);
44 
45  $tpl->setVariable("ARIA_LABEL", $component->getLabel());
46 
47  $nodes = [];
48  foreach ($component->getData() as $record) {
49  $nodes[] = $this->buildNode(
50  $component->getRecursion(),
51  $record,
52  $component->getEnvironment()
53  );
54  }
55 
56  $nodes_html = $default_renderer->render($nodes);
57 
58  if ($component->isSubTree()) {
59  return $nodes_html;
60  }
61 
62  $tpl->setVariable('NODES', $nodes_html);
63 
64  $highlight_node_on_click = $component->getHighlightOnNodeClick();
65  $component = $component->withAdditionalOnLoadCode(
66  fn ($id) => "il.UI.tree.init('$id', $highlight_node_on_click)"
67  );
68 
69  $id = $this->bindJavaScript($component);
70  $tpl->setVariable("ID", $id);
71 
72 
73  return $tpl->get();
74  }
75 
80  protected function buildNode(
81  Tree\TreeRecursion $recursion,
82  $record,
83  $environment
84  ): Tree\Node\Node {
85  $node = $recursion->build(
86  $this->getUIFactory()->tree()->node(),
87  $record,
88  $environment
89  );
90 
91  foreach ($recursion->getChildren($record, $environment) as $sub_record) {
92  $node = $node->withAdditionalSubnode(
93  $this->buildNode($recursion, $sub_record, $environment)
94  );
95  }
96 
97  return $node;
98  }
99 
103  public function registerResources(ResourceRegistry $registry): void
104  {
105  parent::registerResources($registry);
106  $registry->register('./src/UI/templates/js/Tree/tree.js');
107  }
108 
112  protected function getComponentInterfaceName(): array
113  {
114  return array(
115  Tree\Expandable::class
116  );
117  }
118 }
Registry for resources required by rendered output like Javascript or CSS.
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
register(string $name)
Add a dependency.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Expandable.php:21
This describes a Tree Control.
Definition: Tree.php:28
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.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
buildNode(Tree\TreeRecursion $recursion, $record, $environment)
Trigger TreeRecursion::build and recurse into hierarchy by checking for further children of the recor...
Definition: Renderer.php:80
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
Definition: Renderer.php:103
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Expandable.php:21
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.