ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.VideoViewGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
25 
30 {
31  protected string $rss_link;
32  protected \ilToolbarGUI $toolbar;
33  protected \ilGlobalTemplateInterface $main_tpl;
34  protected \ilObjMediaCast $media_cast;
35  protected \ilGlobalTemplateInterface $tpl;
36  protected \ILIAS\DI\UIServices $ui;
37  protected \ilLanguage $lng;
38  protected \ilObjUser $user;
39  protected string $completed_callback = "";
40  protected string $autoplay_callback = "";
42  protected string $video_wrapper_id = "mcst_video";
43 
44  public function __construct(
45  \ilObjMediaCast $obj,
46  \ilGlobalTemplateInterface $tpl = null,
47  string $rss_link = ""
48  ) {
49  global $DIC;
50 
51  $this->ui = $DIC->ui();
52  $this->rss_link = $rss_link;
53  $this->lng = $DIC->language();
54  $this->media_cast = $obj;
55  $this->tpl = $tpl;
56  $this->video_sequence = new VideoSequence($this->media_cast);
57  $this->user = $DIC->user();
58  $this->main_tpl = $DIC->ui()->mainTemplate();
59  $this->toolbar = $DIC->toolbar();
60  }
61 
62  public function setCompletedCallback(string $completed_callback): void
63  {
64  $this->completed_callback = $completed_callback;
65  }
66 
67  public function setAutoplayCallback(string $autoplay_callback): void
68  {
69  $this->autoplay_callback = $autoplay_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  {
88  $toolbar = $this->toolbar;
89  $lng = $this->lng;
90 
91  $video_cnt = count($this->video_sequence->getVideos());
92 
93  $mcst_settings = \ilMediaCastSettings::_getInstance();
94 
95  $autoplay = $this->getAutoplay();
96 
97  $factory = $this->ui->factory();
98  $renderer = $this->ui->renderer();
99 
100  if ($video_cnt > 1) {
101  $back = $factory->button()->standard(
102  "<span class=\"glyphicon glyphicon-chevron-left \" aria-hidden=\"true\"></span>",
103  ""
104  )
105  ->withOnLoadCode(function ($id) {
106  return
107  "$(\"#$id\").click(function() { il.VideoWidget.previous(\"" . $this->video_wrapper_id . "\"); return false;});";
108  });
109  $next = $factory->button()->standard(
110  "<span class=\"glyphicon glyphicon-chevron-right \" aria-hidden=\"true\"></span>",
111  ""
112  )
113  ->withOnLoadCode(function ($id) {
114  return
115  "$(\"#$id\").click(function() { il.VideoWidget.next(\"" . $this->video_wrapper_id . "\"); return false;});";
116  });
117 
118  $toolbar->addComponent($back);
119  $toolbar->addComponent($next);
120  }
121 
122  // autoplay
123  if ($this->media_cast->getAutoplayMode() !== \ilObjMediaCast::AUTOPLAY_NO && $video_cnt > 1) {
124  $toolbar->addSeparator();
125  $s = new SignalGenerator();
126  $autoplay_on = $s->create();
127  $autoplay_off = $s->create();
128  $button = $factory->button()->toggle($lng->txt("mcst_autoplay"), $autoplay_on, $autoplay_off, $autoplay);
129  $toolbar->addComponent($button);
130  $this->main_tpl->addOnLoadCode("
131  $(document).on('" . $autoplay_on . "', function (event, signalData) {
132  il.VideoPlaylist.autoplay('mcst_playlist', true);
133  });
134  $(document).on('" . $autoplay_off . "', function (event, signalData) {
135  il.VideoPlaylist.autoplay('mcst_playlist', false);
136  });");
137  }
138 
139  if ($video_cnt > 0 && $this->rss_link !== "") {
140  $f = $this->ui->factory();
141  $actions = [
142  $f->link()->standard(
143  $lng->txt("mcst_webfeed"),
145  )->withOpenInNewViewport(true)
146  ];
147  $toolbar->addComponent($f->dropdown()->standard($actions));
148  }
149  }
150 
151  protected function getAutoplay(): bool
152  {
153  $video_cnt = count($this->video_sequence->getVideos());
154  if ($video_cnt <= 1) {
155  return false;
156  }
157  $autoplay = ($this->user->existsPref("mcst_autoplay"))
158  ? (bool) $this->user->getPref("mcst_autoplay")
159  : ($this->media_cast->getAutoplayMode() == \ilObjMediaCast::AUTOPLAY_ACT);
160  if ($this->media_cast->getAutoplayMode() == \ilObjMediaCast::AUTOPLAY_NO) {
161  $autoplay = false;
162  }
163  return $autoplay;
164  }
165 
166  public function renderSideColumn(): string
167  {
168  $mcst_settings = \ilMediaCastSettings::_getInstance();
169 
170  $autoplay = $this->getAutoplay();
171 
172  $lng = $this->lng;
173  $tpl = new \ilTemplate("tpl.video_cast_side.html", true, true, "Modules/MediaCast/Presentation");
174 
175  $factory = $this->ui->factory();
176  $renderer = $this->ui->renderer();
177 
178  // items
179  $items = [];
180  $has_items = false;
181 
182  $panel_items = [];
183 
184  foreach ($this->video_sequence->getVideos() as $video) {
185  $has_items = true;
187  $video->getPreviewPic(),
188  "il.VideoPlaylist.toggleItem('mcst_playlist', '" . $video->getId() . "');",
189  $video->getPlayingTime()
190  );
191  $completed = false;
192 
193  $re = \ilChangeEvent::_lookupReadEvents($video->getId(), $this->user->getId());
194  if (count($re) > 0) {
195  if ($re[0]["read_count"] > 0) {
196  $completed = true;
197  }
198  }
199 
200  $b = $factory->button()->shy($video->getTitle(), "")->withOnLoadCode(function ($id) use ($video) {
201  return
202  "$(\"#$id\").click(function() { il.VideoPlaylist.toggleItem('mcst_playlist', '" . $video->getId() . "'); return false;});";
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  ];
218  }
219 
220  $panel = $factory->panel()->secondary()->listing(
221  "Videos",
222  []
223  );
224  $panel_html = $renderer->render($panel);
225  $panel_html = str_replace(
226  '<div class="panel-body">',
227  '<div class="panel-body"><div id="mcst_playlist"></div>',
228  $panel_html,
229  );
230 
231  $tpl->setVariable("PANEL", $panel_html);
232  // previous items / next items links
233  if ($has_items) {
234  $tpl->setVariable(
235  "PREV",
236  $renderer->render(
237  $factory->button()->standard($lng->txt("mcst_prev_items"), "")->withOnLoadCode(
238  function ($id) {
239  return
240  "$(\"#$id\").click(function() { il.VideoPlaylist.previousItems('mcst_playlist'); return false;});";
241  }
242  )
243  )
244  );
245  $tpl->setVariable(
246  "NEXT",
247  $renderer->render(
248  $factory->button()->standard($lng->txt("mcst_next_items"), "")->withOnLoadCode(
249  function ($id) {
250  return
251  "$(\"#$id\").click(function() { il.VideoPlaylist.nextItems('mcst_playlist'); return false;});";
252  }
253  )
254  )
255  );
256 
257  $item_tpl = new \ilTemplate("tpl.playlist_item.html", true, true, "Modules/MediaCast/Video");
258  $item_tpl->setVariable("TITLE", " ");
259  $item_content = str_replace("\n", "", $item_tpl->get());
260 
261  $item = $factory->item()->standard("#video-title#")
262  ->withLeadImage(
263  $factory->image()->responsive("#img-src#", "#img-alt#")
264  );
265 
266  $item_content = $renderer->render($item);
267  $item_content = str_replace("\n", "", $item_content);
268 
269  $init_videos = $this->media_cast->getNumberInitialVideos() > 0
270  ? $this->media_cast->getNumberInitialVideos()
271  : 1;
272 
273  $this->tpl->addOnLoadCode(
274  "il.VideoPlaylist.init('mcst_playlist', 'mcst_video', " . json_encode(
275  $items
276  ) . ", '$item_content', " . ($autoplay ? "true" : "false") . ", " .
277  (int) $init_videos . ", '" . $this->completed_callback . "', '" . $this->autoplay_callback . "', " . ((int) $mcst_settings->getVideoCompletionThreshold()) . ");"
278  );
279 
280  if (count($items) === 1) {
281  return " ";
282  }
283 
284  return $tpl->get();
285  }
286 
287  return "";
288  }
289 
293  public function render(): string
294  {
295  // this is current only to include the resize mechanism when
296  // the main menu is changed, so that the player is resized, too
298  $tpl = new \ilTemplate("tpl.video_cast_layout.html", true, true, "Modules/MediaCast/Presentation");
299  $side_column = $this->renderSideColumn();
300 
301 
302  if ($side_column != "") {
303  $tpl->setCurrentBlock("with_side_column");
304  $tpl->setVariable("SIDE", $side_column);
305  } else {
306  $tpl->setCurrentBlock("video_only");
307  }
308  $tpl->setVariable("MAIN", $this->renderMainColumn());
309  $tpl->parseCurrentBlock();
310  return $tpl->get();
311  }
312 
313  public function show(): void
314  {
315  if (is_object($this->tpl)) {
316  $this->renderToolbar();
317  $this->tpl->setContent($this->renderMainColumn());
318  $this->tpl->setRightContent($this->renderSideColumn());
319  }
320  }
321 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(isset($_FILES['img_file']) &&is_array($_FILES['img_file'])) $panel
Definition: imgupload.php:198
static initJavascript(ilGlobalTemplateInterface $a_tpl=null)
global $DIC
Definition: feed.php:28
$preview
Definition: imgupload.php:81
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupReadEvents($obj_id, $usr_id=null)
Reads all read events which occured on the object.
setCompletedCallback(string $completed_callback)
setAutoplayCallback(string $autoplay_callback)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(\ilObjMediaCast $obj, \ilGlobalTemplateInterface $tpl=null, string $rss_link="")
$factory
Definition: metadata.php:75