ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
8use ILIAS\UI\Renderer as RendererInterface;
10
12{
16 public function render(Component\Component $component, RendererInterface $default_renderer)
17 {
18 $this->checkComponent($component);
19
20 if ($component instanceof Component\Item\Group) {
21 return $this->renderGroup($component, $default_renderer);
22 }
23 if ($component instanceof Component\Item\Standard) {
24 return $this->renderStandard($component, $default_renderer);
25 }
26 }
27
28 protected function renderGroup(Component\Item\Group $component, RendererInterface $default_renderer)
29 {
30 $tpl = $this->getTemplate("tpl.group.html", true, true);
31 $title = $component->getTitle();
32 $items = $component->getItems();
33
34 // items
35 foreach ($items as $item) {
36 $tpl->setCurrentBlock("item");
37 $tpl->setVariable("ITEM", $default_renderer->render($item));
38 $tpl->parseCurrentBlock();
39 }
40
41 // actions
42 $actions = $component->getActions();
43 if ($actions !== null) {
44 $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
45 }
46
47
48 $tpl->setVariable("TITLE", $title);
49
50 return $tpl->get();
51 }
52
53 protected function renderStandard(Component\Item\Item $component, RendererInterface $default_renderer)
54 {
55 global $DIC;
56
57 $tpl = $this->getTemplate("tpl.item_standard.html", true, true);
58
59 // color
60 $color = $component->getColor();
61 if ($color !== null) {
62 $tpl->setCurrentBlock("color");
63 $tpl->setVariable("COLOR", $color->asHex());
64 $tpl->parseCurrentBlock();
65 }
66
67 // lead
68 $lead = $component->getLead();
69 if ($lead != null) {
70 if (is_string($lead)) {
71 $tpl->setCurrentBlock("lead_text");
72 $tpl->setVariable("LEAD_TEXT", $lead);
73 $tpl->parseCurrentBlock();
74 }
75 if ($lead instanceof Component\Image\Image) {
76 $tpl->setCurrentBlock("lead_image");
77 $tpl->setVariable("LEAD_IMAGE", $default_renderer->render($lead));
78 $tpl->parseCurrentBlock();
79 }
80 $tpl->setCurrentBlock("lead_start");
81 $tpl->parseCurrentBlock();
82
83 $tpl->touchBlock("lead_end");
84 }
85
86 // description
87 $desc = $component->getDescription();
88 if (trim($desc) != "") {
89 $tpl->setCurrentBlock("desc");
90 $tpl->setVariable("DESC", $desc);
91 $tpl->parseCurrentBlock();
92 }
93
94 // actions
95 $actions = $component->getActions();
96 if ($actions !== null) {
97 $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
98 }
99
100 // properties
101 $props = $component->getProperties();
102 if (count($props) > 0) {
103 $cnt = 0;
104 foreach ($props as $name => $value) {
105 if ($value instanceof \ILIAS\UI\Component\Button\Shy) {
106 $value = $default_renderer->render($value);
107 }
108
109 $cnt++;
110 if ($cnt % 2 == 1) {
111 $tpl->setCurrentBlock("property_row");
112 $tpl->setVariable("PROP_NAME_A", $name);
113 $tpl->setVariable("PROP_VAL_A", $value);
114 } else {
115 $tpl->setVariable("PROP_NAME_B", $name);
116 $tpl->setVariable("PROP_VAL_B", $value);
117 $tpl->parseCurrentBlock();
118 }
119 }
120 if ($cnt % 2 == 1) {
121 $tpl->parseCurrentBlock();
122 }
123 $tpl->setCurrentBlock("properties");
124 $tpl->parseCurrentBlock();
125 }
126
127 $title = $component->getTitle();
128
129 if ($title instanceof \ILIAS\UI\Component\Button\Shy) {
130 $title = $default_renderer->render($title);
131 }
132
133 $tpl->setVariable("TITLE", $title);
134
135 return $tpl->get();
136 }
137
141 protected function getComponentInterfaceName()
142 {
143 return array(Component\Item\Standard::class
144 , Component\Item\Group::class
145 );
146 }
147}
$tpl
Definition: ilias.php:10
An exception for terminatinating execution or to throw for unit testing.
Common interface to all items.
Definition: Group.php:14
Common interface to all items.
Definition: Item.php:14
getComponentInterfaceName()
Get the name of the component-interface this renderer is supposed to render.ATTENTION: Fully qualifie...
Definition: Renderer.php:141
renderStandard(Component\Item\Item $component, RendererInterface $default_renderer)
Definition: Renderer.php:53
renderGroup(Component\Item\Group $component, RendererInterface $default_renderer)
Definition: Renderer.php:28
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:16
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
checkComponent(Component $component)
Check if a given component fits this renderer and throw \LogicError if that is not the case.
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
if($format !==null) $name
Definition: metadata.php:146
Class BaseForm.
Class Factory.
global $DIC
Definition: saml.php:7