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