ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Renderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Renderer as RendererInterface;
26
28{
32 public function render(Component\Component $component, RendererInterface $default_renderer): string
33 {
34 if (!$component instanceof Component\Chart\ScaleBar) {
35 $this->cannotHandleComponent($component);
36 }
37
38 $tpl = $this->getTemplate("tpl.scale_bar.html", true, true);
39
40 $items = $component->getItems();
41 if (count($items) == 0) {
42 return "";
43 }
44
45 $width = str_replace(",", ".", (string) round(100 / count($items), 5));
46
47 foreach ($component->getItems() as $txt => $active) {
48 if ($active) {
49 $tpl->setCurrentBlock("active");
50 $tpl->setVariable("TXT_ACTIVE", $this->txt("active"));
51 $tpl->parseCurrentBlock();
52 $tpl->touchBlock("active_class");
53 }
54
55 $tpl->setCurrentBlock("item");
56 $tpl->setVariable("ITEM_TEXT", $txt);
57 $tpl->setVariable("ITEM_WIDTH", $width);
58 $tpl->parseCurrentBlock();
59 }
60
61 return $tpl->get();
62 }
63}
render(Component\Component $component, RendererInterface $default_renderer)
@inheritdocs
Definition: Renderer.php:32
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
$txt
Definition: error.php:31
An entity that renders components to a string output.
Definition: Renderer.php:31