ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 = "";
43 protected string $video_wrapper_id = "mcst_video";
44
45 public function __construct(
46 \ilObjMediaCast $obj,
48 string $rss_link = ""
49 ) {
50 global $DIC;
51
52 $this->ui = $DIC->ui();
53 $this->rss_link = $rss_link;
54 $this->lng = $DIC->language();
55 $this->media_cast = $obj;
56 $this->tpl = $tpl;
57 $this->video_sequence = new VideoSequence($this->media_cast);
58 $this->user = $DIC->user();
59 $this->main_tpl = $DIC->ui()->mainTemplate();
60 $this->toolbar = $DIC->toolbar();
61 $this->ctrl = $DIC->ctrl();
62 $this->mc_manager = $DIC->mediaCast()->internal()->domain()->mediaCast(
63 $this->media_cast
64 );
65 }
66
67 public function setCompletedCallback(string $completed_callback): void
68 {
69 $this->completed_callback = $completed_callback;
70 }
71
75 public function renderMainColumn(): string
76 {
77 if (count($this->video_sequence->getVideos()) == 0) {
78 return "";
79 }
80
81 $widget = new VideoWidgetGUI($this->tpl, "mcst_video");
82 $widget->setVideo($this->video_sequence->getFirst());
83 return $widget->render();
84 }
85
86 public function renderToolbar(): void
87 {
90
91 $video_cnt = count($this->video_sequence->getVideos());
92
93 $mcst_settings = \ilMediaCastSettings::_getInstance();
94
95 $factory = $this->ui->factory();
96 $renderer = $this->ui->renderer();
97
98 if ($video_cnt > 1) {
99 $back = $factory->button()->standard(
100 "<span class=\"glyphicon glyphicon-chevron-left \" aria-hidden=\"true\"></span>",
101 ""
102 )
103 ->withOnLoadCode(function ($id) {
104 return
105 "$(\"#$id\").click(function() { il.VideoWidget.previous(\"" . $this->video_wrapper_id . "\"); return false;});";
106 });
107 $next = $factory->button()->standard(
108 "<span class=\"glyphicon glyphicon-chevron-right \" aria-hidden=\"true\"></span>",
109 ""
110 )
111 ->withOnLoadCode(function ($id) {
112 return
113 "$(\"#$id\").click(function() { il.VideoWidget.next(\"" . $this->video_wrapper_id . "\"); return false;});";
114 });
115
116 $toolbar->addStickyItem($back);
117
118 $dd = $this->getDropdown();
119 if (!is_null($dd)) {
121 }
122
123 $toolbar->addStickyItem($next);
124 }
125
126 if ($video_cnt > 0 && $this->rss_link !== "") {
127 $f = $this->ui->factory();
128 $actions = [
129 $f->link()->standard(
130 $lng->txt("mcst_webfeed"),
131 $this->rss_link
132 )->withOpenInNewViewport(true)
133 ];
134 $toolbar->addComponent($f->dropdown()->standard($actions));
135 }
136 }
137
138 protected function getDropdown(): ?\ILIAS\UI\Component\Dropdown\Standard
139 {
140
141 $actions = [];
142 foreach ($this->video_sequence->getVideos() as $video) {
143 $actions[] = $this->ui->factory()->button()->shy(
144 $video->getTitle(),
145 "#"
146 )->withOnLoadCode(function (string $id) use ($video) {
147 return "document.getElementById('$id').addEventListener('click', () => {il.VideoPlaylist.toggleItem('mcst_playlist', '" . $video->getId() . "'); $('.ilToolbarStickyItem .dropdown.open').removeClass('open');});";
148 });
149 }
150 if (count($actions) > 0) {
151 return $this->ui->factory()->dropdown()->standard($actions);
152 }
153 return null;
154 }
155
156 public function renderSideColumn(): string
157 {
158 $mcst_settings = \ilMediaCastSettings::_getInstance();
159
161 $tpl = new \ilTemplate("tpl.video_cast_side.html", true, true, "components/ILIAS/MediaCast/Presentation");
162
163 $factory = $this->ui->factory();
164 $renderer = $this->ui->renderer();
165
166 // items
167 $items = [];
168 $has_items = false;
169
170 $panel_items = [];
171
172 foreach ($this->video_sequence->getVideos() as $video) {
173 $has_items = true;
174 $preview = new VideoPreviewGUI(
175 $video->getPreviewPic(),
176 "il.VideoPlaylist.toggleItem('mcst_playlist', '" . $video->getId() . "');",
177 $video->getPlayingTime()
178 );
179 $completed = false;
180
181 $re = \ilChangeEvent::_lookupReadEvents($video->getId(), $this->user->getId());
182 if (count($re) > 0) {
183 if ($re[0]["read_count"] > 0) {
184 $completed = true;
185 }
186 }
187
188 $b = $factory->button()->shy($video->getTitle(), "")->withOnLoadCode(function ($id) use ($video) {
189 return
190 "$(\"#$id\").click(function() { il.VideoPlaylist.toggleItem('mcst_playlist', '" . $video->getId() . "'); return false;});";
191 });
192
193 $this->ctrl->setParameterByClass(
194 \ilObjMediaCastGUI::class,
195 "mob_id",
196 $video->getId()
197 );
198 $download_url = "";
199 if ($video->isLocal() && $this->media_cast->getDownloadable()) {
200 $this->ctrl->setParameterByClass("ilobjmediacastgui", "purpose", "Standard");
201 $this->ctrl->setParameterByClass("ilobjmediacastgui", "item_id", $video->getNewsId());
202 $download_url = $this->ctrl->getLinkTargetByClass("ilobjmediacastgui", "downloadItem");
203 }
204
205 $items[] = [
206 "id" => $video->getId(),
207 "resource" => $video->getResource(),
208 "preview" => $preview->render(),
209 "preview_pic" => $video->getPreviewPic(),
210 "title" => $video->getTitle(),
211 "linked_title" => $renderer->renderAsync($b),
212 "mime" => $video->getMime(),
213 "poster" => $video->getPreviewPic(),
214 "description" => nl2br($video->getDescription()),
215 "completed" => $completed,
216 "duration" => $video->getDuration(),
217 "renderUrl" => $this->ctrl->getLinkTargetByClass(
218 \ilObjMediaCastGUI::class,
219 "renderVideo"
220 ),
221 "download_url" => $download_url
222 ];
223 }
224
225 $panel = $factory->panel()->secondary()->listing(
226 "Videos",
227 []
228 );
229 $panel_html = $renderer->render($panel);
230 $panel_html = str_replace(
231 '<div class="panel-body">',
232 '<div class="panel-body"><div id="mcst_playlist"></div>',
233 $panel_html,
234 );
235
236 $tpl->setVariable("PANEL", $panel_html);
237 // previous items / next items links
238 if ($has_items) {
240 "PREV",
241 $renderer->render(
242 $factory->button()->standard($lng->txt("mcst_prev_items"), "")->withOnLoadCode(
243 function ($id) {
244 return
245 "$(\"#$id\").click(function() { il.VideoPlaylist.previousItems('mcst_playlist'); return false;});";
246 }
247 )
248 )
249 );
251 "NEXT",
252 $renderer->render(
253 $factory->button()->standard($lng->txt("mcst_next_items"), "")->withOnLoadCode(
254 function ($id) {
255 return
256 "$(\"#$id\").click(function() { il.VideoPlaylist.nextItems('mcst_playlist'); return false;});";
257 }
258 )
259 )
260 );
261
262 $item_tpl = new \ilTemplate("tpl.playlist_item.html", true, true, "components/ILIAS/MediaCast/Video");
263 $item_tpl->setVariable("TITLE", " ");
264 $item_content = str_replace(["\n", "\r"], "", $item_tpl->get());
265
266 $item = $factory->item()->standard("#video-title#")
267 ->withLeadImage(
268 $factory->image()->responsive("#img-src#", "#img-alt#")
269 );
270
271 $item_content = $renderer->render($item);
272 $item_content = str_replace(["\n", "\r"], "", $item_content);
273
274 $init_videos = $this->media_cast->getNumberInitialVideos() > 0
275 ? $this->media_cast->getNumberInitialVideos()
276 : 1;
277 $this->tpl->addOnLoadCode(
278 "il.VideoPlaylist.init('mcst_playlist', 'mcst_video', " . json_encode(
279 $items
280 ) . ", '$item_content', false, " .
281 (int) $init_videos . ", '" . $this->completed_callback . "', '', " . ((int) $mcst_settings->getVideoCompletionThreshold()) . ");"
282 );
283
284 if (count($items) === 1) {
285 return " ";
286 }
287
288 return $tpl->get();
289 }
290
291 return "";
292 }
293
297 public function render(): string
298 {
299 // this is current only to include the resize mechanism when
300 // the main menu is changed, so that the player is resized, too
301 //\ilMediaPlayerGUI::initJavascript();
302 $tpl = new \ilTemplate("tpl.video_cast_layout.html", true, true, "components/ILIAS/MediaCast/Presentation");
303 $side_column = $this->renderSideColumn();
304
305
306 if ($side_column != "") {
307 $tpl->setCurrentBlock("with_side_column");
308 $tpl->setVariable("SIDE", $side_column);
309 } else {
310 $tpl->setCurrentBlock("video_only");
311 }
312 $tpl->setVariable("MAIN", $this->renderMainColumn());
313 $tpl->parseCurrentBlock();
314 return $tpl->get();
315 }
316
317 public function show(): void
318 {
319 if (is_object($this->tpl)) {
320 $this->renderToolbar();
321 $this->tpl->setContent(
322 $this->renderMainColumn() .
324 );
325 $this->tpl->setRightContent($this->renderSideColumn());
326 }
327 }
328
329 public function renderCommentsContainer()
330 {
331 if ($this->mc_manager->commentsActive()) {
332 $target = $this->ctrl->getLinkTargetByClass(
333 \ilObjMediaCastGUI::class,
334 "showComments"
335 );
336 return "<div data-mcst-comments='$target'></div>";
337 }
338 }
339}
$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="")
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