ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
12 
14 {
18  public function render(Component\Component $component, RendererInterface $default_renderer)
19  {
20  $this->checkComponent($component);
21 
22  if ($component instanceof Notification) {
23  return $this->renderNotification($component, $default_renderer);
24  } elseif ($component instanceof Component\Item\Group) {
25  return $this->renderGroup($component, $default_renderer);
26  } elseif ($component instanceof Component\Item\Standard) {
27  return $this->renderStandard($component, $default_renderer);
28  }
29  }
30 
31  protected function renderGroup(Component\Item\Group $component, RendererInterface $default_renderer)
32  {
33  $tpl = $this->getTemplate("tpl.group.html", true, true);
34  $title = $component->getTitle();
35  $items = $component->getItems();
36 
37  // items
38  foreach ($items as $item) {
39  $tpl->setCurrentBlock("item");
40  $tpl->setVariable("ITEM", $default_renderer->render($item));
41  $tpl->parseCurrentBlock();
42  }
43 
44  if ($title != "") {
45  $tpl->setCurrentBlock("title");
46  $tpl->setVariable("TITLE", $title);
47  $tpl->parseCurrentBlock();
48  }
49 
50  // actions
51  $actions = $component->getActions();
52  if ($actions !== null) {
53  $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
54  } else {
55  $tpl->setVariable("ACTIONS", "");
56  }
57 
58 
59 
60  return $tpl->get();
61  }
62 
63  protected function renderStandard(Component\Item\Item $component, RendererInterface $default_renderer)
64  {
65  $tpl = $this->getTemplate("tpl.item_standard.html", true, true);
66 
67  $this->renderTitle($component, $default_renderer, $tpl);
68  $this->renderDescription($component, $default_renderer, $tpl);
69  $this->renderProperties($component, $default_renderer, $tpl);
70  // color
71  $color = $component->getColor();
72  if ($color !== null) {
73  $tpl->setCurrentBlock("color");
74  $tpl->setVariable("COLOR", $color->asHex());
75  $tpl->parseCurrentBlock();
76  }
77 
78  // lead
79  $lead = $component->getLead();
80  if ($lead != null) {
81  if (is_string($lead)) {
82  $tpl->setCurrentBlock("lead_text");
83  $tpl->setVariable("LEAD_TEXT", $lead);
84  $tpl->parseCurrentBlock();
85  }
86  if ($lead instanceof Component\Image\Image) {
87  $tpl->setCurrentBlock("lead_image");
88  $tpl->setVariable("LEAD_IMAGE", $default_renderer->render($lead));
89  $tpl->parseCurrentBlock();
90  }
91  if ($lead instanceof Component\Symbol\Icon\Icon) {
92  $tpl->setCurrentBlock("lead_icon");
93  $tpl->setVariable("LEAD_ICON", $default_renderer->render($lead));
94  $tpl->parseCurrentBlock();
95  $tpl->setCurrentBlock("lead_start_icon");
96  $tpl->parseCurrentBlock();
97  } else {
98  $tpl->setCurrentBlock("lead_start");
99  $tpl->parseCurrentBlock();
100  }
101  $tpl->touchBlock("lead_end");
102  }
103  // actions
104  $actions = $component->getActions();
105  if ($actions !== null) {
106  $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
107  }
108  return $tpl->get();
109  }
110 
111  protected function renderNotification(Notification $component, RendererInterface $default_renderer)
112  {
113  $tpl = $this->getTemplate("tpl.item_notification.html", true, true);
114  $this->renderTitle($component, $default_renderer, $tpl);
115  $this->renderDescription($component, $default_renderer, $tpl);
116  $this->renderProperties($component, $default_renderer, $tpl);
117  $tpl->setVariable("LEAD_ICON", $default_renderer->render($component->getLeadIcon()));
118 
119  // actions
120  $actions = $component->getActions();
121  if ($actions !== null) {
122  $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
123  }
124 
125  // additional content
126  if ($component->getAdditionalContent()) {
127  $tpl->setCurrentBlock("additional_content");
128  $tpl->setVariable("ADDITIONAL_CONTENT", $default_renderer->render($component->getAdditionalContent()));
129  $tpl->parseCurrentBlock();
130  }
131 
132  $aggregates_html = "";
133 
134  // aggregate notification
135  $title = $this->getUIFactory()->button()->bulky($this->getUIFactory()->symbol()->glyph()->back(), $this->txt("back"), "");
136  $aggregates_html = $default_renderer->render(
137  $this->getUIFactory()->mainControls()->slate()->notification($default_renderer->render($title), $component->getAggregateNotifications())
138  );
139 
140  $toggleable = true;
141  if (!empty($component->getAggregateNotifications())) {
142  $toggleable = false;
143  }
144 
148  $component = $component->withAdditionalOnLoadCode(
149  function ($id) use ($toggleable) {
150  return "il.UI.item.notification.getNotificationItemObject($($id)).registerAggregates($toggleable);";
151  }
152  );
153 
154  //Bind id
155  $item_id = $this->bindJavaScript($component);
156 
157  $tpl->setCurrentBlock("aggregate_notifications");
158  $tpl->setVariable("AGGREGATES", $aggregates_html);
159  $tpl->setVariable("PARENT_ID", $item_id);
160  $tpl->parseCurrentBlock();
161 
162  // close action
163  if ($component->getCloseAction()) {
164  $url = $component->getCloseAction();
168  $close_action = $this->getUIFactory()->button()->close()->withAdditionalOnLoadCode(
169  function ($id) use ($url, $item_id) {
170  return "il.UI.item.notification.getNotificationItemObject($($id)).registerCloseAction('$url',1);";
171  }
172  );
173  $tpl->setVariable("CLOSE_ACTION", $default_renderer->render($close_action));
174  }
175 
176  $tpl->setCurrentBlock("id");
177  $tpl->setVariable('ID', $item_id);
178  $tpl->parseCurrentBlock();
179 
180 
181  return $tpl->get();
182  }
183 
184  protected function renderTitle(
185  Component\Item\Item $component,
186  RendererInterface $default_renderer,
187  \ILIAS\UI\Implementation\Render\Template $tpl
188  ) {
189  $title = $component->getTitle();
190  if ($title instanceof \ILIAS\UI\Component\Button\Shy || $title instanceof \ILIAS\UI\Component\Link\Link) {
191  $title = $default_renderer->render($title);
192  }
193  $tpl->setVariable("TITLE", $title);
194  }
195 
196  protected function renderDescription(
197  Component\Item\Item $component,
198  RendererInterface $default_renderer,
199  \ILIAS\UI\Implementation\Render\Template $tpl
200  ) {
201  // description
202  $desc = $component->getDescription();
203  if (trim($desc) != "") {
204  $tpl->setCurrentBlock("desc");
205  $tpl->setVariable("DESC", $desc);
206  $tpl->parseCurrentBlock();
207  }
208  }
209 
210  protected function renderProperties(
211  Component\Item\Item $component,
212  RendererInterface $default_renderer,
213  \ILIAS\UI\Implementation\Render\Template $tpl
214  ) {
215  // properties
216  $props = $component->getProperties();
217  if (count($props) > 0) {
218  $cnt = 0;
219  foreach ($props as $name => $value) {
220  if ($value instanceof \ILIAS\UI\Component\Button\Shy) {
221  $value = $default_renderer->render($value);
222  }
223  $cnt++;
224  if ($cnt % 2 == 1) {
225  $tpl->setCurrentBlock("property_row");
226  $tpl->setVariable("PROP_NAME_A", $name);
227  $tpl->setVariable("PROP_VAL_A", $value);
228  } else {
229  $tpl->setVariable("PROP_NAME_B", $name);
230  $tpl->setVariable("PROP_VAL_B", $value);
231  $tpl->parseCurrentBlock();
232  }
233  }
234  if ($cnt % 2 == 1) {
235  $tpl->parseCurrentBlock();
236  }
237  $tpl->setCurrentBlock("properties");
238  $tpl->parseCurrentBlock();
239  }
240  }
241 
245  public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
246  {
247  parent::registerResources($registry);
248  $registry->register('./src/UI/templates/js/Item/notification.js');
249  }
250 
254  protected function getComponentInterfaceName()
255  {
256  return array(
257  Component\Item\Standard::class,
258  Component\Item\Group::class,
259  Component\Item\Notification::class
260  );
261  }
262 }
Class Factory.
renderGroup(Component\Item\Group $component, RendererInterface $default_renderer)
Definition: Renderer.php:31
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
renderDescription(Component\Item\Item $component, RendererInterface $default_renderer, \ILIAS\UI\Implementation\Render\Template $tpl)
Definition: Renderer.php:196
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:245
Class ChatMainBarProvider .
getAdditionalContent()
Get the additional content of the item or null.
Common interface to all items.
Definition: Item.php:13
back()
Definition: back.php:2
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:18
if($format !==null) $name
Definition: metadata.php:230
getLeadIcon()
Get icon as lead.Note that Notifications only accept Icons as lead, this is different from the standa...
Common interface to all items.
Definition: Group.php:13
renderStandard(Component\Item\Item $component, RendererInterface $default_renderer)
Definition: Renderer.php:63
notification()
Definition: notification.php:2
withAdditionalOnLoadCode(\Closure $binder)
Add some onload-code to the component instead of replacing the existing one.
getCloseAction()
Get the url attached to this Notification Item.
renderProperties(Component\Item\Item $component, RendererInterface $default_renderer, \ILIAS\UI\Implementation\Render\Template $tpl)
Definition: Renderer.php:210
renderTitle(Component\Item\Item $component, RendererInterface $default_renderer, \ILIAS\UI\Implementation\Render\Template $tpl)
Definition: Renderer.php:184
$url
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
getAggregateNotifications()
Get the list of Notification Items, this Notification Item aggregates or an empty list...
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.