ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.VideoViewGUI.php
Go to the documentation of this file.
1<?php
2
20
25
30{
31 protected \ilCtrlInterface $ctrl;
32 protected \ILIAS\MediaCast\MediaCastManager $mc_manager;
33 protected string $rss_link;
34 protected \ilToolbarGUI $toolbar;
35 protected \ilGlobalTemplateInterface $main_tpl;
36 protected \ilObjMediaCast $media_cast;
37 protected \ilGlobalTemplateInterface $tpl;
38 protected \ILIAS\DI\UIServices $ui;
39 protected \ilLanguage $lng;
40 protected \ilObjUser $user;
41 protected string $completed_callback = "";
42 protected string $autoplay_callback = "";
44 protected string $video_wrapper_id = "mcst_video";
45
46 public function __construct(
47 \ilObjMediaCast $obj,
49 string $rss_link = ""
50 ) {
51 global $DIC;
52
53 $this->ui = $DIC->ui();
54 $this->rss_link = $rss_link;
55 $this->lng = $DIC->language();
56 $this->media_cast = $obj;
57 $this->tpl = $tpl;
58 $this->video_sequence = new VideoSequence($this->media_cast);
59 $this->user = $DIC->user();
60 $this->main_tpl = $DIC->ui()->mainTemplate();
61 $this->toolbar = $DIC->toolbar();
62 $this->ctrl = $DIC->ctrl();
63 $this->mc_manager = $DIC->mediaCast()->internal()->domain()->mediaCast(
64 $this->media_cast
65 );
66 }
67
68 public function setCompletedCallback(string $completed_callback): void
69 {
70 $this->completed_callback = $completed_callback;
71 }
72
73 public function setAutoplayCallback(string $autoplay_callback): void
74 {
75 $this->autoplay_callback = $autoplay_callback;
76 }
77
81 public function renderMainColumn(): string
82 {
83 if (count($this->video_sequence->getVideos()) == 0) {
84 return "";
85 }
86
87 $widget = new VideoWidgetGUI($this->tpl, "mcst_video");
88 $widget->setVideo($this->video_sequence->getFirst());
89 return $widget->render();
90 }
91
92 public function renderToolbar(): void
93 {
96
97 $video_cnt = count($this->video_sequence->getVideos());
98
99 $mcst_settings = \ilMediaCastSettings::_getInstance();
100
101 $autoplay = $this->getAutoplay();
102
103 $factory = $this->ui->factory();
104 $renderer = $this->ui->renderer();
105
106 if ($video_cnt > 1) {
107 $back = $factory->button()->standard(
108 "<span class=\"glyphicon glyphicon-chevron-left \" aria-hidden=\"true\"></span>",
109 ""
110 )
111 ->withOnLoadCode(function ($id) {
112 return
113 "$(\"#$id\").click(function() { il.VideoWidget.previous(\"" . $this->video_wrapper_id . "\"); return false;});";
114 });
115 $next = $factory->button()->standard(
116 "<span class=\"glyphicon glyphicon-chevron-right \" aria-hidden=\"true\"></span>",
117 ""
118 )
119 ->withOnLoadCode(function ($id) {
120 return
121 "$(\"#$id\").click(function() { il.VideoWidget.next(\"" . $this->video_wrapper_id . "\"); return false;});";
122 });
123
124 $toolbar->addStickyItem($back);
125
126 $dd = $this->getDropdown();
127 if (!is_null($dd)) {
129 }
130
131 $toolbar->addStickyItem($next);
132 }
133
134 // autoplay
135 if ($this->media_cast->getAutoplayMode() !== \ilObjMediaCast::AUTOPLAY_NO && $video_cnt > 1) {
137 $s = new SignalGenerator();
138 $autoplay_on = $s->create();
139 $autoplay_off = $s->create();
140 $button = $factory->button()->toggle($lng->txt("mcst_autoplay"), $autoplay_on, $autoplay_off, $autoplay);
141 $toolbar->addStickyItem($button);
142 $this->main_tpl->addOnLoadCode("
143 $(document).on('" . $autoplay_on . "', function (event, signalData) {
144 il.VideoPlaylist.autoplay('mcst_playlist', true);
145 });
146 $(document).on('" . $autoplay_off . "', function (event, signalData) {
147 il.VideoPlaylist.autoplay('mcst_playlist', false);
148 });");
149 }
150
151 if ($video_cnt > 0 && $this->rss_link !== "") {
152 $f = $this->ui->factory();
153 $actions = [
154 $f->link()->standard(
155 $lng->txt("mcst_webfeed"),
156 $this->rss_link
157 )->withOpenInNewViewport(true)
158 ];
159 $toolbar->addComponent($f->dropdown()->standard($actions));
160 }
161 }
162
163 protected function getAutoplay(): bool
164 {
165 $video_cnt = count($this->video_sequence->getVideos());
166 if ($video_cnt <= 1) {
167 return false;
168 }
169 $autoplay = (bool) ($this->user->getPref("mcst_autoplay") ??
170 ($this->media_cast->getAutoplayMode() == \ilObjMediaCast::AUTOPLAY_ACT));
171 if ($this->media_cast->getAutoplayMode() == \ilObjMediaCast::AUTOPLAY_NO) {
172 $autoplay = false;
173 }
174 return $autoplay;
175 }
176
177 protected function getDropdown(): ?\ILIAS\UI\Component\Dropdown\Standard
178 {
179
180 $actions = [];
181 foreach ($this->video_sequence->getVideos() as $video) {
182 $actions[] = $this->ui->factory()->button()->shy(
183 $video->getTitle(),
184 "#"
185 )->withOnLoadCode(function (string $id) use ($video) {
186 return "document.getElementById('$id').addEventListener('click', () => {il.VideoPlaylist.toggleItem('mcst_playlist', '" . $video->getId() . "'); $('.ilToolbarStickyItem .dropdown.open').removeClass('open');});";
187 });
188 }
189 if (count($actions) > 0) {
190 return $this->ui->factory()->dropdown()->standard($actions);
191 }
192 return null;
193 }
194
195 public function renderSideColumn(): string
196 {
197 $mcst_settings = \ilMediaCastSettings::_getInstance();
198
199 $autoplay = $this->getAutoplay();
200
201 $lng = $this->lng;
202 $tpl = new \ilTemplate("tpl.video_cast_side.html", true, true, "components/ILIAS/MediaCast/Presentation");
203
204 $factory = $this->ui->factory();
205 $renderer = $this->ui->renderer();
206
207 // items
208 $items = [];
209 $has_items = false;
210
211 $panel_items = [];
212
213 foreach ($this->video_sequence->getVideos() as $video) {
214 $has_items = true;
215 $preview = new VideoPreviewGUI(
216 $video->getPreviewPic(),
217 "il.VideoPlaylist.toggleItem('mcst_playlist', '" . $video->getId() . "');",
218 $video->getPlayingTime()
219 );
220 $completed = false;
221
222 $re = \ilChangeEvent::_lookupReadEvents($video->getId(), $this->user->getId());
223 if (count($re) > 0) {
224 if ($re[0]["read_count"] > 0) {
225 $completed = true;
226 }
227 }
228
229 $b = $factory->button()->shy($video->getTitle(), "")->withOnLoadCode(function ($id) use ($video) {
230 return
231 "$(\"#$id\").click(function() { il.VideoPlaylist.toggleItem('mcst_playlist', '" . $video->getId() . "'); return false;});";
232 });
233
234 $this->ctrl->setParameterByClass(
235 \ilObjMediaCastGUI::class,
236 "mob_id",
237 $video->getId()
238 );
239 $items[] = [
240 "id" => $video->getId(),
241 "resource" => $video->getResource(),
242 "preview" => $preview->render(),
243 "preview_pic" => $video->getPreviewPic(),
244 "title" => $video->getTitle(),
245 "linked_title" => $renderer->renderAsync($b),
246 "mime" => $video->getMime(),
247 "poster" => $video->getPreviewPic(),
248 "description" => nl2br($video->getDescription()),
249 "completed" => $completed,
250 "duration" => $video->getDuration(),
251 "renderUrl" => $this->ctrl->getLinkTargetByClass(
252 \ilObjMediaCastGUI::class,
253 "renderVideo"
254 )
255 ];
256 }
257
258 $panel = $factory->panel()->secondary()->listing(
259 "Videos",
260 []
261 );
262 $panel_html = $renderer->render($panel);
263 $panel_html = str_replace(
264 '<div class="panel-body">',
265 '<div class="panel-body"><div id="mcst_playlist"></div>',
266 $panel_html,
267 );
268
269 $tpl->setVariable("PANEL", $panel_html);
270 // previous items / next items links
271 if ($has_items) {
273 "PREV",
274 $renderer->render(
275 $factory->button()->standard($lng->txt("mcst_prev_items"), "")->withOnLoadCode(
276 function ($id) {
277 return
278 "$(\"#$id\").click(function() { il.VideoPlaylist.previousItems('mcst_playlist'); return false;});";
279 }
280 )
281 )
282 );
284 "NEXT",
285 $renderer->render(
286 $factory->button()->standard($lng->txt("mcst_next_items"), "")->withOnLoadCode(
287 function ($id) {
288 return
289 "$(\"#$id\").click(function() { il.VideoPlaylist.nextItems('mcst_playlist'); return false;});";
290 }
291 )
292 )
293 );
294
295 $item_tpl = new \ilTemplate("tpl.playlist_item.html", true, true, "components/ILIAS/MediaCast/Video");
296 $item_tpl->setVariable("TITLE", " ");
297 $item_content = str_replace(["\n", "\r"], "", $item_tpl->get());
298
299 $item = $factory->item()->standard("#video-title#")
300 ->withLeadImage(
301 $factory->image()->responsive("#img-src#", "#img-alt#")
302 );
303
304 $item_content = $renderer->render($item);
305 $item_content = str_replace(["\n", "\r"], "", $item_content);
306
307 $init_videos = $this->media_cast->getNumberInitialVideos() > 0
308 ? $this->media_cast->getNumberInitialVideos()
309 : 1;
310 $this->tpl->addOnLoadCode(
311 "il.VideoPlaylist.init('mcst_playlist', 'mcst_video', " . json_encode(
312 $items
313 ) . ", '$item_content', " . ($autoplay ? "true" : "false") . ", " .
314 (int) $init_videos . ", '" . $this->completed_callback . "', '" . $this->autoplay_callback . "', " . ((int) $mcst_settings->getVideoCompletionThreshold()) . ");"
315 );
316
317 if (count($items) === 1) {
318 return " ";
319 }
320
321 return $tpl->get();
322 }
323
324 return "";
325 }
326
330 public function render(): string
331 {
332 // this is current only to include the resize mechanism when
333 // the main menu is changed, so that the player is resized, too
334 //\ilMediaPlayerGUI::initJavascript();
335 $tpl = new \ilTemplate("tpl.video_cast_layout.html", true, true, "components/ILIAS/MediaCast/Presentation");
336 $side_column = $this->renderSideColumn();
337
338
339 if ($side_column != "") {
340 $tpl->setCurrentBlock("with_side_column");
341 $tpl->setVariable("SIDE", $side_column);
342 } else {
343 $tpl->setCurrentBlock("video_only");
344 }
345 $tpl->setVariable("MAIN", $this->renderMainColumn());
346 $tpl->parseCurrentBlock();
347 return $tpl->get();
348 }
349
350 public function show(): void
351 {
352 if (is_object($this->tpl)) {
353 $this->renderToolbar();
354 $this->tpl->setContent(
355 $this->renderMainColumn() .
357 );
358 $this->tpl->setRightContent($this->renderSideColumn());
359 }
360 }
361
362 public function renderCommentsContainer()
363 {
364 if ($this->mc_manager->commentsActive()) {
365 $target = $this->ctrl->getLinkTargetByClass(
366 \ilObjMediaCastGUI::class,
367 "showComments"
368 );
369 return "<div data-mcst-comments='$target'></div>";
370 }
371 }
372}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$renderer
ILIAS MediaCast MediaCastManager $mc_manager
__construct(\ilObjMediaCast $obj, ?\ilGlobalTemplateInterface $tpl=null, string $rss_link="")
setAutoplayCallback(string $autoplay_callback)
setCompletedCallback(string $completed_callback)
Definition: UI.php:24
static _lookupReadEvents($obj_id, $usr_id=null)
Reads all read events which occured on the object.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addComponent(\ILIAS\UI\Component\Component $a_comp)
addStickyItem( $a_item, bool $a_output_label=false)
Add a sticky item.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26