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 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
4 
6 
10 
16 {
20  public function render(Component\Component $component, RendererInterface $default_renderer)
21  {
25  $this->checkComponent($component);
26 
27  if ($component instanceof Component\Panel\Standard) {
31  return $this->renderStandard($component, $default_renderer);
32  } elseif ($component instanceof Component\Panel\Sub) {
36  return $this->renderSub($component, $default_renderer);
37  }
41  return $this->renderReport($component, $default_renderer);
42  }
43 
49  protected function getContentAsString(Component\Component $component, RendererInterface $default_renderer)
50  {
51  $content = "";
52  foreach ($component->getContent() as $item) {
53  $content .= $default_renderer->render($item);
54  }
55  return $content;
56  }
57 
63  protected function renderStandard(Component\Panel\Standard $component, RendererInterface $default_renderer)
64  {
65  $tpl = $this->getTemplate("tpl.standard.html", true, true);
66 
67  // actions
68  $actions = $component->getActions();
69  if ($actions !== null) {
70  $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
71  }
72 
73  $tpl->setVariable("TITLE", $component->getTitle());
74  $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
75  return $tpl->get();
76  }
77 
83  protected function renderSub(Component\Panel\Sub $component, RendererInterface $default_renderer)
84  {
85  $tpl = $this->getTemplate("tpl.sub.html", true, true);
86 
87  $actions = $component->getActions();
88 
89  if ($component->getTitle() != "" || $actions !== null) {
90  $tpl->setCurrentBlock("title");
91 
92  // actions
93  if ($actions !== null) {
94  $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
95  }
96 
97  // title
98  $tpl->setVariable("TITLE", $component->getTitle());
99  $tpl->parseCurrentBlock();
100  }
101 
102  if ($component->getCard()) {
103  $tpl->setCurrentBlock("with_card");
104  $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
105  $tpl->setVariable("CARD", $default_renderer->render($component->getCard()));
106  $tpl->parseCurrentBlock();
107  } else {
108  $tpl->setCurrentBlock("no_card");
109  $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
110  $tpl->parseCurrentBlock();
111  }
112 
113  return $tpl->get();
114  }
115 
121  protected function renderReport(Component\Panel\Report $component, RendererInterface $default_renderer)
122  {
123  $tpl = $this->getTemplate("tpl.report.html", true, true);
124  $tpl->setVariable("TITLE", $component->getTitle());
125  $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
126  return $tpl->get();
127  }
128 
132  protected function getComponentInterfaceName()
133  {
134  return [Component\Panel\Panel::class];
135  }
136 }
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
$tpl
Definition: ilias.php:10
renderSub(Component\Panel\Sub $component, RendererInterface $default_renderer)
Definition: Renderer.php:83
renderReport(Component\Panel\Report $component, RendererInterface $default_renderer)
Definition: Renderer.php:121
getContentAsString(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:49
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
renderStandard(Component\Panel\Standard $component, RendererInterface $default_renderer)
Definition: Renderer.php:63
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.