ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 
32 {
36  public function render(Component\Component $component, RendererInterface $default_renderer): string
37  {
41  $this->checkComponent($component);
42  $tpl = $this->getTemplate("tpl.card.html", true, true);
43 
44  $title = $component->getTitle();
45  if ($title instanceof Shy) {
46  $image_alt = $title->getLabel();
47  $title = $default_renderer->render($title);
48  } else {
49  $image_alt = $title;
50  }
51 
52  if ($component->isHighlighted()) {
53  $tpl->touchBlock("highlight");
54  } else {
55  $tpl->touchBlock("no_highlight");
56  }
57 
58  $id = $this->bindJavaScript($component);
59  if (!$id) {
60  $id = $this->createId();
61  }
62  if (!empty($component->getTitleAction())) {
63  if (is_string($component->getTitleAction())) {
64  $tpl->setCurrentBlock("title_action_begin");
65  $tpl->setVariable("HREF", $component->getTitleAction());
66  $tpl->setVariable("ID", $id);
67  $tpl->parseCurrentBlock();
68  } elseif ($title instanceof Shy) {
69  $title = $default_renderer->render($title);
70  }
71  if (is_array($component->getTitleAction())) {
72  $tpl->setCurrentBlock("title_action_begin");
73  $tpl->setVariable("ID", $id);
74  $tpl->parseCurrentBlock();
75  }
76  }
77 
78  $tpl->setVariable("TITLE", $title);
79 
80  if ($component->getImage()) {
81  $tpl->setVariable("IMAGE", $default_renderer->render(
82  $component->getImage()->withAlt($this->txt("open")." ".strip_tags($image_alt))
83  ));
84  }
85 
86  if (!empty($component->getTitleAction())) {
87  $tpl->touchBlock("title_action_end");
88  }
89 
90  if (is_array($component->getSections())) {
91  foreach ($component->getSections() as $section) {
92  $tpl->setCurrentBlock("section");
93  $tpl->setVariable("SECTION", $default_renderer->render($section));
94  $tpl->parseCurrentBlock();
95  }
96  }
97 
98  if ($component instanceof Component\Card\RepositoryObject) {
99  $tpl->setCurrentBlock("action");
100 
101  $obj_icon = $component->getObjectIcon();
102  if ($obj_icon !== null) {
103  $tpl->setVariable("OBJECT_ICON", $default_renderer->render($obj_icon));
104  }
105 
106  $progress = $component->getProgress();
107  if ($progress !== null) {
108  $tpl->setVariable("PROGRESS_STATUS", $default_renderer->render($progress));
109  }
110 
111  $certificate = $component->getCertificateIcon();
112  if ($certificate !== null) {
113  $certificate_icon = new StandardIcon("cert", "Certificate", "medium", false);
114  $tpl->setVariable("PROGRESS_STATUS", $default_renderer->render($certificate_icon));
115  }
116 
117  $dropdown = $component->getActions();
118  if ($dropdown !== null) {
119  $tpl->setVariable("DROPDOWN", $default_renderer->render($dropdown));
120  }
121 
122  $tpl->parseCurrentBlock();
123  }
124 
125  return $tpl->get();
126  }
127 
131  protected function getComponentInterfaceName(): array
132  {
133  return array(Component\Card\Card::class);
134  }
135 }
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $id)
Get a text from the language file.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Card.php:21
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.