ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
28 {
29  public function render(Component\Component $component, RendererInterface $default_renderer): string
30  {
31  $this->checkComponent($component);
32  if ($component instanceof Inline) {
33  return $this->renderInline($component, $default_renderer);
34  }
35  throw new LogicException("Cannot render: " . get_class($component));
36  }
37 
38  public function renderInline(Inline $component, RendererInterface $default_renderer): string
39  {
40  if ($result = $component->getResult()) {
41  $f = $component->getEvaluation();
42  $f($result, $component);
43  }
44 
45  $tpl = $this->getTemplate("tpl.launcher_inline.html", true, true);
46  $ui_factory = $this->getUIFactory();
47 
48  $target = $component->getTarget()->getURL();
49  $label = $component->getButtonLabel();
50  $launchable = $component->isLaunchable();
51 
52  $launch_glyph = $ui_factory->symbol()->glyph()->launch();
53  $start_button = $ui_factory->button()->bulky($launch_glyph, $label, (string) $target);
54 
55  if ($modal = $component->getModal()) {
56  if ($modal_submit_lable = $component->getModalSubmitLabel()) {
57  $modal = $modal->withSubmitLabel($modal_submit_lable);
58  }
59 
60  if ($modal_cancel_label = $component->getModalCancelLabel()) {
61  $modal = $modal->withCancelButtonLabel($modal_cancel_label);
62  }
63 
64  $tpl->setVariable("FORM", $default_renderer->render($modal));
65  $start_button = $start_button->withOnClick($modal->getShowSignal());
66  }
67 
68  if (!$launchable) {
69  $start_button =$start_button->withUnavailableAction();
70  }
71  if ($status_icon = $component->getStatusIcon()) {
72  $tpl->setVariable("STATUS_ICON", $default_renderer->render($status_icon));
73  }
74  if ($status_message = $component->getStatusMessageBox()) {
75  $tpl->setVariable("STATUS_MESSAGE", $default_renderer->render($status_message));
76  }
77  $tpl->setVariable("DESCRIPTION", $component->getDescription());
78  $tpl->setVariable("BUTTON", $default_renderer->render($start_button));
79 
80  return $tpl->get();
81  }
82 
83  protected function getComponentInterfaceName(): array
84  {
85  return [
86  Inline::class
87  ];
88  }
89 }
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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:29
renderInline(Inline $component, RendererInterface $default_renderer)
Definition: Renderer.php:38