ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Renderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Renderer as RendererInterface;
30
32{
36 public function render(Component\Component $component, RendererInterface $default_renderer): string
37 {
38 if (!$component instanceof Component\Card\Card) {
39 $this->cannotHandleComponent($component);
40 }
41
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}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This implements commonalities between standard and primary buttons.
Definition: Button.php:35
render(Component\Component $component, RendererInterface $default_renderer)
@inheritdocs
Definition: Renderer.php:36
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
An entity that renders components to a string output.
Definition: Renderer.php:31