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 
3 declare(strict_types=1);
4 
22 
26 
32 {
33  public function render(Component\Component $component, RendererInterface $default_renderer): string
34  {
38  $this->checkComponent($component);
39 
40  if ($component instanceof Component\Player\Audio) {
41  return $this->renderAudio($component, $default_renderer);
42  }
43  if ($component instanceof Component\Player\Video) {
44  return $this->renderVideo($component, $default_renderer);
45  }
46  return "";
47  }
48 
49  public function renderAudio(Component\Component $component, RendererInterface $default_renderer): string
50  {
51  $tpl = $this->getTemplate("tpl.audio.html", true, true);
52 
53  $component = $component->withAdditionalOnLoadCode(function ($id) {
54  return "$('#$id').mediaelementplayer({stretching: 'responsive'});";
55  });
56  $id = $this->bindJavaScript($component);
57 
58  if ($component->getTranscription() != "") {
59  $factory = $this->getUIFactory();
60  $page = $factory->modal()->lightboxTextPage(
61  $component->getTranscription(),
62  $this->txt("ui_transcription")
63  );
64  $modal = $factory->modal()->lightbox($page);
65  $button = $factory->button()->standard($this->txt("ui_transcription"), '')
66  ->withOnClick($modal->getShowSignal());
67 
68  $tpl->setCurrentBlock("transcription");
69  $tpl->setVariable("BUTTON_AND_MODAL", $default_renderer->render([$button, $modal]));
70  $tpl->parseCurrentBlock();
71  }
72 
73  $tpl->setVariable("ID", $id);
74  $tpl->setVariable("SOURCE", $component->getSource());
75 
76  return $tpl->get();
77  }
78 
79  public function renderVideo(
80  Component\Component $component,
81  RendererInterface $default_renderer
82  ): string {
83  $tpl = $this->getTemplate("tpl.video.html", true, true);
84 
85  $component = $component->withAdditionalOnLoadCode(function ($id) {
86  return "$('#$id').mediaelementplayer();";
87  });
88  $id = $this->bindJavaScript($component);
89 
90  foreach ($component->getSubtitleFiles() as $lang_key => $file) {
91  $tpl->setCurrentBlock("track");
92  $tpl->setVariable("TRACK_SOURCE", $file);
93  $tpl->setVariable("TRACK_LANG", $lang_key);
94  $tpl->parseCurrentBlock();
95  }
96 
97  if ($component->getPoster() !== "") {
98  $tpl->setCurrentBlock("poster");
99  $tpl->setVariable("POSTER_SOURCE", $component->getPoster());
100  $tpl->parseCurrentBlock();
101  }
102 
103  $tpl->setVariable("ID", $id);
104  $tpl->setVariable("SOURCE", $component->getSource());
105 
106  return $tpl->get();
107  }
108 
109  public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry): void
110  {
111  parent::registerResources($registry);
112  $registry->register('./node_modules/mediaelement/build/mediaelement-and-player.min.js');
113  $registry->register('./node_modules/mediaelement/build/renderers/vimeo.min.js');
114  $registry->register('./node_modules/mediaelement/build/mediaelementplayer.min.css');
115  }
116 
117  protected function getComponentInterfaceName(): array
118  {
119  return [Component\Player\Player::class];
120  }
121 }
Class Factory.
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
Class ChatMainBarProvider .
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.
renderAudio(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:49
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:109
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: Audio.php:21
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
renderVideo(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:79
$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
$factory
Definition: metadata.php:75
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.