ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
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)
Definition: Renderer.php:32
txt(string $id)
Get a text from the language file.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
$txt
Definition: error.php:31