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;
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 $component = $component->withAdditionalOnLoadCode(function ($id) {
49 return "$('#$id').mediaelementplayer({stretching: 'responsive'});";
50 });
51 $id = $this->bindJavaScript($component);
52
53 if ($component->getTranscription() != "") {
54 $factory = $this->getUIFactory();
55 $page = $factory->modal()->lightboxTextPage(
56 $component->getTranscription(),
57 $this->txt("ui_transcription")
58 );
59 $modal = $factory->modal()->lightbox($page);
60 $button = $factory->button()->standard($this->txt("ui_transcription"), '')
61 ->withOnClick($modal->getShowSignal());
62
63 $tpl->setCurrentBlock("transcription");
64 $tpl->setVariable("BUTTON_AND_MODAL", $default_renderer->render([$button, $modal]));
65 $tpl->parseCurrentBlock();
66 }
67
68 $tpl->setVariable("ID", $id);
69 $tpl->setVariable("SOURCE", $component->getSource());
70
71 return $tpl->get();
72 }
73
74 public function renderVideo(
75 Component\Component $component,
76 RendererInterface $default_renderer
77 ): string {
78 $tpl = $this->getTemplate("tpl.video.html", true, true);
79
80 $component = $component->withAdditionalOnLoadCode(function ($id) {
81 return "$('#$id').mediaelementplayer();";
82 });
83 $id = $this->bindJavaScript($component);
84
85 foreach ($component->getSubtitleFiles() as $lang_key => $file) {
86 $tpl->setCurrentBlock("track");
87 $tpl->setVariable("TRACK_SOURCE", $file);
88 $tpl->setVariable("TRACK_LANG", $lang_key);
89 $tpl->parseCurrentBlock();
90 }
91
92 if ($component->getPoster() !== "") {
93 $tpl->setCurrentBlock("poster");
94 $tpl->setVariable("POSTER_SOURCE", $component->getPoster());
95 $tpl->parseCurrentBlock();
96 }
97
98 $tpl->setVariable("ID", $id);
99 $tpl->setVariable("SOURCE", $component->getSource());
100
101 return $tpl->get();
102 }
103
104 public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry): void
105 {
106 parent::registerResources($registry);
107 $registry->register('./assets/js/mediaelement-and-player.min.js');
108 $registry->register('./assets/css/mediaelementplayer.min.css');
109 $registry->register('./assets/js/vimeo.min.js');
110 }
111}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:104
renderAudio(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:44
renderVideo(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:74
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:33
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.
Definition: UI.php:24
return true
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.