ILIAS  release_8 Revision v8.24
Renderer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24use ILIAS\UI\Renderer as RendererInterface;
26
32{
36 public function render(Component\Component $component, RendererInterface $default_renderer): string
37 {
41 $this->checkComponent($component);
42
43 if ($component instanceof Component\Panel\Standard) {
47 return $this->renderStandard($component, $default_renderer);
48 } elseif ($component instanceof Component\Panel\Sub) {
52 return $this->renderSub($component, $default_renderer);
53 }
57 return $this->renderReport($component, $default_renderer);
58 }
59
60 protected function getContentAsString(Component\Component $component, RendererInterface $default_renderer): string
61 {
62 $content = "";
63 foreach ($component->getContent() as $item) {
64 $content .= $default_renderer->render($item);
65 }
66 return $content;
67 }
68
69 protected function renderStandard(Component\Panel\Standard $component, RendererInterface $default_renderer): string
70 {
71 $tpl = $this->getTemplate("tpl.standard.html", true, true);
72
73 $view_controls = $component->getViewControls();
74 if ($view_controls) {
75 foreach ($view_controls as $view_control) {
76 $tpl->setCurrentBlock("view_controls");
77 $tpl->setVariable("VIEW_CONTROL", $default_renderer->render($view_control));
78 $tpl->parseCurrentBlock();
79 }
80 }
81
82 // actions
83 $actions = $component->getActions();
84 if ($actions !== null) {
85 $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
86 }
87
88 $tpl->setVariable("TITLE", $component->getTitle());
89 $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
90 return $tpl->get();
91 }
92
93 protected function renderSub(Component\Panel\Sub $component, RendererInterface $default_renderer): string
94 {
95 $tpl = $this->getTemplate("tpl.sub.html", true, true);
96
97 $actions = $component->getActions();
98
99 if ($component->getTitle() != "" || $actions !== null) {
100 $tpl->setCurrentBlock("title");
101
102 // actions
103 if ($actions !== null) {
104 $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
105 }
106
107 // title
108 $tpl->setVariable("TITLE", $component->getTitle());
109 $tpl->parseCurrentBlock();
110 }
111
112 if ($component->getFurtherInformation()) {
113 $tpl->setCurrentBlock("with_further_information");
114 $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
115 $tpl->setVariable("INFO", $default_renderer->render($component->getFurtherInformation()));
116 $tpl->parseCurrentBlock();
117 } else {
118 $tpl->setCurrentBlock("no_further_information");
119 $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
120 $tpl->parseCurrentBlock();
121 }
122
123 return $tpl->get();
124 }
125
126 protected function renderReport(Component\Panel\Report $component, RendererInterface $default_renderer): string
127 {
128 $tpl = $this->getTemplate("tpl.report.html", true, true);
129 $tpl->setVariable("TITLE", $component->getTitle());
130 $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
131 return $tpl->get();
132 }
133
137 protected function getComponentInterfaceName(): array
138 {
139 return [Component\Panel\Panel::class];
140 }
141}
renderStandard(Component\Panel\Standard $component, RendererInterface $default_renderer)
Definition: Renderer.php:69
getContentAsString(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:60
renderReport(Component\Panel\Report $component, RendererInterface $default_renderer)
Definition: Renderer.php:126
renderSub(Component\Panel\Sub $component, RendererInterface $default_renderer)
Definition: Renderer.php:93
checkComponent(Component $component)
Check if a given component fits this renderer and throw \LogicError if that is not the case.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
An entity that renders components to a string output.
Definition: Renderer.php:31
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21