ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Renderer.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Alex Killing <killing@leifos.de> Extended GPL, see docs/LICENSE */
4 
6 
10 
12 {
16  public function render(Component\Component $component, RendererInterface $default_renderer)
17  {
18  $this->checkComponent($component);
19 
20  $tpl = $this->getTemplate("tpl.scale_bar.html", true, true);
21 
22  $items = $component->getItems();
23  if (count($items) == 0) {
24  return "";
25  }
26 
27  $width = str_replace(",", ".", round(100 / count($items), 5));
28 
29  foreach ($component->getItems() as $txt => $active) {
30  if ($active) {
31  $tpl->setCurrentBlock("active");
32  $tpl->setVariable("TXT_ACTIVE", $this->txt("active"));
33  $tpl->parseCurrentBlock();
34  $tpl->touchBlock("active_class");
35  }
36 
37  $tpl->setCurrentBlock("item");
38  $tpl->setVariable("ITEM_TEXT", $txt);
39  $tpl->setVariable("ITEM_WIDTH", $width);
40  $tpl->parseCurrentBlock();
41  }
42 
43  return $tpl->get();
44  }
45 
49  protected function getComponentInterfaceName()
50  {
51  return array(Component\Chart\ScaleBar::class);
52  }
53 }
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:16
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
$tpl
Definition: ilias.php:10
$txt
Definition: error.php:11
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.