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  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  if ($lead instanceof Component\Icon\Icon) {
81  $tpl->setCurrentBlock("lead_icon");
82  $tpl->setVariable("LEAD_ICON", $default_renderer->render($lead));
83  $tpl->parseCurrentBlock();
84  $tpl->setCurrentBlock("lead_start_icon");
85  $tpl->parseCurrentBlock();
86  } else {
87  $tpl->setCurrentBlock("lead_start");
88  $tpl->parseCurrentBlock();
89  }
90 
91 
92  $tpl->touchBlock("lead_end");
93  }
94 
95  // description
96  $desc = $component->getDescription();
97  if (trim($desc) != "") {
98  $tpl->setCurrentBlock("desc");
99  $tpl->setVariable("DESC", $desc);
100  $tpl->parseCurrentBlock();
101  }
102 
103  // actions
104  $actions = $component->getActions();
105  if ($actions !== null) {
106  $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
107  }
108 
109  // properties
110  $props = $component->getProperties();
111  if (count($props) > 0) {
112  $cnt = 0;
113  foreach ($props as $name => $value) {
114  if ($value instanceof \ILIAS\UI\Component\Button\Shy) {
115  $value = $default_renderer->render($value);
116  }
117 
118  $cnt++;
119  if ($cnt % 2 == 1) {
120  $tpl->setCurrentBlock("property_row");
121  $tpl->setVariable("PROP_NAME_A", $name);
122  $tpl->setVariable("PROP_VAL_A", $value);
123  } else {
124  $tpl->setVariable("PROP_NAME_B", $name);
125  $tpl->setVariable("PROP_VAL_B", $value);
126  $tpl->parseCurrentBlock();
127  }
128  }
129  if ($cnt % 2 == 1) {
130  $tpl->parseCurrentBlock();
131  }
132  $tpl->setCurrentBlock("properties");
133  $tpl->parseCurrentBlock();
134  }
135 
136  $title = $component->getTitle();
137 
138  if ($title instanceof \ILIAS\UI\Component\Button\Shy) {
139  $title = $default_renderer->render($title);
140  }
141 
142  $tpl->setVariable("TITLE", $title);
143 
144  return $tpl->get();
145  }
146 
150  protected function getComponentInterfaceName()
151  {
152  return array(Component\Item\Standard::class
153  , Component\Item\Group::class
154  );
155  }
156 }
Class Factory.
renderGroup(Component\Item\Group $component, RendererInterface $default_renderer)
Definition: Renderer.php:28
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
Class BaseForm.
Common interface to all items.
Definition: Item.php:13
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:16
Common interface to all items.
Definition: Group.php:13
renderStandard(Component\Item\Item $component, RendererInterface $default_renderer)
Definition: Renderer.php:53
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.