ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
33 {
37  public function render(Component\Component $component, RendererInterface $default_renderer): string
38  {
39  if ($component instanceof Component\Panel\Standard) {
40  return $this->renderStandard($component, $default_renderer);
41  } elseif ($component instanceof Component\Panel\Sub) {
42  return $this->renderSub($component, $default_renderer);
43  } elseif ($component instanceof Component\Panel\Report) {
44  return $this->renderReport($component, $default_renderer);
45  }
46  $this->cannotHandleComponent($component);
47  }
48 
49  protected function getContentAsString(Component\Component $component, RendererInterface $default_renderer): string
50  {
51  $content = "";
52  foreach ($component->getContent() as $item) {
53  $content .= $default_renderer->render($item);
54  }
55  return $content;
56  }
57 
58  protected function renderStandard(Component\Panel\Standard $component, RendererInterface $default_renderer): string
59  {
60  $tpl = $this->getTemplate("tpl.standard.html", true, true);
61  $tpl = $this->parseHeader($component, $default_renderer, $tpl);
62  $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
63  return $tpl->get();
64  }
65 
66  protected function renderSub(Component\Panel\Sub $component, RendererInterface $default_renderer): string
67  {
68  $tpl = $this->getTemplate("tpl.sub.html", true, true);
69 
70  $actions = $component->getActions();
71 
72  if ($component->getTitle() != "" || $actions !== null) {
73  $tpl->setCurrentBlock("title");
74 
75  // actions
76  if ($actions !== null) {
77  $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
78  }
79 
80  // title
81  $tpl->setVariable("TITLE", $component->getTitle());
82  $tpl->parseCurrentBlock();
83  }
84 
85  if ($component->getFurtherInformation()) {
86  $tpl->setCurrentBlock("with_further_information");
87  $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
88  $tpl->setVariable("INFO", $default_renderer->render($component->getFurtherInformation()));
89  $tpl->parseCurrentBlock();
90  } else {
91  $tpl->setCurrentBlock("no_further_information");
92  $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
93  $tpl->parseCurrentBlock();
94  }
95 
96  return $tpl->get();
97  }
98 
99  protected function renderReport(Component\Panel\Report $component, RendererInterface $default_renderer): string
100  {
101  $tpl = $this->getTemplate("tpl.report.html", true, true);
102  $tpl = $this->parseHeader($component, $default_renderer, $tpl);
103  $tpl->setVariable("BODY", $this->getContentAsString($component, $default_renderer));
104  return $tpl->get();
105  }
106 
107  protected function parseHeader(
109  RendererInterface $default_renderer,
110  Template $tpl
111  ): Template {
112  $view_controls = $component->getViewControls();
113  if ($view_controls) {
114  foreach ($view_controls as $view_control) {
115  $tpl->setCurrentBlock("view_controls");
116  $tpl->setVariable("VIEW_CONTROL", $default_renderer->render($view_control));
117  $tpl->parseCurrentBlock();
118  }
119  }
120 
121  $actions = $component->getActions();
122  if ($actions !== null) {
123  $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
124  }
125 
126  $tpl->setVariable("TITLE", $component->getTitle());
127 
128  return $tpl;
129  }
130 }
renderSub(Component\Panel\Sub $component, RendererInterface $default_renderer)
Definition: Renderer.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
renderReport(Component\Panel\Report $component, RendererInterface $default_renderer)
Definition: Renderer.php:99
getContentAsString(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:49
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:37
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
renderStandard(Component\Panel\Standard $component, RendererInterface $default_renderer)
Definition: Renderer.php:58
parseHeader(Component\Panel\Standard|Component\Panel\Report $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:107