ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 2017 Alexander Killing <killing@leifos.de> Extended GPL, see docs/LICENSE */
6 
8 
13 
15 {
19  public function render(Component\Component $component, RendererInterface $default_renderer)
20  {
21  $this->checkComponent($component);
22 
23  if ($component instanceof Component\Link\Standard) {
24  return $this->renderStandard($component, $default_renderer);
25  }
26  if ($component instanceof Component\Link\Bulky) {
27  return $this->renderBulky($component, $default_renderer);
28  }
29  }
30 
31  protected function setStandardVars(
32  string $tpl_name,
33  Component\Link\Link $component
34  ) : Template {
35  $tpl = $this->getTemplate($tpl_name, true, true);
36  $action = $component->getAction();
37  $label = $component->getLabel();
38  if ($component->getOpenInNewViewport()) {
39  $tpl->touchBlock("open_in_new_viewport");
40  }
41  $tpl->setVariable("LABEL", $label);
42  $tpl->setVariable("HREF", $action);
43  return $tpl;
44  }
45 
46  protected function renderStandard(
47  Component\Link\Standard $component,
48  RendererInterface $default_renderer
49  ) : string {
50  $tpl_name = "tpl.standard.html";
51  $tpl = $this->setStandardVars($tpl_name, $component);
52  return $tpl->get();
53  }
54 
55  protected function renderBulky(
56  Component\Link\Bulky $component,
57  RendererInterface $default_renderer
58  ) : string {
59  $tpl_name = "tpl.bulky.html";
60  $tpl = $this->setStandardVars($tpl_name, $component);
61  $renderer = $default_renderer->withAdditionalContext($component);
62  $tpl->setVariable("SYMBOL", $renderer->render($component->getSymbol()));
63 
64  $id = $this->bindJavaScript($component);
65  $tpl->setVariable("ID", $id);
66  return $tpl->get();
67  }
68 
72  protected function getComponentInterfaceName()
73  {
74  return [
75  Component\Link\Standard::class,
76  Component\Link\Bulky::class
77  ];
78  }
79 }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.