ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
Renderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Renderer as RendererInterface;
26
32{
33 public function render(Component\Component $component, RendererInterface $default_renderer): string
34 {
35 if ($component instanceof Component\Player\Audio) {
36 return $this->renderAudio($component, $default_renderer);
37 }
38 if ($component instanceof Component\Player\Video) {
39 return $this->renderVideo($component, $default_renderer);
40 }
41 $this->cannotHandleComponent($component);
42 }
43
44 public function renderAudio(Component\Component $component, RendererInterface $default_renderer): string
45 {
46 $tpl = $this->getTemplate("tpl.audio.html", true, true);
47
48 $id = $this->bindJavaScript($component) ?? $this->createId();
49
50 if ($component->getTranscription() != "") {
51 $factory = $this->getUIFactory();
52 $page = $factory->modal()->lightboxTextPage(
53 $component->getTranscription(),
54 $this->txt("ui_transcription")
55 );
56 $modal = $factory->modal()->lightbox($page);
57 $button = $factory->button()->standard($this->txt("ui_transcription"), '')
58 ->withOnClick($modal->getShowSignal());
59
60 $tpl->setCurrentBlock("transcription");
61 $tpl->setVariable("BUTTON_AND_MODAL", $default_renderer->render([$button, $modal]));
62 $tpl->parseCurrentBlock();
63 }
64
65 $tpl->setVariable("ID", $id);
66 $tpl->setVariable("SOURCE", $component->getSource());
67
68 return $tpl->get();
69 }
70
71 public function renderVideo(
72 Component\Component $component,
73 RendererInterface $default_renderer
74 ): string {
75 if ($this->isVimeo($component)) {
76 return $this->renderVimeo(
77 $component,
78 $default_renderer
79 );
80 } elseif ($this->isYoutube($component)) {
81 return $this->renderYoutube(
82 $component,
83 $default_renderer
84 );
85 }
86 return $this->renderNative(
87 $component,
88 $default_renderer
89 );
90 }
91
92 public function renderVimeo(
93 Component\Component $component,
94 RendererInterface $default_renderer
95 ): string {
96
97 $tpl = $this->getTemplate("tpl.video_vimeo.html", true, true);
98
99 $id = $this->bindJavaScript($component) ?? $this->createId();
100
101 $tpl->setVariable("ID", $id);
102 $tpl->setVariable("SOURCE", $component->getSource());
103
104 return $tpl->get();
105 }
106
107 public function renderYoutube(
108 Component\Component $component,
109 RendererInterface $default_renderer
110 ): string {
111
112 $tpl = $this->getTemplate("tpl.video_youtube.html", true, true);
113
114 $id = $this->bindJavaScript($component) ?? $this->createId();
115
116 $tpl->setVariable("ID", $id);
117 $tpl->setVariable("SOURCE", $component->getSource());
118
119 return $tpl->get();
120 }
121
122 public function renderNative(
123 Component\Component $component,
124 RendererInterface $default_renderer
125 ): string {
126
127 $tpl = $this->getTemplate("tpl.video.html", true, true);
128
129 $id = $this->bindJavaScript($component) ?? $this->createId();
130
131 foreach ($component->getSubtitleFiles() as $lang_key => $file) {
132 $tpl->setCurrentBlock("track");
133 $tpl->setVariable("TRACK_SOURCE", $file);
134 $tpl->setVariable("TRACK_LANG", $lang_key);
135 $tpl->parseCurrentBlock();
136 }
137
138 if ($component->getPoster() !== "") {
139 $tpl->setCurrentBlock("poster");
140 $tpl->setVariable("POSTER_SOURCE", $component->getPoster());
141 $tpl->parseCurrentBlock();
142 }
143
144 $tpl->setVariable("ID", $id);
145 $tpl->setVariable("SOURCE", $component->getSource());
146
147 return $tpl->get();
148 }
149
150 protected function isVimeo(
151 Component\Component $component
152 ): bool {
153 if (is_int(strpos($component->getSource(), 'vimeo.com'))) {
154 return true;
155 }
156 return false;
157 }
158
159 protected function isYoutube(
160 Component\Component $component
161 ): bool {
162 if (is_int(strpos($component->getSource(), 'youtube.com'))) {
163 return true;
164 }
165 return false;
166 }
167}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
renderNative(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:122
renderAudio(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:44
renderVideo(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:71
isVimeo(Component\Component $component)
Definition: Renderer.php:150
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:33
renderYoutube(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:107
isYoutube(Component\Component $component)
Definition: Renderer.php:159
renderVimeo(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:92
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.
return true
An entity that renders components to a string output.
Definition: Renderer.php:31
if(!file_exists('../ilias.ini.php'))