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) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
8use ILIAS\UI\Renderer as RendererInterface;
10
12{
13 protected function getTemplateFilename()
14 {
15 return "tpl.glyph.standard.html";
16 }
17
21 public function render(Component\Component $component, RendererInterface $default_renderer)
22 {
23 $this->checkComponent($component);
24
25 $tpl_file = $this->getTemplateFilename();
26 $tpl = $this->getTemplate($tpl_file, true, true);
27
28 $action = $component->getAction();
29 if ($component->isActive() && $action !== null) {
30 $tpl->setCurrentBlock("with_action");
31 $tpl->setVariable("ACTION", $component->getAction());
32 $tpl->parseCurrentBlock();
33 }
34
35 if ($component->isHighlighted()) {
36 $tpl->touchBlock("highlighted");
37 }
38
39 if (!$component->isActive()) {
40 $tpl->touchBlock("disabled");
41
42 $tpl->setCurrentBlock("with_aria_disabled");
43 $tpl->setVariable("ARIA_DISABLED", "true");
44 $tpl->parseCurrentBlock();
45 }
46
47 $tpl->setVariable("LABEL", $this->txt($component->getAriaLabel()));
48
49 $id = $this->bindJavaScript($component);
50
51 if ($id !== null) {
52 $tpl->setCurrentBlock("with_id");
53 $tpl->setVariable("ID", $id);
54 $tpl->parseCurrentBlock();
55 }
56
57 $tpl->setVariable("GLYPH", $this->getInnerGlyphHTML($component, $default_renderer));
58 return $tpl->get();
59 }
60
61
62 protected function getInnerGlyphHTML(Component\Component $component, RendererInterface $default_renderer)
63 {
64 $tpl = $this->getTemplate('tpl.glyph.html', true, true);
65
66 $tpl->touchBlock($component->getType());
67
68 $largest_counter = 0;
69 foreach ($component->getCounters() as $counter) {
70 if ($largest_counter < $counter->getNumber()) {
71 $largest_counter = $counter->getNumber();
72 }
73 $n = "counter_" . $counter->getType();
74 $tpl->setCurrentBlock($n);
75 $tpl->setVariable(strtoupper($n), $default_renderer->render($counter));
76 $tpl->parseCurrentBlock();
77 }
78
79 if ($largest_counter) {
80 $tpl->setCurrentBlock("counter_spacer");
81 $tpl->setVariable("COUNTER_SPACER", $largest_counter);
82 $tpl->parseCurrentBlock();
83 }
84 return $tpl->get();
85 }
86
90 protected function getComponentInterfaceName()
91 {
92 return array(Component\Glyph\Glyph::class);
93 }
94}
$n
Definition: RandomTest.php:85
$tpl
Definition: ilias.php:10
An exception for terminatinating execution or to throw for unit testing.
getInnerGlyphHTML(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:62
render(Component\Component $component, RendererInterface $default_renderer)
@inheritdocs
Definition: Renderer.php:21
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
checkComponent(Component $component)
Check if a given component fits this renderer and throw \LogicError if that is not the case.
$action
if(!array_key_exists('StateId', $_REQUEST)) $id
A component is the most general form of an entity in the UI.
Definition: Component.php:14
An entity that renders components to a string output.
Definition: Renderer.php:15