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