ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjMediaCastGUI.php
Go to the documentation of this file.
1 <?php
2 
25 
34 {
35  protected \ILIAS\MediaCast\MediaCastManager $mc_manager;
39  protected ilTabsGUI $tabs;
40  protected ilLogger $log;
41  protected ilHelpGUI $help;
42  private array $additionalPurposes = [];
43  private array $purposeSuffixes = [];
44  private array $mimeTypes = [];
45  protected FileSystem $filesystem;
46 
50  public function __construct(
51  $a_data,
52  int $a_id,
53  bool $a_call_by_reference,
54  bool $a_prepare_output = true
55  ) {
56  global $DIC;
57 
58  $this->ctrl = $DIC->ctrl();
59  $this->lng = $DIC->language();
60  $this->user = $DIC->user();
61  $this->tabs = $DIC->tabs();
62  $this->tpl = $DIC["tpl"];
63  $this->access = $DIC->access();
64  $this->toolbar = $DIC->toolbar();
65  $this->filesystem = $DIC->filesystem()->web();
66  $this->log = $DIC["ilLog"];
67  $this->help = $DIC["ilHelp"];
68  $this->locator = $DIC["ilLocator"];
69  $ilCtrl = $DIC->ctrl();
70  $lng = $DIC->language();
71  $this->mc_request = $DIC->mediaCast()
72  ->internal()
73  ->gui()
74  ->standardRequest();
75 
76  $this->type = "mcst";
77  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
78  $lng->loadLanguageModule("mcst");
79  $lng->loadLanguageModule("news");
80  $lng->loadLanguageModule("rep");
81 
82  $ilCtrl->saveParameter($this, "item_id");
83 
85  $this->purposeSuffixes = $settings->getPurposeSuffixes();
86  $this->mimeTypes = array();
87  $mime_types = $settings->getMimeTypes();
88  foreach ($mime_types as $mt) {
89  $this->mimeTypes[$mt] = $mt;
90  }
91 
92  foreach (MimeType::getExt2MimeMap() as $mt) {
93  // $this->mimeTypes[$mt] = $mt;
94  }
95  asort($this->mimeTypes);
96 
97  $this->mc_manager = $DIC->mediaCast()->internal()
98  ->domain()->mediaCast();
99  }
100 
101  public function executeCommand(): void
102  {
104  $ilTabs = $this->tabs;
105 
106  $next_class = $this->ctrl->getNextClass($this);
107  $cmd = $this->ctrl->getCmd();
108  $this->prepareOutput();
109 
110  switch ($next_class) {
111  case "ilmediacreationgui":
112  $this->ctrl->setReturn($this, "listItems");
113  $ilTabs->activateTab("content");
114  $this->addContentSubTabs("manage");
115  $med_type = [];
116  switch ($this->object->getViewMode()) {
118  $med_type = [ilMediaCreationGUI::TYPE_VIDEO];
119  break;
121  $med_type = [ilMediaCreationGUI::TYPE_IMAGE];
122  break;
124  $med_type = [ilMediaCreationGUI::TYPE_AUDIO];
125  break;
126  }
127  $creation = new ilMediaCreationGUI($med_type, function ($mob_id) {
128  $this->afterUpload($mob_id);
129  }, function ($mob_id, $long_desc) {
130  $this->afterUrlSaving($mob_id, $long_desc);
131  }, function ($mob_ids) {
132  $this->afterPoolInsert($mob_ids);
133  }, function ($mob_id) {
134  $this->finishSingleUpload($mob_id);
135  }, function ($mob_id) {
136  $this->onMobUpdate($mob_id);
137  });
138  /*
139  $creation->setAllSuffixes($this->purposeSuffixes["Standard"]);
140  $creation->setAllMimeTypes($this->mimeTypes);*/
141  $this->ctrl->forwardCommand($creation);
142  break;
143 
144  case "ilinfoscreengui":
145  if (!$this->checkPermissionBool("read")) {
146  $this->checkPermission("visible");
147  }
148  $this->infoScreen(); // forwards command
149  break;
150 
151  case "ilexportgui":
152  // $this->prepareOutput();
153  $ilTabs->activateTab("export");
154  $exp_gui = new ilExportGUI($this);
155  $exp_gui->addFormat("xml");
156  $ret = $this->ctrl->forwardCommand($exp_gui);
157  // $this->tpl->show();
158  break;
159 
160  case 'ilpermissiongui':
161  $ilTabs->activateTab("id_permissions");
162  $perm_gui = new ilPermissionGUI($this);
163  $ret = $this->ctrl->forwardCommand($perm_gui);
164  break;
165 
166  case 'ilobjectcopygui':
167  $cp = new ilObjectCopyGUI($this);
168  $cp->setType('mcst');
169  $this->ctrl->forwardCommand($cp);
170  break;
171 
172  case "ilcommonactiondispatchergui":
174  $this->ctrl->forwardCommand($gui);
175  break;
176 
177  case "illearningprogressgui":
178  $ilTabs->activateTab('learning_progress');
179  $new_gui = new ilLearningProgressGUI(
181  $this->object->getRefId(),
182  $this->mc_request->getUserId() ?: $ilUser->getId()
183  );
184  $this->ctrl->forwardCommand($new_gui);
185  $this->tabs_gui->setTabActive('learning_progress');
186  break;
187 
188  case "mcstimagegallerygui":
189  $view = new \McstImageGalleryGUI($this->object, $this->tpl, $this->getFeedLink());
190  $this->ctrl->forwardCommand($view);
191  break;
192 
193  case "mcstpodcastgui":
194  $view = new \McstPodcastGUI($this->object, $this->tpl, $this->getFeedLink());
195  $this->ctrl->forwardCommand($view);
196  break;
197 
198  default:
199  if (!$cmd) {
200  $cmd = "infoScreen";
201  }
202  $cmd .= "Object";
203  if ($cmd != "infoScreenObject") {
204  $this->checkPermission("read");
205  } else {
206  $this->checkPermission("visible");
207  }
208  $this->$cmd();
209 
210  break;
211  }
212  $this->addHeaderAction();
213  }
214 
215  protected function initCreationForms(string $new_type): array
216  {
217  $forms = array(self::CFORM_NEW => $this->initCreateForm($new_type),
218  self::CFORM_IMPORT => $this->initImportForm($new_type),
219  self::CFORM_CLONE => $this->fillCloneTemplate(null, $new_type));
220 
221  return $forms;
222  }
223 
224  protected function afterSave(ilObject $new_object): void
225  {
226  // always send a message
227  $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
228  ilUtil::redirect("ilias.php?baseClass=ilMediaCastHandlerGUI&ref_id=" . $new_object->getRefId() . "&cmd=editSettings");
229  }
230 
231  public function listItemsObject(bool $a_presentation_mode = false): void
232  {
233  $tpl = $this->tpl;
234  $lng = $this->lng;
235  $ilAccess = $this->access;
236  $ilToolbar = $this->toolbar;
237 
238  $this->checkPermission("read");
239 
240  if ($a_presentation_mode) {
241  $this->tpl->setOnScreenMessage('info', $this->lng->txt("mcst_view_abandoned"));
242  return;
243  }
244 
245  if ($a_presentation_mode) {
246  $this->addContentSubTabs("content");
247  } else {
248  $this->addContentSubTabs("manage");
249  }
250 
251  $med_items = $this->object->getSortedItemsArray();
252 
253  if ($a_presentation_mode) {
254  $table_gui = new ilMediaCastTableGUI($this, "showContent", false, true);
255  } else {
256  $table_gui = new ilMediaCastTableGUI($this, "listItems");
257  }
258 
259  $table_gui->setData($med_items);
260 
261  if ($ilAccess->checkAccess("write", "", $this->requested_ref_id) && !$a_presentation_mode) {
262  if (in_array($this->object->getViewMode(), [
266  ], true)) {
267  $ilToolbar->addButton($lng->txt("add"), $this->ctrl->getLinkTargetByClass("ilMediaCreationGUI", ""));
268  } else {
269  $ilToolbar->addButton($lng->txt("add"), $this->ctrl->getLinkTarget($this, "addCastItem"));
270  }
271 
272  $table_gui->addMultiCommand("confirmDeletionItems", $lng->txt("delete"));
273  $table_gui->setSelectAllCheckbox("item_id");
274  }
275  $tpl->setContent($table_gui->getHTML());
276  }
277 
278  public function getFeedLink(): string
279  {
280  $public_feed = ilBlockSetting::_lookup(
281  "news",
282  "public_feed",
283  0,
284  $this->object->getId()
285  );
286  $url = "";
287  // rss icon/link
288  if ($public_feed) {
289  $news_set = new ilSetting("news");
290  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
291  if ($enable_internal_rss) {
292  $url = ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&" . "ref_id=" . $this->requested_ref_id;
293  }
294  }
295  return $url;
296  }
297 
301  public function addCastItemObject(): void
302  {
303  $tpl = $this->tpl;
304 
305  $this->checkPermission("write");
306 
307  $this->initAddCastItemForm();
308  $tpl->setContent($this->form_gui->getHTML());
309  }
310 
311  public function editCastItemObject(): void
312  {
313  $tpl = $this->tpl;
314  $ilToolbar = $this->toolbar;
315  $ilCtrl = $this->ctrl;
316 
317  $this->checkPermission("write");
318 
319  // conversion toolbar
320  if (ilFFmpeg::enabled()) {
321  $this->mcst_item = new ilNewsItem(
322  $this->mc_request->getItemId()
323  );
324  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
325 
326  $conv_cnt = 0;
327  // we had other purposes as source as well, but
328  // currently only "Standard" is implemented in the convertFile method
329  $p = "Standard";
330  $med = $mob->getMediaItem($p);
331  if (is_object($med)) {
332  if (ilFFmpeg::supportsImageExtraction($med->getFormat())) {
333  // second
334  $ni = new ilTextInputGUI($this->lng->txt("mcst_second"), "sec");
335  $ni->setMaxLength(4);
336  $ni->setSize(4);
337  $ni->setValue(1);
338  $ilToolbar->addInputItem($ni, true);
339 
340  $ilToolbar->addFormButton($this->lng->txt("mcst_extract_preview_image"), "extractPreviewImage");
341  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
342  }
343  }
344  }
345 
346  $this->initAddCastItemForm("edit");
347  $this->getCastItemValues();
348  $tpl->setContent($this->form_gui->getHTML());
349  }
350 
351  public function finishSingleUpload(int $mob_id): void
352  {
353  foreach ($this->object->getSortedItemsArray() as $item) {
354  if ($mob_id == $item["mob_id"]) {
355  $this->ctrl->setParameter($this, "item_id", $item["id"]);
356  $this->ctrl->redirect($this, "editCastItem");
357  }
358  }
359  $this->ctrl->redirect($this, "listItems");
360  }
361 
362  protected function onMobUpdate(int $mob_id): void
363  {
364  foreach ($this->object->getSortedItemsArray() as $item) {
365  if ($mob_id == $item["mob_id"]) {
366  $mob = new ilObjMediaObject($item["mob_id"]);
367  $mc_item = new ilNewsItem($item["id"]);
368  $mc_item->setTitle($mob->getTitle());
369  $mc_item->setContent($mob->getLongDescription());
370  $mc_item->update();
371  }
372  }
373  }
374 
375  public function initAddCastItemForm(string $a_mode = "create"): void
376  {
377  $lng = $this->lng;
378  $ilCtrl = $this->ctrl;
379  $ilTabs = $this->tabs;
380 
381  $this->checkPermission("write");
382  $ilTabs->activateTab("edit_content");
383 
384  $lng->loadLanguageModule("mcst");
385 
386  $news_set = new ilSetting("news");
387  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
388 
389  $this->form_gui = new ilPropertyFormGUI();
390  $this->form_gui->setMultipart(true);
391 
392  // Property Title
393  $text_input = new ilTextInputGUI($lng->txt("title"), "title");
394  $text_input->setMaxLength(200);
395  $this->form_gui->addItem($text_input);
396 
397  // Property Content
398  $text_area = new ilTextAreaInputGUI($lng->txt("description"), "description");
399  $text_area->setRequired(false);
400  $this->form_gui->addItem($text_area);
401 
402  // Property Visibility
403  if ($enable_internal_rss) {
404  $radio_group = new ilRadioGroupInputGUI($lng->txt("access_scope"), "visibility");
405  $radio_option = new ilRadioOption($lng->txt("access_users"), "users");
406  $radio_group->addOption($radio_option);
407  $radio_option = new ilRadioOption($lng->txt("access_public"), "public");
408  $radio_group->addOption($radio_option);
409  $radio_group->setInfo($lng->txt("mcst_visibility_info"));
410  $radio_group->setRequired(true);
411  $radio_group->setValue($this->object->getDefaultAccess() == 0 ? "users" : "public");
412  $this->form_gui->addItem($radio_group);
413  }
414 
415  // Duration
416  $dur = new ilDurationInputGUI($lng->txt("mcst_duration"), "duration");
417  $dur->setInfo($lng->txt("mcst_duration_info"));
418  $dur->setShowDays(false);
419  $dur->setShowHours(true);
420  $dur->setShowSeconds(true);
421  $this->form_gui->addItem($dur);
422 
423  foreach (ilObjMediaCast::$purposes as $purpose) {
424  if ($purpose == "VideoAlternative" &&
425  $a_mode == "create") {
426  continue;
427  }
428 
429  $section = new ilFormSectionHeaderGUI();
430  $section->setTitle($lng->txt("mcst_" . strtolower($purpose) . "_title"));
431  $this->form_gui->addItem($section);
432  if ($a_mode != "create") {
433  $value = new ilHiddenInputGUI("value_" . $purpose);
434  $label = new ilNonEditableValueGUI($lng->txt("value"));
435  $label->setPostVar("label_value_" . $purpose);
436  $label->setInfo($lng->txt("mcst_current_value_info"));
437  $this->form_gui->addItem($label);
438  $this->form_gui->addItem($value);
439  }
440  $file = new ilFileInputGUI($lng->txt("file"), "file_" . $purpose);
441  $file->setSuffixes($this->mc_manager->getSuffixesForViewMode(
442  $this->object->getViewMode()
443  ));
444  $this->form_gui->addItem($file);
445  $text_input = new ilRegExpInputGUI($lng->txt("url"), "url_" . $purpose);
446  $text_input->setPattern("/https?\:\/\/.+/i");
447  $text_input->setInfo($lng->txt("mcst_reference_info"));
448  $this->form_gui->addItem($text_input);
449  if ($purpose != "Standard") {
450  $clearCheckBox = new ilCheckboxInputGUI();
451  $clearCheckBox->setPostVar("delete_" . $purpose);
452  $clearCheckBox->setTitle($lng->txt("mcst_clear_purpose_title"));
453  $this->form_gui->addItem($clearCheckBox);
454  } else {
455 
456  //
457  $ne = new ilNonEditableValueGUI($lng->txt("mcst_mimetype"), "mimetype_" . $purpose);
458  $this->form_gui->addItem($ne);
459 
460  // mime type selection
461  /*
462  $mimeTypeSelection = new ilSelectInputGUI();
463  $mimeTypeSelection->setPostVar("mimetype_" . $purpose);
464  $mimeTypeSelection->setTitle($lng->txt("mcst_mimetype"));
465  $mimeTypeSelection->setInfo($lng->txt("mcst_mimetype_info"));
466  $options = array("" => $lng->txt("mcst_automatic_detection"));
467  $options = array_merge($options, $this->mimeTypes);
468  $mimeTypeSelection->setOptions($options);
469  $this->form_gui->addItem($mimeTypeSelection);*/
470 
471  // preview picure
472  $pp = new ilImageFileInputGUI($lng->txt("mcst_preview_picture"), "preview_pic");
473  $pp->setSuffixes(array("png", "jpeg", "jpg"));
474  $pp->setInfo($lng->txt("mcst_preview_picture_info") . " mp4, mp3, png, jp(e)g, gif");
475  $this->form_gui->addItem($pp);
476  }
477  }
478 
479  // save/cancel button
480  if ($a_mode == "create") {
481  $this->form_gui->setTitle($lng->txt("mcst_add_new_item"));
482  $this->form_gui->addCommandButton("saveCastItem", $lng->txt("save"));
483  } else {
484  $this->form_gui->setTitle($lng->txt("mcst_edit_item"));
485  $this->form_gui->addCommandButton("updateCastItem", $lng->txt("save"));
486  }
487  $this->form_gui->addCommandButton("listItems", $lng->txt("cancel"));
488  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveCastItem"));
489  }
490 
494  public function getCastItemValues(): void
495  {
496  $lng = $this->lng;
497 
498  // get mob
499  $this->mcst_item = new ilNewsItem(
500  $this->mc_request->getItemId()
501  );
502  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
503 
504  // preview
505  $ppic = $mob->getVideoPreviewPic();
506  if ($ppic != "") {
507  $i = $this->form_gui->getItemByPostVar("preview_pic");
508  $i->setImage($ppic);
509  }
510 
511 
512  $values = array();
513  $mediaItems = $this->getMediaItems(
514  $this->mc_request->getItemId()
515  );
516  if (count($mediaItems) > 0) {
517  foreach ($mediaItems as $med) {
518  if (!isset($values["title"])) {
519  // first item, so set title, description, ...
520  $values["title"] = $this->mcst_item->getTitle();
521  $values["description"] = $this->mcst_item->getContent();
522  $values["visibility"] = $this->mcst_item->getVisibility();
523  $length = explode(":", $this->mcst_item->getPlaytime());
524  $values["duration"] = array("hh" => $length[0], "mm" => $length[1], "ss" => $length[2]);
525  }
526 
527  $values["value_" . $med->getPurpose()] = (strlen($med->getLocation()) > 100) ? "..." . substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
528  $values["label_value_" . $med->getPurpose()] = (strlen($med->getLocation()) > 100) ? "..." . substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
529  $values["mimetype_" . $med->getPurpose()] = $med->getFormat();
530  }
531  }
532  foreach (ilObjMediaCast::$purposes as $purpose) {
533  if (!isset($values["value_" . $purpose])) {
534  $values["label_value_" . $purpose] = $lng->txt("none");
535  $values["value_" . $purpose] = $lng->txt("none");
536  }
537  }
538  $this->form_gui->setValuesByArray($values);
539  }
540 
541  public function saveCastItemObject(): void
542  {
543  return;
544  $tpl = $this->tpl;
545  $ilCtrl = $this->ctrl;
547  $lng = $this->lng;
548  $ilTabs = $this->tabs;
549 
550  $this->checkPermission("write");
551  $ilTabs->activateTab("edit_content");
552 
553  $this->initAddCastItemForm();
554 
555  if (!$this->form_gui->checkInput() ||
556  ($this->form_gui->getInput("url_Standard") == "" && !$_FILES['file_Standard']['tmp_name'])) {
557  $this->tpl->setOnScreenMessage('failure', $lng->txt("mcst_input_either_file_or_url"));
558  $this->populateFormFromPost();
559  } else {
560  // create dummy object in db (we need an id)
561  $mob = new ilObjMediaObject();
562  $mob->create();
563 
564  //handle standard purpose
565  $file = $this->createMediaItemForPurpose($mob, "Standard");
566 
567  // set title and description
568  // set title to basename of file if left empty
569  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
570  $description = $this->form_gui->getInput("description");
571  $mob->setTitle($title);
572  $mob->setDescription($description);
573 
574  // save preview pic
575  $prevpic = $this->form_gui->getInput("preview_pic");
576  if ($prevpic["size"] > 0) {
577  $mob->uploadVideoPreviewPic($prevpic);
578  }
579 
580  // determine duration for standard purpose
581  $duration = $this->getDuration($file);
582 
583  // handle other purposes
584  foreach ($this->additionalPurposes as $purpose) {
585  // check if some purpose has been uploaded
586  $file_gui = $this->form_gui->getInput("file_" . $purpose);
587  $url_gui = $this->form_gui->getInput("url_" . $purpose);
588  if ($url_gui || $file_gui["size"] > 0) {
589  $this->createMediaItemForPurpose($mob, $purpose);
590  }
591  }
592 
593  $mob->update();
594 
595  if ($prevpic["size"] == 0) {
596  // re-read media object
597  $mob = new ilObjMediaObject($mob->getId());
598  $mob->generatePreviewPic(320, 240);
599  }
600 
601  //
602  // @todo: save usage
603  //
604 
605  $news_set = new ilSetting("news");
606  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
607 
608  // create new media cast item
609  $mc_item = new ilNewsItem();
610  $mc_item->setMobId($mob->getId());
611  $mc_item->setContentType(NEWS_AUDIO);
612  $mc_item->setContextObjId($this->object->getId());
613  $mc_item->setContextObjType($this->object->getType());
614  $mc_item->setUserId($ilUser->getId());
615  $mc_item->setPlaytime($duration);
616  $mc_item->setTitle($title);
617  $mc_item->setContent($description);
618  $mc_item->setLimitation(false);
619  if ($enable_internal_rss) {
620  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
621  } else {
622  $mc_item->setVisibility("users");
623  }
624  $mc_item->create();
625 
626  $ilCtrl->redirect($this, "listItems");
627  }
628  }
629 
630  private function getDuration(ilMediaItem $media_item): string
631  {
632  $duration = isset($this->form_gui)
633  ? $this->form_gui->getInput("duration")
634  : array("hh" => 0, "mm" => 0, "ss" => 0);
635 
636  $duration_str = str_pad($duration["hh"], 2, "0", STR_PAD_LEFT) . ":" .
637  str_pad($duration["mm"], 2, "0", STR_PAD_LEFT) . ":" .
638  str_pad($duration["ss"], 2, "0", STR_PAD_LEFT);
639 
640  if ($duration["hh"] == 0 && $duration["mm"] == 0 && $duration["ss"] == 0) {
641  $media_item->determineDuration();
642  $d = $media_item->getDuration();
643  if ($d > 0) {
644  $duration_str = $this->object->getPlaytimeForSeconds($d);
645  }
646  }
647 
648  return $duration_str;
649  }
650 
654  private function createMediaItemForPurpose(
655  ilObjMediaObject $mob,
656  string $purpose
657  ): string {
658  $mediaItem = new ilMediaItem();
659  $mob->addMediaItem($mediaItem);
660  $mediaItem->setPurpose($purpose);
661  return $this->updateMediaItem($mob, $mediaItem);
662  }
663 
671  private function updateMediaItem(
672  ilObjMediaObject $mob,
673  ilMediaItem $mediaItem
674  ): string {
675  $locationType = "";
676  $location = "";
677  $file = "";
678  $purpose = $mediaItem->getPurpose();
679  $locationType = $mediaItem->getLocationType();
680  $url_gui = $this->form_gui->getInput("url_" . $purpose);
681  $file_gui = $this->form_gui->getInput("file_" . $purpose);
682  if ($url_gui) {
683  // http
684  $file = $this->form_gui->getInput("url_" . $purpose);
685  $title = basename($file);
686  $location = $this->form_gui->getInput("url_" . $purpose);
687  $locationType = "Reference";
688  } elseif ($file_gui["size"] > 0) {
689  // lokal
690  // determine and create mob directory, move uploaded file to directory
691  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
692  if (!is_dir($mob_dir)) {
693  $mob->createDirectory();
694  } else {
695  $dir = LegacyPathHelper::createRelativePath($mob_dir);
696  $old_files = $this->filesystem->finder()->in([$dir])->exclude([$dir . '/mob_vpreview.png'])->files();
697  foreach ($old_files as $file) {
698  $this->filesystem->delete($file->getPath());
699  }
700  }
701 
702  $file_name = ilFileUtils::getASCIIFilename($_FILES['file_' . $purpose]['name']);
703  $file_name = str_replace(" ", "_", $file_name);
704 
705  $file = $mob_dir . "/" . $file_name;
706  $title = $file_name;
707  $locationType = "LocalFile";
708  $location = $title;
709  ilFileUtils::moveUploadedFile($_FILES['file_' . $purpose]['tmp_name'], $file_name, $file);
711  }
712 
713  // check if not automatic mimetype detection
714  $format = ilObjMediaObject::getMimeType($mediaItem->getLocation(), ($locationType === "Reference"));
715  $mediaItem->setFormat($format);
716 
717  if ($file != "") {
718  // get mime type, if not already set!
719  if ($format === "") {
720  $format = ilObjMediaObject::getMimeType($file, ($locationType === "Reference"));
721  }
722 
723  // set real meta and object data
724  $mediaItem->setFormat($format);
725  $mediaItem->setLocation($location);
726  $mediaItem->setLocationType($locationType);
727  $mediaItem->setHAlign("Left");
728  $mediaItem->setHeight(self::isAudio($format) ? 0 : 180);
729  }
730 
731  if (($purpose === "Standard") && isset($title)) {
732  $mob->setTitle($title);
733  }
734 
735  return $file;
736  }
737 
741  public function updateCastItemObject(): void
742  {
743  $ilCtrl = $this->ctrl;
745  $ilLog = $this->log;
746  $title = "";
747  $description = "";
748  $file = null;
749 
750  $this->checkPermission("write");
751 
752  $this->initAddCastItemForm("edit");
753 
754  if ($this->form_gui->checkInput()) {
755  // create new media cast item
756  $mc_item = new ilNewsItem(
757  $this->mc_request->getItemId()
758  );
759  $mob_id = $mc_item->getMobId();
760 
761  // create dummy object in db (we need an id)
762  $mob = new ilObjMediaObject($mob_id);
763 
764 
765  foreach (ilObjMediaCast::$purposes as $purpose) {
766  if ($this->form_gui->getInput("delete_" . $purpose)) {
767  $mob->removeMediaItem($purpose);
768  $ilLog->write("Mcst: deleting purpose $purpose");
769  continue;
770  }
771  $media_item = $mob->getMediaItem($purpose);
772  $url_gui = $this->form_gui->getInput("url_" . $purpose);
773  $file_gui = $this->form_gui->getInput("file_" . $purpose);
774 
775  if ($media_item == null) {
776  if ($purpose != "Standard" &&
777  ($url_gui || $file_gui["size"] > 0)) {
778  // check if we added an additional purpose when updating
779  // either by url or by file
780  $file = $this->createMediaItemForPurpose($mob, $purpose);
781  }
782  } else {
783  $file = $this->updateMediaItem($mob, $media_item);
784  }
785 
786  if ($purpose == "Standard") {
787  $duration = $this->getDuration($media_item);
788  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
789  $description = $this->form_gui->getInput("description");
790 
791  $mob->setTitle($title);
792  $mob->setDescription($description);
793 
794  $prevpic = $this->form_gui->getInput("preview_pic");
795  if ($prevpic["size"] > 0) {
796  $mob->uploadVideoPreviewPic($prevpic);
797  } else {
798  $prevpici = $this->form_gui->getItemByPostVar("preview_pic");
799  if ($prevpici->getDeletionFlag()) {
800  $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
801  }
802  }
803  }
804  }
805 
806  // set real meta and object data
807  $mob->update();
808 
809  //
810  // @todo: save usage
811  //
812 
813  $news_set = new ilSetting("news");
814  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
815 
816  $mc_item->setUserId($ilUser->getId());
817  if (isset($duration)) {
818  $mc_item->setPlaytime($duration);
819  $dur_arr = explode(":", $duration);
820  $seconds = ((int) $dur_arr[0] * 60 * 60) + ((int) $dur_arr[1] * 60) + ((int) $dur_arr[2]);
821  $st_med = $mob->getMediaItem("Standard");
822  $st_med->setDuration($seconds);
823  $st_med->update();
824  }
825  $mc_item->setTitle($title);
826  $mc_item->setContent($description);
827  if ($enable_internal_rss) {
828  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
829  }
830  $mc_item->update();
831 
832  $ilCtrl->redirect($this, "listItems");
833  } else {
834  $this->populateFormFromPost();
835  }
836  }
837 
838  public function confirmDeletionItemsObject(): void
839  {
840  $ilCtrl = $this->ctrl;
841  $lng = $this->lng;
842  $tpl = $this->tpl;
843  $ilTabs = $this->tabs;
844 
845  $this->checkPermission("write");
846  $ilTabs->activateTab("edit_content");
847 
848  $ids = $this->mc_request->getItemIds();
849  if (count($ids) == 0) {
850  $this->listItemsObject();
851  return;
852  }
853 
854  $c_gui = new ilConfirmationGUI();
855 
856  // set confirm/cancel commands
857  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteItems"));
858  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
859  $c_gui->setCancel($lng->txt("cancel"), "listItems");
860  $c_gui->setConfirm($lng->txt("confirm"), "deleteItems");
861 
862  // add items to delete
863  foreach ($ids as $item_id) {
864  $item = new ilNewsItem($item_id);
865  $c_gui->addItem(
866  "item_id[]",
867  $item_id,
868  $item->getTitle(),
869  ilUtil::getImagePath("icon_mcst.svg")
870  );
871  }
872 
873  $tpl->setContent($c_gui->getHTML());
874  }
875 
876  public function deleteItemsObject(): void
877  {
878  $ilCtrl = $this->ctrl;
879 
880  $this->checkPermission("write");
881 
882  // delete all selected news items
883  $ids = $this->mc_request->getItemIds();
884  foreach ($ids as $item_id) {
885  $mc_item = new ilNewsItem($item_id);
886  $mc_item->delete();
887  }
888  $this->object->saveOrder(array_map(function($i) {
889  return $i["id"];
890  }, $this->object->readItems()));
891  $ilCtrl->redirect($this, "listItems");
892  }
893 
897  public function downloadItemObject(): void
898  {
899  $ilCtrl = $this->ctrl;
901 
902  $this->checkPermission("read");
903  $news_item = new ilNewsItem($this->mc_request->getItemId());
904  $this->object->handleLPUpdate($ilUser->getId(), $news_item->getMobId());
905  if (!$news_item->deliverMobFile(
906  $this->mc_request->getPurpose(),
907  $this->mc_request->getPresentation()
908  )) {
909  $ilCtrl->redirect($this, "listItems");
910  }
911  exit;
912  }
913 
914  public function determinePlaytimeObject(): void
915  {
916  $ilCtrl = $this->ctrl;
917  $lng = $this->lng;
918 
919  $mc_item = new ilNewsItem($this->mc_request->getItemId());
920  $mob = $mc_item->getMobId();
921  $mob = new ilObjMediaObject($mob);
922  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
923  $m_item = $mob->getMediaItem("Standard");
924 
925  $success = false;
926 
927  $m_item->determineDuration();
928  $dur = $m_item->getDuration();
929  if ($dur > 0) {
930  $mc_item->setPlaytime($this->object->getPlaytimeForSeconds($dur));
931  $mc_item->update();
932  $success = true;
933  $this->tpl->setOnScreenMessage('success', $lng->txt("mcst_set_playtime"), true);
934  }
935 
936  if (!$success) {
937  $this->tpl->setOnScreenMessage('failure', $lng->txt("mcst_unable_to_determin_playtime"), true);
938  }
939 
940  $ilCtrl->redirect($this, "listItems");
941  }
942 
946  public function infoScreenObject(): void
947  {
948  if (!$this->checkPermissionBool("read")) {
949  $this->checkPermission("visible");
950  }
951  $this->ctrl->setCmd("showSummary");
952  $this->ctrl->setCmdClass("ilinfoscreengui");
953  $this->infoScreen();
954  }
955 
956  public function infoScreen(): void
957  {
958  $ilTabs = $this->tabs;
959 
960  $ilTabs->activateTab("id_info");
961 
962  if (!$this->checkPermissionBool("read")) {
963  $this->checkPermission("visible");
964  }
965 
966  $info = new ilInfoScreenGUI($this);
967 
968  $info->enablePrivateNotes();
969 
970  // general information
971  $this->lng->loadLanguageModule("meta");
972  $this->lng->loadLanguageModule("mcst");
973  $med_items = $this->object->getItemsArray();
974  $info->addSection($this->lng->txt("meta_general"));
975  $info->addProperty(
976  $this->lng->txt("mcst_nr_items"),
977  count($med_items)
978  );
979 
980  if (count($med_items) > 0) {
981  $cur = current($med_items);
982  $last = ilDatePresentation::formatDate(new ilDateTime($cur["creation_date"], IL_CAL_DATETIME));
983  } else {
984  $last = "-";
985  }
986 
987  $info->addProperty($this->lng->txt("mcst_last_submission"), $last);
988 
989  // forward the command
990  $this->ctrl->forwardCommand($info);
991  }
992 
993  protected function setTabs(): void
994  {
995  $ilAccess = $this->access;
996  $ilTabs = $this->tabs;
997  $lng = $this->lng;
998  $ilHelp = $this->help;
999 
1000  $ilHelp->setScreenIdComponent("mcst");
1001 
1002  // list items
1003  if ($ilAccess->checkAccess('read', "", $this->object->getRefId())) {
1004  $ilTabs->addTab(
1005  "content",
1006  $lng->txt("content"),
1007  $this->ctrl->getLinkTarget($this, "showContent")
1008  );
1009  }
1010 
1011  // info screen
1012  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId()) ||
1013  $ilAccess->checkAccess('read', "", $this->object->getRefId())) {
1014  $ilTabs->addTab(
1015  "id_info",
1016  $lng->txt("info_short"),
1017  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary")
1018  );
1019  }
1020 
1021  // settings
1022  if ($ilAccess->checkAccess('write', "", $this->object->getRefId())) {
1023  $ilTabs->addTab(
1024  "id_settings",
1025  $lng->txt("settings"),
1026  $this->ctrl->getLinkTarget($this, "editSettings")
1027  );
1028  }
1029 
1030  if (ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
1031  $ilTabs->addTab(
1032  'learning_progress',
1033  $lng->txt('learning_progress'),
1034  $this->ctrl->getLinkTargetByClass(array(__CLASS__, 'illearningprogressgui'), '')
1035  );
1036  }
1037 
1038  // export
1039  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1040  $ilTabs->addTab(
1041  "export",
1042  $lng->txt("export"),
1043  $this->ctrl->getLinkTargetByClass("ilexportgui", "")
1044  );
1045  }
1046 
1047  // edit permissions
1048  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
1049  $ilTabs->addTab(
1050  "id_permissions",
1051  $lng->txt("perm_settings"),
1052  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm")
1053  );
1054  }
1055  }
1056 
1057  public function addContentSubTabs(
1058  string $a_active = "content"
1059  ): void {
1060  $ilTabs = $this->tabs;
1061  $ilAccess = $this->access;
1062  $lng = $this->lng;
1063 
1064  $ilTabs->addSubTab(
1065  "content",
1066  $lng->txt("view"),
1067  $this->ctrl->getLinkTarget($this, "showContent")
1068  );
1069 
1070  if ($ilAccess->checkAccess("write", "", $this->requested_ref_id)) {
1071  $ilTabs->addSubTab(
1072  "manage",
1073  $lng->txt("mcst_manage"),
1074  $this->ctrl->getLinkTarget($this, "listItems")
1075  );
1076 
1077  if ($this->object->getOrder() == ilObjMediaCast::ORDER_MANUAL) {
1078  $ilTabs->addSubTab(
1079  "sorting",
1080  $lng->txt("mcst_ordering"),
1081  $this->ctrl->getLinkTarget($this, "editOrder")
1082  );
1083  }
1084  }
1085 
1086  $ilTabs->activateSubTab($a_active);
1087  $ilTabs->activateTab("content");
1088  }
1089 
1090  public function editSettingsObject(): void
1091  {
1092  $tpl = $this->tpl;
1093  $ilTabs = $this->tabs;
1094 
1095  $this->checkPermission("write");
1096  $ilTabs->activateTab("id_settings");
1097 
1098  $this->initSettingsForm();
1099  $tpl->setContent($this->form_gui->getHTML());
1100  }
1101 
1105  public function initSettingsForm(): void
1106  {
1107  $lng = $this->lng;
1108  $ilCtrl = $this->ctrl;
1109  $obj_service = $this->object_service;
1110 
1111  $lng->loadLanguageModule("mcst");
1112 
1113  $this->form_gui = new ilPropertyFormGUI();
1114  $this->form_gui->setTitle($lng->txt("mcst_settings"));
1115 
1116  // Title
1117  $tit = new ilTextInputGUI($lng->txt("title"), "title");
1118  $tit->setValue($this->object->getTitle());
1119  $tit->setRequired(true);
1120  $this->form_gui->addItem($tit);
1121 
1122  // description
1123  $des = new ilTextAreaInputGUI($lng->txt("description"), "description");
1124  $des->setValue($this->object->getLongDescription());
1125  $this->form_gui->addItem($des);
1126 
1127  $sh = new ilFormSectionHeaderGUI();
1128  $sh->setTitle($lng->txt("rep_activation_availability"));
1129  $this->form_gui->addItem($sh);
1130 
1131  // Online
1132  $online = new ilCheckboxInputGUI($lng->txt("online"), "online");
1133  $online->setChecked($this->object->getOnline());
1134  $this->form_gui->addItem($online);
1135 
1136  // presentation
1137  $sh = new ilFormSectionHeaderGUI();
1138  $sh->setTitle($lng->txt("obj_presentation"));
1139  $this->form_gui->addItem($sh);
1140 
1141  // tile image
1142  $obj_service->commonSettings()->legacyForm($this->form_gui, $this->object)->addTileImage();
1143 
1144  // Sorting
1145  $sort = new ilRadioGroupInputGUI($lng->txt("mcst_ordering"), "order");
1146  $sort->addOption(new ilRadioOption(
1147  $lng->txt("mcst_ordering_title"),
1149  ));
1150  $sort->addOption(new ilRadioOption(
1151  $lng->txt("mcst_ordering_creation_date_asc"),
1153  ));
1154  $sort->addOption(new ilRadioOption(
1155  $lng->txt("mcst_ordering_creation_date_desc"),
1157  ));
1158  $sort->addOption(new ilRadioOption(
1159  $lng->txt("mcst_ordering_manual"),
1161  ));
1162  $sort->setValue($this->object->getOrder());
1163  $this->form_gui->addItem($sort);
1164 
1165  // view mode
1166  $si = new ilRadioGroupInputGUI($this->lng->txt("mcst_viewmode"), "viewmode");
1167  /*$si->addOption(new ilRadioOption(
1168  $lng->txt("mcst_list"),
1169  ilObjMediaCast::VIEW_LIST
1170  ));
1171  $si->addOption(new ilRadioOption(
1172  $lng->txt("mcst_gallery"),
1173  ilObjMediaCast::VIEW_GALLERY
1174  ));*/
1175  $si->addOption(new ilRadioOption(
1176  $lng->txt("mcst_img_gallery"),
1178  ));
1179  $si->addOption(new ilRadioOption(
1180  $lng->txt("mcst_podcast"),
1182  ));
1183  $si->addOption($vc_opt = new ilRadioOption(
1184  $lng->txt("mcst_video_cast"),
1186  ));
1187 
1188  // $si->setOptions($options);
1189  $si->setValue($this->object->getViewMode());
1190  $this->form_gui->addItem($si);
1191 
1192  // autoplay
1193  $options = array(
1194  ilObjMediaCast::AUTOPLAY_NO => $lng->txt("mcst_no_autoplay"),
1195  ilObjMediaCast::AUTOPLAY_ACT => $lng->txt("mcst_autoplay_active"),
1196  ilObjMediaCast::AUTOPLAY_INACT => $lng->txt("mcst_autoplay_inactive")
1197  );
1198  $si = new ilSelectInputGUI($lng->txt("mcst_autoplay"), "autoplaymode");
1199  $si->setInfo($lng->txt("mcst_autoplay_info"));
1200  $si->setOptions($options);
1201  $si->setValue($this->object->getAutoplayMode());
1202  $vc_opt->addSubItem($si);
1203 
1204  // number of initial videos
1205  $ti = new ilNumberInputGUI($lng->txt("mcst_nr_videos"), "nr_videos");
1206  $ti->setValue(max(1, $this->object->getNumberInitialVideos()));
1207  $ti->setMinValue(1);
1208  $ti->setSize(2);
1209  $vc_opt->addSubItem($ti);
1210 
1211  // Downloadable
1212  $downloadable = new ilCheckboxInputGUI($lng->txt("mcst_downloadable"), "downloadable");
1213  $downloadable->setChecked($this->object->getDownloadable());
1214  $downloadable->setInfo($lng->txt("mcst_downloadable_info"));
1215  $this->form_gui->addItem($downloadable);
1216 
1217  $news_set = new ilSetting("news");
1218  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1219 
1220  //Default Visibility
1221  if ($enable_internal_rss) {
1222  // webfeed
1223  $sh = new ilFormSectionHeaderGUI();
1224  $sh->setTitle($lng->txt("mcst_webfeed"));
1225  $this->form_gui->addItem($sh);
1226 
1227  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "defaultaccess");
1228  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "0");
1229  $radio_option->setInfo($lng->txt("news_news_item_def_visibility_users_info"));
1230  $radio_group->addOption($radio_option);
1231  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "1");
1232  $radio_option->setInfo($lng->txt("news_news_item_def_visibility_public_info"));
1233  $radio_group->addOption($radio_option);
1234  $radio_group->setRequired(false);
1235  $radio_group->setValue($this->object->getDefaultAccess());
1236  #$ch->addSubItem($radio_group);
1237  $this->form_gui->addItem($radio_group);
1238 
1239  //Extra Feed
1240  $public_feed = ilBlockSetting::_lookup("news", "public_feed", 0, $this->object->getId());
1241  $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"), "extra_feed");
1242  $ch->setInfo($lng->txt("news_public_feed_info"));
1243  $ch->setChecked((bool) $public_feed);
1244  $this->form_gui->addItem($ch);
1245 
1246  // keep minimal x number of items
1247  $ni = new ilNumberInputGUI($this->lng->txt("news_keep_minimal_x_items"), "keep_rss_min");
1248  $ni->setMaxValue(100);
1249  $ni->setMinValue(0);
1250  $ni->setMaxLength(3);
1251  $ni->setSize(3);
1252  $ni->setInfo($this->lng->txt("news_keep_minimal_x_items_info") . " (" .
1253  ilNewsItem::_lookupRSSPeriod() . " " . (ilNewsItem::_lookupRSSPeriod() == 1 ? $lng->txt("day") : $lng->txt("days")) . ")");
1254  $ni->setValue((int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $this->object->getId()));
1255  $ch->addSubItem($ni);
1256 
1257  // Include Files in Pubic Items
1258  $incl_files = new ilCheckboxInputGUI($lng->txt("mcst_incl_files_in_rss"), "public_files");
1259  $incl_files->setChecked($this->object->getPublicFiles());
1260  $incl_files->setInfo($lng->txt("mcst_incl_files_in_rss_info"));
1261  #$ch->addSubItem($incl_files);
1262  $this->form_gui->addItem($incl_files);
1263  }
1264 
1265  if (ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
1266  $sh = new ilFormSectionHeaderGUI();
1267  $sh->setTitle($lng->txt("learning_progress"));
1268  $this->form_gui->addItem($sh);
1269 
1270  // Include new items automatically in learning progress
1271  $auto_lp = new ilCheckboxInputGUI($lng->txt("mcst_new_items_det_lp"), "auto_det_lp");
1272  $auto_lp->setChecked($this->object->getNewItemsInLearningProgress());
1273  $auto_lp->setInfo($lng->txt("mcst_new_items_det_lp_info"));
1274  $this->form_gui->addItem($auto_lp);
1275  }
1276 
1277 
1278  // Form action and save button
1279  $this->form_gui->addCommandButton("saveSettings", $lng->txt("save"));
1280  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveSettings"));
1281  }
1282 
1283  public function saveSettingsObject(): void
1284  {
1285  $ilCtrl = $this->ctrl;
1286  $ilTabs = $this->tabs;
1287  $obj_service = $this->object_service;
1288 
1289  $this->checkPermission("write");
1290  $ilTabs->activateTab("id_settings");
1291 
1292  $this->initSettingsForm();
1293  if ($this->form_gui->checkInput()) {
1294  $news_set = new ilSetting("news");
1295  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1296 
1297  $this->object->setTitle($this->form_gui->getInput("title"));
1298  $this->object->setDescription($this->form_gui->getInput("description"));
1299  $this->object->setOnline($this->form_gui->getInput("online"));
1300  $this->object->setDownloadable($this->form_gui->getInput("downloadable"));
1301  $this->object->setOrder($this->form_gui->getInput("order"));
1302  $this->object->setViewMode($this->form_gui->getInput("viewmode"));
1303  $this->object->setAutoplayMode((int) $this->form_gui->getInput("autoplaymode"));
1304  $this->object->setNumberInitialVideos((int) $this->form_gui->getInput("nr_videos"));
1305  $this->object->setNewItemsInLearningProgress((int) $this->form_gui->getInput("auto_det_lp"));
1306 
1307  // tile image
1308  $obj_service->commonSettings()->legacyForm($this->form_gui, $this->object)->saveTileImage();
1309 
1310  if ($enable_internal_rss) {
1311  $this->object->setPublicFiles($this->form_gui->getInput("public_files"));
1312  $this->object->setDefaultAccess($this->form_gui->getInput("defaultaccess"));
1313  }
1314  $this->object->update();
1315 
1316  if ($enable_internal_rss) {
1318  "news",
1319  "public_feed",
1320  $this->form_gui->getInput("extra_feed"),
1321  0,
1322  $this->object->getId()
1323  );
1324 
1326  "news",
1327  "keep_rss_min",
1328  $this->form_gui->getInput("keep_rss_min"),
1329  0,
1330  $this->object->getId()
1331  );
1332  }
1333 
1334  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
1335  $ilCtrl->redirect($this, "editSettings");
1336  } else {
1337  $this->form_gui->setValuesByPost();
1338  $this->tpl->setContent($this->form_gui->getHTML());
1339  }
1340  }
1341 
1342  protected function addLocatorItems(): void
1343  {
1344  $ilLocator = $this->locator;
1345 
1346  if (is_object($this->object)) {
1347  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listItems"), "", $this->requested_ref_id);
1348  }
1349  }
1350 
1351  public static function _goto(string $a_target): void
1352  {
1353  global $DIC;
1354  $main_tpl = $DIC->ui()->mainTemplate();
1355 
1356  $ilAccess = $DIC->access();
1357  $lng = $DIC->language();
1358  $ctrl = $DIC->ctrl();
1359 
1360  if ($ilAccess->checkAccess("read", "", $a_target)) {
1361  $ctrl->setParameterByClass("ilobjmediacastgui", "ref_id", $a_target);
1362  $ctrl->redirectByClass(["ilmediacasthandlergui", "ilobjmediacastgui"], "showContent");
1363  } elseif ($ilAccess->checkAccess("visible", "", $a_target)) {
1364  ilObjectGUI::_gotoRepositoryNode($a_target, "infoScreen");
1365  } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
1366  $main_tpl->setOnScreenMessage('failure', sprintf(
1367  $lng->txt("msg_no_perm_read_item"),
1369  ));
1371  }
1372 
1373  throw new ilPermissionException($lng->txt("msg_no_perm_read"));
1374  }
1375 
1376  protected static function isAudio(string $extension): bool
1377  {
1378  return strpos($extension, "audio") !== false;
1379  }
1380 
1384  protected function getMediaItem(int $id): ilMediaItem
1385  {
1386  $this->mcst_item = new ilNewsItem($id);
1387  // create dummy object in db (we need an id)
1388  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1389  return $mob->getMediaItem("Standard");
1390  }
1391 
1392  protected function getMediaItems(int $id): array
1393  {
1394  $this->mcst_item = new ilNewsItem($id);
1395  // create dummy object in db (we need an id)
1396  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1397  return $mob->getMediaItems();
1398  }
1399 
1400  private function populateFormFromPost(): void
1401  {
1402  $tpl = $this->tpl;
1403  $this->form_gui->setValuesByPost();
1404 
1405  //issue: we have to display the current settings
1406  // problem: POST does not contain values of disabled text fields
1407  // solution: use hidden field and label to display-> here we need to synchronize the labels
1408  // with the values from the hidden fields.
1409  foreach (ilObjMediaCast::$purposes as $purpose) {
1410  if ($this->form_gui->getInput("value_" . $purpose)) {
1411  $input = $this->form_gui->getItemByPostVar("label_value_" . $purpose);
1412  $input->setValue($this->form_gui->getInput("value_" . $purpose));
1413  }
1414  }
1415 
1416  $this->form_gui->setValuesByPost();
1417  $tpl->setContent($this->form_gui->getHTML());
1418  }
1419 
1420  protected function editOrderObject(): void
1421  {
1422  $ilTabs = $this->tabs;
1423  $lng = $this->lng;
1424  $tpl = $this->tpl;
1425 
1426  $this->checkPermission("write");
1427  $ilTabs->activateTab("edit_content");
1428 
1429  $this->addContentSubTabs("sorting");
1430 
1431  // sort by order setting
1432  switch ($this->object->getOrder()) {
1436  $this->listItemsObject();
1437  return;
1438 
1440  // sub-tabs
1441  break;
1442  }
1443 
1444  $table_gui = new ilMediaCastTableGUI($this, "editOrder", true);
1445 
1446  $table_gui->setTitle($lng->txt("mcst_media_cast"));
1447  $table_gui->setData($this->object->getSortedItemsArray());
1448 
1449  $table_gui->addCommandButton("saveOrder", $lng->txt("mcst_save_order"));
1450 
1451  $tpl->setContent($table_gui->getHTML());
1452  }
1453 
1454  public function saveOrderObject(): void
1455  {
1456  $lng = $this->lng;
1457 
1458  $ids = $this->mc_request->getItemIds();
1459  asort($ids);
1460 
1461  $items = array();
1462  foreach (array_keys($ids) as $id) {
1463  $items[] = $id;
1464  }
1465  $this->object->saveOrder($items);
1466 
1467  $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
1468  $this->ctrl->redirect($this, "editOrder");
1469  }
1470 
1474 
1475  public function showContentObject(): void
1476  {
1477  $tpl = $this->tpl;
1478  $ilUser = $this->user;
1479  $ilTabs = $this->tabs;
1480 
1481  // need read events for parent for LP statistics
1483  "mcst",
1484  $this->object->getRefId(),
1485  $this->object->getId(),
1486  $ilUser->getId()
1487  );
1488 
1489  // trigger LP update
1490  ilLPStatusWrapper::_updateStatus($this->object->getId(), $ilUser->getId());
1491 
1492  if ($this->object->getViewMode() == ilObjMediaCast::VIEW_GALLERY) {
1493  $this->showGallery();
1494  } elseif ($this->object->getViewMode() == ilObjMediaCast::VIEW_IMG_GALLERY) {
1495  $view = new \McstImageGalleryGUI($this->object, $this->tpl, $this->getFeedLink());
1496  $view->setCompletedCallback($this->ctrl->getLinkTarget(
1497  $this,
1498  "handlePlayerCompletedEvent",
1499  "",
1500  true,
1501  false
1502  ));
1503  $this->tabs->activateTab("content");
1504  $this->addContentSubTabs("content");
1505  $tpl->setContent($this->ctrl->getHTML($view));
1506  } elseif ($this->object->getViewMode() == ilObjMediaCast::VIEW_PODCAST) {
1507  $view = new \McstPodcastGUI($this->object, $this->tpl, $this->getFeedLink());
1508  $this->tabs->activateTab("content");
1509  $this->addContentSubTabs("content");
1510  $tpl->setContent($this->ctrl->getHTML($view));
1511  } elseif ($this->object->getViewMode() == ilObjMediaCast::VIEW_VCAST) {
1512  $ilTabs->activateTab("content");
1513  $this->addContentSubTabs("content");
1514  $view = new \ILIAS\MediaCast\Presentation\VideoViewGUI($this->object, $tpl, $this->getFeedLink());
1515  $view->setCompletedCallback($this->ctrl->getLinkTarget(
1516  $this,
1517  "handlePlayerCompletedEvent",
1518  "",
1519  true,
1520  false
1521  ));
1522  $view->setAutoplayCallback($this->ctrl->getLinkTarget(
1523  $this,
1524  "handleAutoplayTrigger",
1525  "",
1526  true,
1527  false
1528  ));
1529  $view->show();
1530  } else {
1531  $this->listItemsObject(true);
1532  }
1533 
1534  $tpl->setPermanentLink($this->object->getType(), $this->object->getRefId());
1535  }
1536 
1537  public function showGallery(): void
1538  {
1539  $tpl = $this->tpl;
1540  $ilTabs = $this->tabs;
1541  $ilCtrl = $this->ctrl;
1542 
1543  $this->tpl->setOnScreenMessage('info', $this->lng->txt("mcst_view_abandoned"));
1544  }
1545 
1546  public function extractPreviewImageObject(): void
1547  {
1548  $ilCtrl = $this->ctrl;
1549  $add = "";
1550 
1551  $this->checkPermission("write");
1552 
1553  $this->mcst_item = new ilNewsItem($this->mc_request->getItemId());
1554  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1555 
1556  try {
1557  $sec = $this->mc_request->getSeconds();
1558  if ($sec < 0) {
1559  $sec = 0;
1560  }
1561 
1562  $mob->generatePreviewPic(320, 240, $sec);
1563  if ($mob->getVideoPreviewPic() !== "") {
1564  $this->tpl->setOnScreenMessage('info', $this->lng->txt("mcst_image_extracted"), true);
1565  } else {
1566  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("mcst_no_extraction_possible"), true);
1567  }
1568  } catch (ilException $e) {
1569  if (DEVMODE == 1) {
1571  $add = (is_array($ret) && count($ret) > 0)
1572  ? "<br />" . implode("<br />", $ret)
1573  : "";
1574  }
1575  $this->tpl->setOnScreenMessage('failure', $e->getMessage() . $add, true);
1576  }
1577 
1578  $ilCtrl->redirect($this, "editCastItem");
1579  }
1580 
1581  public function handlePlayerEventObject(): void
1582  {
1583  if ($this->mc_request->getEvent() === "play") {
1584  $player = explode("_", $this->mc_request->getPlayer());
1585  $news_id = (int) $player[1];
1586  $item = new ilNewsItem($news_id);
1587  $item->increasePlayCounter();
1588 
1589  $mob_id = $item->getMobId();
1590  if ($mob_id) {
1591  $ilUser = $this->user;
1592  $this->object->handleLPUpdate($ilUser->getId(), $mob_id);
1593  }
1594  }
1595  exit;
1596  }
1597 
1598  protected function handlePlayerCompletedEventObject(): void
1599  {
1600  $mob_id = $this->mc_request->getMobId();
1601  if ($mob_id > 0) {
1602  $ilUser = $this->user;
1603  $this->object->handleLPUpdate($ilUser->getId(), $mob_id);
1604  }
1605  exit;
1606  }
1607 
1608  protected function afterUpload($mob_ids): void
1609  {
1610  $this->addMobsToCast($mob_ids, "", false);
1611  }
1612 
1613  protected function afterUrlSaving(int $mob_id, string $long_desc): void
1614  {
1615  $this->addMobsToCast([$mob_id], $long_desc);
1616  }
1617 
1618  protected function addMobsToCast(
1619  array $mob_ids,
1620  string $long_desc = "",
1621  bool $redirect = true,
1622  bool $extract = false
1623  ): void {
1624  $ctrl = $this->ctrl;
1625  $user = $this->user;
1626 
1627  $item_ids = [];
1628  foreach ($mob_ids as $mob_id) {
1629  $item_ids[] = $this->object->addMobToCast($mob_id, $user->getId(), $long_desc, $extract);
1630  }
1631 
1632  if ($redirect) {
1633  if (count($item_ids) === 1) {
1634  $ctrl->setParameter($this, "item_id", $item_ids[0]);
1635  $ctrl->redirect($this, "editCastItem");
1636  }
1637  $ctrl->redirect($this, "listItems");
1638  }
1639  }
1640 
1641  protected function afterPoolInsert(array $mob_ids): void
1642  {
1643  $this->addMobsToCast($mob_ids, "", true, true);
1644  }
1645 
1646  protected function handleAutoplayTriggerObject(): void
1647  {
1648  $this->user->writePref(
1649  "mcst_autoplay",
1650  $this->mc_request->getAutoplay()
1651  );
1652  exit;
1653  }
1654 }
ILIAS MediaCast MediaCastManager $mc_manager
getDuration(ilMediaItem $media_item)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLastReturnValues()
Get last return values.
exit
Definition: login.php:28
Class ilInfoScreenGUI.
getMediaItem(int $id)
Get MediaItem for id and updates local variable mcst_item.
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
initImportForm(string $new_type)
static _lookupRSSPeriod()
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
GUI class for the workflow of copying objects.
initSettingsForm()
Init Settings Form.
const ROOT_FOLDER_ID
Definition: constants.php:32
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
prepareOutput(bool $show_sub_objects=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
__construct( $a_data, int $a_id, bool $a_call_by_reference, bool $a_prepare_output=true)
setInfo(string $a_info)
listItemsObject(bool $a_presentation_mode=false)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Help GUI class.
addMediaItem(ilMediaItem $a_item)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setPattern(string $pattern)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
setPlaytime(string $a_playtime)
static _gotoRepositoryNode(int $ref_id, string $cmd="")
This class represents a checkbox property in a property form.
setParameterByClass(string $a_class, string $a_parameter, $a_value)
setLocation(string $a_location)
createDirectory()
Create file directory of media object.
static isAudio(string $extension)
addOption(ilRadioOption $a_option)
setSuffixes(array $a_suffixes)
loadLanguageModule(string $a_module)
Load language module.
setTitle(string $title)
afterUrlSaving(int $mob_id, string $long_desc)
setFormat(string $a_format)
static checkAccess(int $a_ref_id, bool $a_allow_only_read=true)
check access to learning progress
static _lookupObjId(int $ref_id)
static getASCIIFilename(string $a_filename)
setPostVar(string $a_postvar)
setHAlign(string $a_halign)
set horizontal align
global $DIC
Definition: feed.php:28
static renameExecutables(string $a_dir)
static _goto(string $a_target)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLanguage $lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static supportsImageExtraction(string $a_mime)
Check if mime type supports image extraction.
static _getDirectory(int $a_mob_id)
Get absolute directory.
This class represents a property in a property form.
fillCloneTemplate(?string $tpl_name, string $type)
Fill object clone template This method can be called from any object GUI class that wants to offer ob...
ilGlobalTemplateInterface $tpl
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
static _lookupTitle(int $obj_id)
getCastItemValues()
Get cast item values into form.
setContent(string $a_html)
Sets content for standard template.
addCastItemObject()
Add media cast item.
This class represents a number property in a property form.
setValue(?string $a_value)
setMaxValue(float $a_maxvalue, bool $a_display_always=false)
setScreenIdComponent(string $a_comp)
updateCastItemObject()
Update cast item.
Class ilObjectGUI Basic methods of all Output classes.
addContentSubTabs(string $a_active="content")
const CLIENT_ID
Definition: constants.php:41
static _recordReadEvent(string $a_type, int $a_ref_id, int $obj_id, int $usr_id, bool $isCatchupWriteEvents=true, $a_ext_rc=null, $a_ext_time=null)
getMediaItem(string $a_purpose)
get item for media purpose
ilPropertyFormGUI $form_gui
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
updateMediaItem(ilObjMediaObject $mob, ilMediaItem $mediaItem)
Update media item from form.
ilToolbarGUI $toolbar
initAddCastItemForm(string $a_mode="create")
$format
Definition: metadata.php:235
ilObjectService $object_service
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
StandardGUIRequest $mc_request
setRequired(bool $a_required)
setHeight(string $a_height)
static array $purposes
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
static redirect(string $a_script)
setPermanentLink(string $a_type, ?int $a_id, string $a_append="", string $a_target="", string $a_title="")
Generates and sets a permanent ilias link.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
activateTab(string $a_id)
A news item can be created by different sources.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
downloadItemObject()
Download news media item.
initCreateForm(string $new_type)
afterSave(ilObject $new_object)
This class represents a text area property in a property form.
ilAccessHandler $access
$ilUser
Definition: imgupload.php:34
addItem(string $a_title, string $a_link, string $a_frame="", int $a_ref_id=0, ?string $type=null)
const NEWS_AUDIO
TableGUI class for table NewsForContext.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
$url
addMobsToCast(array $mob_ids, string $long_desc="", bool $redirect=true, bool $extract=false)
static enabled()
Checks, whether FFmpeg support is enabled (path is set in the setup)
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
setLocationType(string $a_type)
createMediaItemForPurpose(ilObjMediaObject $mob, string $purpose)
Handle media item for given purpose.
addHeaderAction()
Add header action menu.
ilLocatorGUI $locator
ilSetting $settings
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
infoScreenObject()
This one is called from the info button in the repository.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initCreationForms(string $new_type)