ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjMediaCastGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
9
10require_once "./Services/Object/classes/class.ilObjectGUI.php";
11
24{
28 protected $tabs;
29
33 protected $log;
34
38 protected $error;
39
43 protected $help;
44
48 protected $filesystem;
49
50 //private $additionalPurposes = array("VideoPortable", "AudioPortable");
51 private $additionalPurposes = [];
52 private $purposeSuffixes = array();
53 private $mimeTypes = array();
54
59 public function __construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
60 {
61 global $DIC;
62
63 $this->ctrl = $DIC->ctrl();
64 $this->lng = $DIC->language();
65 $this->user = $DIC->user();
66 $this->tabs = $DIC->tabs();
67 $this->tpl = $DIC["tpl"];
68 $this->access = $DIC->access();
69 $this->toolbar = $DIC->toolbar();
70 $this->filesystem = $DIC->filesystem()->web();
71 $this->log = $DIC["ilLog"];
72 $this->error = $DIC["ilErr"];
73 $this->help = $DIC["ilHelp"];
74 $this->locator = $DIC["ilLocator"];
75 $ilCtrl = $DIC->ctrl();
76 $lng = $DIC->language();
77
78 $this->type = "mcst";
79 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
80 $lng->loadLanguageModule("mcst");
81 $lng->loadLanguageModule("news");
82 $lng->loadLanguageModule("rep");
83
84 $ilCtrl->saveParameter($this, "item_id");
85
86 include_once("./Modules/MediaCast/classes/class.ilMediaCastSettings.php");
88 $this->purposeSuffixes = $settings->getPurposeSuffixes();
89 $this->mimeTypes = array();
90 $mime_types = $settings->getMimeTypes();
91 foreach ($mime_types as $mt) {
92 $this->mimeTypes[$mt] = $mt;
93 }
94
95 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
96 foreach (ilMimeTypeUtil::getExt2MimeMap() as $mt) {
97// $this->mimeTypes[$mt] = $mt;
98 }
99 asort($this->mimeTypes);
100 }
101
102 public function executeCommand()
103 {
105 $ilTabs = $this->tabs;
106
107 $next_class = $this->ctrl->getNextClass($this);
108 $cmd = $this->ctrl->getCmd();
109 $this->prepareOutput();
110
111 switch ($next_class) {
112
113 case "ilmediacreationgui":
114 $this->ctrl->setReturn($this, "listItems");
115 $ilTabs->activateTab("content");
116 $this->addContentSubTabs("manage");
117 $creation = new ilMediaCreationGUI([ilMediaCreationGUI::TYPE_ALL], function ($mob_id) {
118 $this->afterUpload($mob_id);
119 }, function ($mob_id, $long_desc) {
120 $this->afterUrlSaving($mob_id, $long_desc);
121 }, function ($mob_ids) {
122 $this->afterPoolInsert($mob_ids);
123 });
124 $creation->setAllSuffixes($this->purposeSuffixes["Standard"]);
125 $creation->setAllMimeTypes($this->mimeTypes);
126 $this->ctrl->forwardCommand($creation);
127 break;
128
129 case "ilinfoscreengui":
130 if (!$this->checkPermissionBool("read")) {
131 $this->checkPermission("visible");
132 }
133 $this->infoScreen(); // forwards command
134 break;
135
136 case "ilexportgui":
137// $this->prepareOutput();
138 $ilTabs->activateTab("export");
139 include_once("./Services/Export/classes/class.ilExportGUI.php");
140 $exp_gui = new ilExportGUI($this);
141 $exp_gui->addFormat("xml");
142 $ret = $this->ctrl->forwardCommand($exp_gui);
143// $this->tpl->show();
144 break;
145
146 case 'ilpermissiongui':
147 $ilTabs->activateTab("id_permissions");
148 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
149 $perm_gui = new ilPermissionGUI($this);
150 $ret = $this->ctrl->forwardCommand($perm_gui);
151 break;
152
153 case 'ilobjectcopygui':
154 include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
155 $cp = new ilObjectCopyGUI($this);
156 $cp->setType('mcst');
157 $this->ctrl->forwardCommand($cp);
158 break;
159
160 case "ilcommonactiondispatchergui":
161 include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
163 $this->ctrl->forwardCommand($gui);
164 break;
165
166 case "illearningprogressgui":
167 $ilTabs->activateTab('learning_progress');
168 require_once 'Services/Tracking/classes/class.ilLearningProgressGUI.php';
169 $new_gui = new ilLearningProgressGUI(
171 $this->object->getRefId(),
172 $_GET['user_id'] ? $_GET['user_id'] : $ilUser->getId()
173 );
174 $this->ctrl->forwardCommand($new_gui);
175 $this->tabs_gui->setTabActive('learning_progress');
176 break;
177
178 default:
179 if (!$cmd) {
180 $cmd = "infoScreen";
181 }
182 $cmd .= "Object";
183 if ($cmd != "infoScreenObject") {
184 $this->checkPermission("read");
185 } else {
186 $this->checkPermission("visible");
187 }
188 $this->$cmd();
189
190 break;
191 }
192
193 $this->addHeaderAction();
194
195 return true;
196 }
197
198 protected function initCreationForms($a_new_type)
199 {
200 $forms = array(self::CFORM_NEW => $this->initCreateForm($a_new_type),
201 self::CFORM_IMPORT => $this->initImportForm($a_new_type),
202 self::CFORM_CLONE => $this->fillCloneTemplate(null, $a_new_type));
203
204 return $forms;
205 }
206
211 public function afterSave(ilObject $newObj)
212 {
213 // always send a message
214 ilUtil::sendSuccess($this->lng->txt("object_added"), true);
215 ilUtil::redirect("ilias.php?baseClass=ilMediaCastHandlerGUI&ref_id=" . $newObj->getRefId() . "&cmd=editSettings");
216 }
217
221 public function listItemsObject($a_presentation_mode = false)
222 {
225 $ilAccess = $this->access;
226 $ilTabs = $this->tabs;
227 $ilToolbar = $this->toolbar;
228
229 $this->checkPermission("read");
230
231 if ($a_presentation_mode) {
232 $this->addContentSubTabs("content");
233 } else {
234 $this->addContentSubTabs("manage");
235 }
236
237 $med_items = $this->object->getSortedItemsArray();
238
239 include_once("./Modules/MediaCast/classes/class.ilMediaCastTableGUI.php");
240 if ($a_presentation_mode) {
241 $table_gui = new ilMediaCastTableGUI($this, "showContent", false, true);
242 } else {
243 $table_gui = new ilMediaCastTableGUI($this, "listItems");
244 }
245
246 $table_gui->setData($med_items);
247
248 if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]) && !$a_presentation_mode) {
249 $ilToolbar->addButton($lng->txt("add"), $this->ctrl->getLinkTargetByClass("ilMediaCreationGUI", ""));
250
251 $table_gui->addMultiCommand("confirmDeletionItems", $lng->txt("delete"));
252 $table_gui->setSelectAllCheckbox("item_id");
253 }
254
255 $feed_icon_html = $this->getFeedIconsHTML();
256 if ($feed_icon_html != "") {
257 $table_gui->setHeaderHTML($feed_icon_html);
258 }
259
260 $tpl->setContent($table_gui->getHTML());
261 }
262
269 public function getFeedIconsHTML()
270 {
272
273 $html = "";
274
275 include_once("./Services/Block/classes/class.ilBlockSetting.php");
276 $public_feed = ilBlockSetting::_lookup(
277 "news",
278 "public_feed",
279 0,
280 $this->object->getId()
281 );
282
283 // rss icon/link
284 if ($public_feed) {
285 $news_set = new ilSetting("news");
286 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
287
288 if ($enable_internal_rss) {
289 // create dummy object in db (we need an id)
290 $items = $this->object->getItemsArray();
291 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
292 $html = "";
293 foreach (ilObjMediaCast::$purposes as $purpose) {
294 foreach ($items as $id => $item) {
295 $mob = new ilObjMediaObject($item["mob_id"]);
296 $mob->read();
297 if ($mob->hasPurposeItem($purpose)) {
298 if ($html == "") {
299 $html = " ";
300 }
301 $url = ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&" . "ref_id=" . $_GET["ref_id"] . "&purpose=$purpose";
302 $title = $lng->txt("news_feed_url");
303
304 include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
305 switch (strtolower($purpose)) {
306 case "audioportable":
309 break;
310
311 case "videoportable":
314 break;
315
316 default:
319 break;
320 }
321 $row1 .= "&nbsp;" . ilRSSButtonGUI::get($type1, $url);
322 if ($this->object->getPublicFiles()) {
323 $url = preg_replace("/https?/i", "itpc", $url);
324 $title = $lng->txt("news_feed_url");
325
326 include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
327 $row2 .= "&nbsp;" . ilRSSButtonGUI::get($type2, $url);
328 }
329 break;
330 }
331 }
332 }
333 if ($html != "") {
334 $html .= $row1;
335 if ($row2 != "") {
336 $html .= $row2;
337 }
338 }
339 }
340 }
341 return $html;
342 }
343
344
348 public function addCastItemObject()
349 {
351
352 $this->checkPermission("write");
353
354 $this->initAddCastItemForm();
355 $tpl->setContent($this->form_gui->getHTML());
356 }
357
361 public function editCastItemObject()
362 {
364 $ilToolbar = $this->toolbar;
365 $ilCtrl = $this->ctrl;
366
367 $this->checkPermission("write");
368
369 // conversion toolbar
370 include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
371 if (ilFFmpeg::enabled()) {
372 $this->mcst_item = new ilNewsItem($_GET["item_id"]);
373 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
374 $mob = new ilObjMediaObject($this->mcst_item->getMobId());
375
376 $conv_cnt = 0;
377 // we had other purposes as source as well, but
378 // currently only "Standard" is implemented in the convertFile method
379 foreach (array("Standard") as $p) {
380 /*
381 $med = $mob->getMediaItem($p);
382 if (is_object($med))
383 {
384 $options = ilFFmpeg::getPossibleTargetMimeTypes($med->getFormat());
385 if (count($options) > 0)
386 {
387 if ($conv_cnt > 0)
388 {
389 $ilToolbar->addSeparator();
390 }
391
392 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
393 $si = new ilSelectInputGUI($this->lng->txt("mcst_conv_".
394 strtolower($p)."_to"), "target_format");
395 $si->setOptions($options);
396 $ilToolbar->addInputItem($si, true);
397
398 $si = new ilSelectInputGUI(", ".$this->lng->txt("mcst_target").": ",
399 "target_purpose");
400 $si->setOptions(array("Standard" => $this->lng->txt("mcst_purpose_standard"),
401 "VideoAlternative" => $this->lng->txt("mcst_purpose_videoalternative")
402 ));
403 $si->setValue($p);
404 $ilToolbar->addInputItem($si, true);
405
406 $ilToolbar->addFormButton($this->lng->txt("mcst_convert"), "convertFile");
407
408 $conv_cnt++;
409 }
410 }
411 */
412
413 $med = $mob->getMediaItem($p);
414 if (is_object($med)) {
415 if (ilFFmpeg::supportsImageExtraction($med->getFormat())) {
416 // second
417 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
418 $ni = new ilTextInputGUI($this->lng->txt("mcst_second"), "sec");
419 $ni->setMaxLength(4);
420 $ni->setSize(4);
421 $ni->setValue(1);
422 $ilToolbar->addInputItem($ni, true);
423
424 $ilToolbar->addFormButton($this->lng->txt("mcst_extract_preview_image"), "extractPreviewImage");
425 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
426 }
427 }
428
429 /*if ($conv_cnt > 0)
430 {
431 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
432 }*/
433 }
434 }
435
436 $this->initAddCastItemForm("edit");
437 $this->getCastItemValues();
438 $tpl->setContent($this->form_gui->getHTML());
439 }
440
444 public function initAddCastItemForm($a_mode = "create")
445 {
447 $ilCtrl = $this->ctrl;
448 $ilTabs = $this->tabs;
449
450 $this->checkPermission("write");
451 $ilTabs->activateTab("edit_content");
452
453 $lng->loadLanguageModule("mcst");
454
455 $news_set = new ilSetting("news");
456 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
457
458 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
459 $this->form_gui = new ilPropertyFormGUI();
460 $this->form_gui->setMultipart(true);
461
462 // Property Title
463 $text_input = new ilTextInputGUI($lng->txt("title"), "title");
464 $text_input->setMaxLength(200);
465 $this->form_gui->addItem($text_input);
466
467 // Property Content
468 $text_area = new ilTextAreaInputGUI($lng->txt("description"), "description");
469 $text_area->setRequired(false);
470 $this->form_gui->addItem($text_area);
471
472 // Property Visibility
473 if ($enable_internal_rss) {
474 $radio_group = new ilRadioGroupInputGUI($lng->txt("access_scope"), "visibility");
475 $radio_option = new ilRadioOption($lng->txt("access_users"), "users");
476 $radio_group->addOption($radio_option);
477 $radio_option = new ilRadioOption($lng->txt("access_public"), "public");
478 $radio_group->addOption($radio_option);
479 $radio_group->setInfo($lng->txt("mcst_visibility_info"));
480 $radio_group->setRequired(true);
481 $radio_group->setValue($this->object->getDefaultAccess() == 0 ? "users" : "public");
482 $this->form_gui->addItem($radio_group);
483 }
484
485 // Duration
486 $dur = new ilDurationInputGUI($lng->txt("mcst_duration"), "duration");
487 $dur->setInfo($lng->txt("mcst_duration_info"));
488 $dur->setShowDays(false);
489 $dur->setShowHours(true);
490 $dur->setShowSeconds(true);
491 $this->form_gui->addItem($dur);
492
493 foreach (ilObjMediaCast::$purposes as $purpose) {
494 if ($purpose == "VideoAlternative" &&
495 $a_mode == "create") {
496 continue;
497 }
498
500 $section->setTitle($lng->txt("mcst_" . strtolower($purpose) . "_title"));
501 $this->form_gui->addItem($section);
502 if ($a_mode != "create") {
503 $value = new ilHiddenInputGUI("value_" . $purpose);
504 $label = new ilNonEditableValueGUI($lng->txt("value"));
505 $label->setPostVar("label_value_" . $purpose);
506 $label->setInfo($lng->txt("mcst_current_value_info"));
507 $this->form_gui->addItem($label);
508 $this->form_gui->addItem($value);
509 }
510 $file = new ilFileInputGUI($lng->txt("file"), "file_" . $purpose);
511 $file->setSuffixes($this->purposeSuffixes[$purpose]);
512 $this->form_gui->addItem($file);
513 $text_input = new ilRegExpInputGUI($lng->txt("url"), "url_" . $purpose);
514 $text_input->setPattern("/https?\:\/\/.+/i");
515 $text_input->setInfo($lng->txt("mcst_reference_info"));
516 $this->form_gui->addItem($text_input);
517 if ($purpose != "Standard") {
518 $clearCheckBox = new ilCheckboxInputGUI();
519 $clearCheckBox->setPostVar("delete_" . $purpose);
520 $clearCheckBox->setTitle($lng->txt("mcst_clear_purpose_title"));
521 $this->form_gui->addItem($clearCheckBox);
522 } else {
523
524 //
525 $ne = new ilNonEditableValueGUI($lng->txt("mcst_mimetype"), "mimetype_" . $purpose);
526 $this->form_gui->addItem($ne);
527
528 // mime type selection
529 /*
530 $mimeTypeSelection = new ilSelectInputGUI();
531 $mimeTypeSelection->setPostVar("mimetype_" . $purpose);
532 $mimeTypeSelection->setTitle($lng->txt("mcst_mimetype"));
533 $mimeTypeSelection->setInfo($lng->txt("mcst_mimetype_info"));
534 $options = array("" => $lng->txt("mcst_automatic_detection"));
535 $options = array_merge($options, $this->mimeTypes);
536 $mimeTypeSelection->setOptions($options);
537 $this->form_gui->addItem($mimeTypeSelection);*/
538
539 // preview picure
540 $pp = new ilImageFileInputGUI($lng->txt("mcst_preview_picture"), "preview_pic");
541 $pp->setSuffixes(array("png", "jpeg", "jpg"));
542 $pp->setInfo($lng->txt("mcst_preview_picture_info") . " mp4, mp3, png, jp(e)g, gif");
543 $this->form_gui->addItem($pp);
544 }
545 }
546
547 // save/cancel button
548 if ($a_mode == "create") {
549 $this->form_gui->setTitle($lng->txt("mcst_add_new_item"));
550 $this->form_gui->addCommandButton("saveCastItem", $lng->txt("save"));
551 } else {
552 $this->form_gui->setTitle($lng->txt("mcst_edit_item"));
553 $this->form_gui->addCommandButton("updateCastItem", $lng->txt("save"));
554 }
555 $this->form_gui->addCommandButton("listItems", $lng->txt("cancel"));
556 $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveCastItem"));
557 }
558
562 public function getCastItemValues()
563 {
565
566 // get mob
567 $this->mcst_item = new ilNewsItem($_GET["item_id"]);
568 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
569 $mob = new ilObjMediaObject($this->mcst_item->getMobId());
570
571 // preview
572 $ppic = $mob->getVideoPreviewPic();
573 if ($ppic != "") {
574 $i = $this->form_gui->getItemByPostVar("preview_pic");
575 $i->setImage($ppic);
576 }
577
578
579 $values = array();
580 $mediaItems = $this->getMediaItems($_GET["item_id"]);
581 if (count($mediaItems) > 0) {
582 foreach ($mediaItems as $med) {
583 if (!isset($values["title"])) {
584 // first item, so set title, description, ...
585 $values["title"] = $this->mcst_item->getTitle();
586 $values["description"] = $this->mcst_item->getContent();
587 $values["visibility"] = $this->mcst_item->getVisibility();
588 $length = explode(":", $this->mcst_item->getPlaytime());
589 $values["duration"] = array("hh" => $length[0], "mm" => $length[1], "ss" => $length[2]);
590 }
591
592 $values["value_" . $med->getPurpose()] = (strlen($med->getLocation()) > 100) ? "..." . substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
593 $values["label_value_" . $med->getPurpose()] = (strlen($med->getLocation()) > 100) ? "..." . substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
594 $values["mimetype_" . $med->getPurpose()] = $med->getFormat();
595 }
596 }
597 foreach (ilObjMediaCast::$purposes as $purpose) {
598 if (!isset($values["value_" . $purpose])) {
599 $values["label_value_" . $purpose] = $lng->txt("none");
600 $values["value_" . $purpose] = $lng->txt("none");
601 }
602 }
603 $this->form_gui->setValuesByArray($values);
604 }
605
609 public function saveCastItemObject()
610 {
612 $ilCtrl = $this->ctrl;
615 $ilTabs = $this->tabs;
616
617 $this->checkPermission("write");
618 $ilTabs->activateTab("edit_content");
619
620 $this->initAddCastItemForm();
621
622 if (!$this->form_gui->checkInput() ||
623 ($_POST["url_Standard"] == "" && !$_FILES['file_Standard']['tmp_name'])) {
624 if (($_POST["url_Standard"] == "" && !$_FILES['file_Standard']['tmp_name'])) {
625 ilUtil::sendFailure($lng->txt("mcst_input_either_file_or_url"));
626 }
627 $this->populateFormFromPost();
628 } else {
629 // create dummy object in db (we need an id)
630 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
631 $mob = new ilObjMediaObject();
632 $mob->create();
633
634 //handle standard purpose
635 $file = $this->createMediaItemForPurpose($mob, "Standard");
636
637 // set title and description
638 // set title to basename of file if left empty
639 $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
640 $description = $this->form_gui->getInput("description");
641 $mob->setTitle($title);
642 $mob->setDescription($description);
643
644 // save preview pic
645 $prevpic = $this->form_gui->getInput("preview_pic");
646 if ($prevpic["size"] > 0) {
647 $mob->uploadVideoPreviewPic($prevpic);
648 }
649
650 // determine duration for standard purpose
651 $duration = $this->getDuration($file);
652
653 // handle other purposes
654 foreach ($this->additionalPurposes as $purpose) {
655 // check if some purpose has been uploaded
656 $file_gui = $this->form_gui->getInput("file_" . $purpose);
657 $url_gui = $this->form_gui->getInput("url_" . $purpose);
658 if ($url_gui || $file_gui["size"] > 0) {
659 $this->createMediaItemForPurpose($mob, $purpose);
660 }
661 }
662
663 $mob->update();
664
665 if ($prevpic["size"] == 0) {
666 // re-read media object
667 $mob = new ilObjMediaObject($mob->getId());
668 $mob->generatePreviewPic(320, 240);
669 }
670
671 //
672 // @todo: save usage
673 //
674
675 $news_set = new ilSetting("news");
676 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
677
678 // create new media cast item
679 include_once("./Services/News/classes/class.ilNewsItem.php");
680 $mc_item = new ilNewsItem();
681 $mc_item->setMobId($mob->getId());
682 $mc_item->setContentType(NEWS_AUDIO);
683 $mc_item->setContextObjId($this->object->getId());
684 $mc_item->setContextObjType($this->object->getType());
685 $mc_item->setUserId($ilUser->getId());
686 $mc_item->setPlaytime($duration);
687 $mc_item->setTitle($title);
688 $mc_item->setContent($description);
689 $mc_item->setLimitation(false);
690 if ($enable_internal_rss) {
691 $mc_item->setVisibility($this->form_gui->getInput("visibility"));
692 } else {
693 $mc_item->setVisibility("users");
694 }
695 $mc_item->create();
696
697 $ilCtrl->redirect($this, "listItems");
698 }
699 }
700
707 private function getDuration($file)
708 {
709 $duration = isset($this->form_gui)
710 ? $this->form_gui->getInput("duration")
711 : array("hh" => 0, "mm" => 0, "ss" => 0);
712 if ($duration["hh"] == 0 && $duration["mm"] == 0 && $duration["ss"] == 0 && is_file($file)) {
713 include_once("./Services/MediaObjects/classes/class.ilMediaAnalyzer.php");
714 $ana = new ilMediaAnalyzer();
715 $ana->setFile($file);
716 $ana->analyzeFile();
717 $dur = $ana->getPlaytimeString();
718 $dur = explode(":", $dur);
719 $cnt = count($dur);
720 $duration["hh"] = $dur[$cnt - 3] ?? 0;
721 $duration["mm"] = $dur[$cnt - 2] ?? 0;
722 $duration["ss"] = $dur[$cnt - 1];
723 }
724 $duration = str_pad($duration["hh"], 2, "0", STR_PAD_LEFT) . ":" .
725 str_pad($duration["mm"], 2, "0", STR_PAD_LEFT) . ":" .
726 str_pad($duration["ss"], 2, "0", STR_PAD_LEFT);
727 return $duration;
728 }
729
736 private function createMediaItemForPurpose($mob, $purpose)
737 {
738 $mediaItem = new ilMediaItem();
739 $mob->addMediaItem($mediaItem);
740 $mediaItem->setPurpose($purpose);
741 return $this->updateMediaItem($mob, $mediaItem);
742 }
743
753 private function updateMediaItem($mob, &$mediaItem)
754 {
755 $purpose = $mediaItem->getPurpose();
756 $locationType = $mediaItem->getLocationType();
757 $url_gui = $this->form_gui->getInput("url_" . $purpose);
758 $file_gui = $this->form_gui->getInput("file_" . $purpose);
759 if ($url_gui) {
760 // http
761 $file = $this->form_gui->getInput("url_" . $purpose);
762 $title = basename($file);
763 $location = $this->form_gui->getInput("url_" . $purpose);
764 $locationType = "Reference";
765 } elseif ($file_gui["size"] > 0) {
766 // lokal
767 // determine and create mob directory, move uploaded file to directory
768 $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
769 if (!is_dir($mob_dir)) {
770 $mob->createDirectory();
771 } else {
772 $dir = LegacyPathHelper::createRelativePath($mob_dir);
773 $old_files = $this->filesystem->finder()->in([$dir])->exclude([$dir . '/mob_vpreview.png'])->files();
774 foreach ($old_files as $file) {
775 $this->filesystem->delete($file->getPath());
776 }
777 }
778
779 $file_name = ilUtil::getASCIIFilename($_FILES['file_' . $purpose]['name']);
780 $file_name = str_replace(" ", "_", $file_name);
781
782 $file = $mob_dir . "/" . $file_name;
783 $title = $file_name;
784 $locationType = "LocalFile";
785 $location = $title;
786 ilUtil::moveUploadedFile($_FILES['file_' . $purpose]['tmp_name'], $file_name, $file);
788 }
789
790 // check if not automatic mimetype detection
791// if ($_POST["mimetype_" . $purpose] != "") {
792// $mediaItem->setFormat($_POST["mimetype_" . $purpose]);
793// } elseif ($mediaItem->getLocation() != "") {
794 $format = ilObjMediaObject::getMimeType($mediaItem->getLocation(), ($locationType == "Reference"));
795 $mediaItem->setFormat($format);
796// }
797
798 if (isset($file)) {
799 // get mime type, if not already set!
800 if (!isset($format)) {
801 $format = ilObjMediaObject::getMimeType($file, ($locationType == "Reference"));
802 }
803
804 // set real meta and object data
805 $mediaItem->setFormat($format);
806 $mediaItem->setLocation($location);
807 $mediaItem->setLocationType($locationType);
808 $mediaItem->setHAlign("Left");
809 $mediaItem->setHeight(self::isAudio($format)?0:180);
810 }
811
812 if ($purpose == "Standard") {
813 if (isset($title)) {
814 $mob->setTitle($title);
815 }
816 if (isset($format)) {
817 $mob->setDescription($format);
818 }
819 }
820
821 return $file;
822 }
823
827 public function updateCastItemObject()
828 {
829 $ilCtrl = $this->ctrl;
831 $ilLog = $this->log;
832
833 $this->checkPermission("write");
834
835 $this->initAddCastItemForm("edit");
836
837 if ($this->form_gui->checkInput()) {
838 // create new media cast item
839 include_once("./Services/News/classes/class.ilNewsItem.php");
840 $mc_item = new ilNewsItem($_GET["item_id"]);
841 $mob_id = $mc_item->getMobId();
842
843 // create dummy object in db (we need an id)
844 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
845 $mob = new ilObjMediaObject($mob_id);
846
847
848 foreach (ilObjMediaCast::$purposes as $purpose) {
849 if ($this->form_gui->getInput("delete_" . $purpose)) {
850 $mob->removeMediaItem($purpose);
851 $ilLog->write("Mcst: deleting purpose $purpose");
852 continue;
853 }
854 $media_item = $mob->getMediaItem($purpose);
855 $url_gui = $this->form_gui->getInput("url_" . $purpose);
856 $file_gui = $this->form_gui->getInput("file_" . $purpose);
857
858 if ($media_item == null) {
859 if ($purpose != "Standard" &&
860 ($url_gui || $file_gui["size"] > 0)) {
861 // check if we added an additional purpose when updating
862 // either by url or by file
863 $file = $this->createMediaItemForPurpose($mob, $purpose);
864 }
865 } else {
866 $file = $this->updateMediaItem($mob, $media_item);
867 }
868
869 if ($purpose == "Standard") {
870 $duration = $this->getDuration($file);
871 $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
872 $description = $this->form_gui->getInput("description");
873
874 $mob->setTitle($title);
875 $mob->setDescription($description);
876
877 $prevpic = $this->form_gui->getInput("preview_pic");
878 if ($prevpic["size"] > 0) {
879 $mob->uploadVideoPreviewPic($prevpic);
880 } else {
881 $prevpici = $this->form_gui->getItemByPostVar("preview_pic");
882 if ($prevpici->getDeletionFlag()) {
883 $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
884 }
885 }
886 }
887 }
888
889 // set real meta and object data
890 $mob->update();
891
892 //
893 // @todo: save usage
894 //
895
896 $news_set = new ilSetting("news");
897 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
898
899 $mc_item->setUserId($ilUser->getId());
900 if (isset($duration)) {
901 $mc_item->setPlaytime($duration);
902 }
903 $mc_item->setTitle($title);
904 $mc_item->setContent($description);
905 if ($enable_internal_rss) {
906 $mc_item->setVisibility($this->form_gui->getInput("visibility"));
907 }
908 $mc_item->update();
909
910 $ilCtrl->redirect($this, "listItems");
911 } else {
912 $this->populateFormFromPost();
913 }
914 }
915
920 {
921 $ilCtrl = $this->ctrl;
924 $ilTabs = $this->tabs;
925
926 $this->checkPermission("write");
927 $ilTabs->activateTab("edit_content");
928
929 if (!is_array($_POST["item_id"])) {
930 $this->listItemsObject();
931 return;
932 }
933
934 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
935 $c_gui = new ilConfirmationGUI();
936
937 // set confirm/cancel commands
938 $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteItems"));
939 $c_gui->setHeaderText($lng->txt("info_delete_sure"));
940 $c_gui->setCancel($lng->txt("cancel"), "listItems");
941 $c_gui->setConfirm($lng->txt("confirm"), "deleteItems");
942
943 // add items to delete
944 include_once("./Services/News/classes/class.ilNewsItem.php");
945 foreach ($_POST["item_id"] as $item_id) {
946 $item = new ilNewsItem($item_id);
947 $c_gui->addItem(
948 "item_id[]",
949 $item_id,
950 $item->getTitle(),
951 ilUtil::getImagePath("icon_mcst.svg")
952 );
953 }
954
955 $tpl->setContent($c_gui->getHTML());
956 }
957
961 public function deleteItemsObject()
962 {
963 $ilCtrl = $this->ctrl;
964
965 $this->checkPermission("write");
966
967 // delete all selected news items
968 foreach ($_POST["item_id"] as $item_id) {
969 $mc_item = new ilNewsItem($item_id);
970 $mc_item->delete();
971 }
972
973 $ilCtrl->redirect($this, "listItems");
974 }
975
979 public function downloadItemObject()
980 {
981 $ilCtrl = $this->ctrl;
983
984 $this->checkPermission("read");
985 $news_item = new ilNewsItem($_GET["item_id"]);
986 $this->object->handleLPUpdate($ilUser->getId(), $news_item->getMobId());
987 if (!$news_item->deliverMobFile($_GET["purpose"], (int) $_GET["presentation"])) {
988 $ilCtrl->redirect($this, "listItems");
989 }
990 exit;
991 }
992
996 public function determinePlaytimeObject()
997 {
998 $ilCtrl = $this->ctrl;
1000
1001 $mc_item = new ilNewsItem($_GET["item_id"]);
1002 $mob = $mc_item->getMobId();
1003 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1004 $mob = new ilObjMediaObject($mob);
1005 $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
1006 $m_item = $mob->getMediaItem("Standard");
1007 $file = $mob_dir . "/" . $m_item->getLocation();
1008 $duration = $this->getDuration($file);
1009 if ($duration != "00:00:00") {
1010 $mc_item->setPlaytime($duration);
1011 $mc_item->update();
1012 ilUtil::sendSuccess($lng->txt("mcst_set_playtime"), true);
1013 } else {
1014 ilUtil::sendFailure($lng->txt("mcst_unable_to_determin_playtime"), true);
1015 }
1016
1017 $ilCtrl->redirect($this, "listItems");
1018 }
1019
1025 public function infoScreenObject()
1026 {
1027 if (!$this->checkPermissionBool("read")) {
1028 $this->checkPermission("visible");
1029 }
1030 $this->ctrl->setCmd("showSummary");
1031 $this->ctrl->setCmdClass("ilinfoscreengui");
1032 $this->infoScreen();
1033 }
1034
1038 public function infoScreen()
1039 {
1040 $ilAccess = $this->access;
1042 $ilTabs = $this->tabs;
1043
1044 $ilTabs->activateTab("id_info");
1045
1046 if (!$this->checkPermissionBool("read")) {
1047 $this->checkPermission("visible");
1048 }
1049
1050 include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1051 $info = new ilInfoScreenGUI($this);
1052
1053 $info->enablePrivateNotes();
1054
1055 // general information
1056 $this->lng->loadLanguageModule("meta");
1057 $this->lng->loadLanguageModule("mcst");
1058 $med_items = $this->object->getItemsArray();
1059 $info->addSection($this->lng->txt("meta_general"));
1060 $info->addProperty(
1061 $this->lng->txt("mcst_nr_items"),
1062 (int) count($med_items)
1063 );
1064
1065 if (count($med_items) > 0) {
1066 $cur = current($med_items);
1067 $last = ilDatePresentation::formatDate(new ilDateTime($cur["creation_date"], IL_CAL_DATETIME));
1068 } else {
1069 $last = "-";
1070 }
1071
1072 $info->addProperty($this->lng->txt("mcst_last_submission"), $last);
1073
1074 // forward the command
1075 $this->ctrl->forwardCommand($info);
1076 }
1077
1082 public function setTabs()
1083 {
1084 $ilAccess = $this->access;
1085 $ilTabs = $this->tabs;
1086 $lng = $this->lng;
1087 $ilHelp = $this->help;
1088
1089 $ilHelp->setScreenIdComponent("mcst");
1090
1091 // list items
1092 if ($ilAccess->checkAccess('read', "", $this->object->getRefId())) {
1093 $ilTabs->addTab(
1094 "content",
1095 $lng->txt("content"),
1096 $this->ctrl->getLinkTarget($this, "showContent")
1097 );
1098 }
1099
1100 // info screen
1101 if ($ilAccess->checkAccess('visible', "", $this->object->getRefId()) ||
1102 $ilAccess->checkAccess('read', "", $this->object->getRefId())) {
1103 $ilTabs->addTab(
1104 "id_info",
1105 $lng->txt("info_short"),
1106 $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary")
1107 );
1108 }
1109
1110 // settings
1111 if ($ilAccess->checkAccess('write', "", $this->object->getRefId())) {
1112 $ilTabs->addTab(
1113 "id_settings",
1114 $lng->txt("settings"),
1115 $this->ctrl->getLinkTarget($this, "editSettings")
1116 );
1117 }
1118
1119 require_once 'Services/Tracking/classes/class.ilLearningProgressAccess.php';
1120 if (ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
1121 $ilTabs->addTab(
1122 'learning_progress',
1123 $lng->txt('learning_progress'),
1124 $this->ctrl->getLinkTargetByClass(array(__CLASS__, 'illearningprogressgui'), '')
1125 );
1126 }
1127
1128 // export
1129 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1130 $ilTabs->addTab(
1131 "export",
1132 $lng->txt("export"),
1133 $this->ctrl->getLinkTargetByClass("ilexportgui", "")
1134 );
1135 }
1136
1137 // edit permissions
1138 if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
1139 $ilTabs->addTab(
1140 "id_permissions",
1141 $lng->txt("perm_settings"),
1142 $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm")
1143 );
1144 }
1145 }
1146
1153 public function addContentSubTabs($a_active = "content")
1154 {
1155 $ilTabs = $this->tabs;
1156 $ilAccess = $this->access;
1157 $lng = $this->lng;
1158
1159 $ilTabs->addSubTab(
1160 "content",
1161 $lng->txt("view"),
1162 $this->ctrl->getLinkTarget($this, "showContent")
1163 );
1164
1165 if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) {
1166 $ilTabs->addSubTab(
1167 "manage",
1168 $lng->txt("mcst_manage"),
1169 $this->ctrl->getLinkTarget($this, "listItems")
1170 );
1171
1172 if ($this->object->getOrder() == ilObjMediaCast::ORDER_MANUAL) {
1173 $ilTabs->addSubTab(
1174 "sorting",
1175 $lng->txt("mcst_ordering"),
1176 $this->ctrl->getLinkTarget($this, "editOrder")
1177 );
1178 }
1179 }
1180
1181 $ilTabs->activateSubTab($a_active);
1182 $ilTabs->activateTab("content");
1183 }
1184
1185
1189 public function editSettingsObject()
1190 {
1191 $tpl = $this->tpl;
1192 $ilTabs = $this->tabs;
1193
1194 $this->checkPermission("write");
1195 $ilTabs->activateTab("id_settings");
1196
1197 $this->initSettingsForm();
1198 $tpl->setContent($this->form_gui->getHtml());
1199 }
1200
1204 public function initSettingsForm()
1205 {
1206 $tpl = $this->tpl;
1207 $lng = $this->lng;
1208 $ilCtrl = $this->ctrl;
1209 $obj_service = $this->object_service;
1210
1211 $lng->loadLanguageModule("mcst");
1212
1213 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1214 $this->form_gui = new ilPropertyFormGUI();
1215 $this->form_gui->setTitle($lng->txt("mcst_settings"));
1216
1217 // Title
1218 $tit = new ilTextInputGUI($lng->txt("title"), "title");
1219 $tit->setValue($this->object->getTitle());
1220 $tit->setRequired(true);
1221 $this->form_gui->addItem($tit);
1222
1223 // description
1224 $des = new ilTextAreaInputGUI($lng->txt("description"), "description");
1225 $des->setValue($this->object->getLongDescription());
1226 $this->form_gui->addItem($des);
1227
1228 $sh = new ilFormSectionHeaderGUI();
1229 $sh->setTitle($lng->txt("rep_activation_availability"));
1230 $this->form_gui->addItem($sh);
1231
1232 // Online
1233 $online = new ilCheckboxInputGUI($lng->txt("online"), "online");
1234 $online->setChecked($this->object->getOnline());
1235 $this->form_gui->addItem($online);
1236
1237 // presentation
1238 $sh = new ilFormSectionHeaderGUI();
1239 $sh->setTitle($lng->txt("obj_presentation"));
1240 $this->form_gui->addItem($sh);
1241
1242 // tile image
1243 $obj_service->commonSettings()->legacyForm($this->form_gui, $this->object)->addTileImage();
1244
1245 // Sorting
1246 $sort = new ilRadioGroupInputGUI($lng->txt("mcst_ordering"), "order");
1247 $sort->addOption(new ilRadioOption(
1248 $lng->txt("mcst_ordering_title"),
1250 ));
1251 $sort->addOption(new ilRadioOption(
1252 $lng->txt("mcst_ordering_creation_date_asc"),
1254 ));
1255 $sort->addOption(new ilRadioOption(
1256 $lng->txt("mcst_ordering_creation_date_desc"),
1258 ));
1259 $sort->addOption(new ilRadioOption(
1260 $lng->txt("mcst_ordering_manual"),
1262 ));
1263 $sort->setValue($this->object->getOrder());
1264 $this->form_gui->addItem($sort);
1265
1266 // view mode
1267 $options = array(
1268 ilObjMediaCast::VIEW_LIST => $lng->txt("mcst_list"),
1269 ilObjMediaCast::VIEW_GALLERY => $lng->txt("mcst_gallery")
1270 );
1271 $si = new ilRadioGroupInputGUI($this->lng->txt("mcst_viewmode"), "viewmode");
1272 $si->addOption(new ilRadioOption(
1273 $lng->txt("mcst_list"),
1275 ));
1276 $si->addOption(new ilRadioOption(
1277 $lng->txt("mcst_gallery"),
1279 ));
1280
1281 // $si->setOptions($options);
1282 $si->setValue($this->object->getViewMode());
1283 $this->form_gui->addItem($si);
1284
1285
1286 // Downloadable
1287 $downloadable = new ilCheckboxInputGUI($lng->txt("mcst_downloadable"), "downloadable");
1288 $downloadable->setChecked($this->object->getDownloadable());
1289 $downloadable->setInfo($lng->txt("mcst_downloadable_info"));
1290 $this->form_gui->addItem($downloadable);
1291
1292 $news_set = new ilSetting("news");
1293 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1294
1295 //Default Visibility
1296 if ($enable_internal_rss) {
1297 // webfeed
1298 $sh = new ilFormSectionHeaderGUI();
1299 $sh->setTitle($lng->txt("mcst_webfeed"));
1300 $this->form_gui->addItem($sh);
1301
1302 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "defaultaccess");
1303 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "0");
1304 $radio_option->setInfo($lng->txt("news_news_item_def_visibility_users_info"));
1305 $radio_group->addOption($radio_option);
1306 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "1");
1307 $radio_option->setInfo($lng->txt("news_news_item_def_visibility_public_info"));
1308 $radio_group->addOption($radio_option);
1309 $radio_group->setRequired(false);
1310 $radio_group->setValue($this->object->getDefaultAccess());
1311 #$ch->addSubItem($radio_group);
1312 $this->form_gui->addItem($radio_group);
1313
1314 //Extra Feed
1315 include_once("./Services/Block/classes/class.ilBlockSetting.php");
1316 $public_feed = ilBlockSetting::_lookup("news", "public_feed", 0, $this->object->getId());
1317 $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"), "extra_feed");
1318 $ch->setInfo($lng->txt("news_public_feed_info"));
1319 $ch->setChecked($public_feed);
1320 $this->form_gui->addItem($ch);
1321
1322 // keep minimal x number of items
1323 $ni = new ilNumberInputGUI($this->lng->txt("news_keep_minimal_x_items"), "keep_rss_min");
1324 $ni->setMaxValue(100);
1325 $ni->setMinValue(0);
1326 $ni->setMaxLength(3);
1327 $ni->setSize(3);
1328 $ni->setInfo($this->lng->txt("news_keep_minimal_x_items_info") . " (" .
1329 ilNewsItem::_lookupRSSPeriod() . " " . (ilNewsItem::_lookupRSSPeriod() == 1 ? $lng->txt("day") : $lng->txt("days")) . ")");
1330 $ni->setValue((int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $this->object->getId()));
1331 $ch->addSubItem($ni);
1332
1333 // Include Files in Pubic Items
1334 $incl_files = new ilCheckboxInputGUI($lng->txt("mcst_incl_files_in_rss"), "public_files");
1335 $incl_files->setChecked($this->object->getPublicFiles());
1336 $incl_files->setInfo($lng->txt("mcst_incl_files_in_rss_info"));
1337 #$ch->addSubItem($incl_files);
1338 $this->form_gui->addItem($incl_files);
1339 }
1340
1341 // Form action and save button
1342 $this->form_gui->addCommandButton("saveSettings", $lng->txt("save"));
1343 $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveSettings"));
1344 }
1345
1349 public function saveSettingsObject()
1350 {
1351 $ilCtrl = $this->ctrl;
1352 $ilTabs = $this->tabs;
1353 $obj_service = $this->object_service;
1354
1355 $this->checkPermission("write");
1356 $ilTabs->activateTab("id_settings");
1357
1358 $this->initSettingsForm();
1359 if ($this->form_gui->checkInput()) {
1360 $news_set = new ilSetting("news");
1361 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1362
1363 $this->object->setTitle($this->form_gui->getInput("title"));
1364 $this->object->setDescription($this->form_gui->getInput("description"));
1365 $this->object->setOnline($this->form_gui->getInput("online"));
1366 $this->object->setDownloadable($this->form_gui->getInput("downloadable"));
1367 $this->object->setOrder($this->form_gui->getInput("order"));
1368 $this->object->setViewMode($this->form_gui->getInput("viewmode"));
1369
1370 // tile image
1371 $obj_service->commonSettings()->legacyForm($this->form_gui, $this->object)->saveTileImage();
1372
1373 if ($enable_internal_rss) {
1374 $this->object->setPublicFiles($this->form_gui->getInput("public_files"));
1375 $this->object->setDefaultAccess($this->form_gui->getInput("defaultaccess"));
1376 }
1377 $this->object->update();
1378
1379 if ($enable_internal_rss) {
1380 include_once("./Services/Block/classes/class.ilBlockSetting.php");
1382 "news",
1383 "public_feed",
1384 $this->form_gui->getInput("extra_feed"),
1385 0,
1386 $this->object->getId()
1387 );
1388
1390 "news",
1391 "keep_rss_min",
1392 $this->form_gui->getInput("keep_rss_min"),
1393 0,
1394 $this->object->getId()
1395 );
1396 }
1397
1398 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1399 $ilCtrl->redirect($this, "editSettings");
1400 } else {
1401 $this->form_gui->setValuesByPost();
1402 $this->tpl->setContent($this->form_gui->getHTML());
1403 }
1404 }
1405
1406 // add media cast to locator
1407 public function addLocatorItems()
1408 {
1409 $ilLocator = $this->locator;
1410
1411 if (is_object($this->object)) {
1412 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listItems"), "", $_GET["ref_id"]);
1413 }
1414 }
1415
1416 public static function _goto($a_target)
1417 {
1418 global $DIC;
1419
1420 $ilAccess = $DIC->access();
1421 $ilErr = $DIC["ilErr"];
1422 $lng = $DIC->language();
1423
1424 if ($ilAccess->checkAccess("read", "", $a_target)) {
1425 $_GET["cmd"] = "showContent";
1426 $_GET["ref_id"] = $a_target;
1427 $_GET["baseClass"] = "ilmediacasthandlergui";
1428 $_GET["cmdClass"] = "ilobjmediacastgui";
1429 include("ilias.php");
1430 exit;
1431 } elseif ($ilAccess->checkAccess("visible", "", $a_target)) {
1432 ilObjectGUI::_gotoRepositoryNode($a_target, "infoScreen");
1433 } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
1434 ilUtil::sendFailure(sprintf(
1435 $lng->txt("msg_no_perm_read_item"),
1437 ));
1439 }
1440
1441 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1442 }
1443
1450 protected static function isAudio($extension)
1451 {
1452 return strpos($extension, "audio") !== false;
1453 }
1454
1461 protected function getMediaItem($id)
1462 {
1463 include_once("./Services/News/classes/class.ilNewsItem.php");
1464 $this->mcst_item = new ilNewsItem($id);
1465 // create dummy object in db (we need an id)
1466 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1467 $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1468 return $mob->getMediaItem("Standard");
1469 }
1470
1477 protected function getMediaItems($id)
1478 {
1479 include_once("./Services/News/classes/class.ilNewsItem.php");
1480 $this->mcst_item = new ilNewsItem($id);
1481 // create dummy object in db (we need an id)
1482 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1483 $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1484 return $mob->getMediaItems();
1485 }
1486
1487 private function populateFormFromPost()
1488 {
1489 $tpl = $this->tpl;
1490 //issue: we have to display the current settings
1491 // problem: POST does not contain values of disabled textfields
1492 // solution: use hidden field and label to display-> here we need to synchronize the labels
1493 // with the values from the hidden fields.
1494 foreach (ilObjMediaCast::$purposes as $purpose) {
1495 if ($_POST["value_" . $purpose]) {
1496 $_POST["label_value_" . $purpose] = $_POST["value_" . $purpose];
1497 }
1498 }
1499
1500 $this->form_gui->setValuesByPost();
1501 $tpl->setContent($this->form_gui->getHTML());
1502 }
1503
1504 protected function editOrderObject()
1505 {
1506 $ilTabs = $this->tabs;
1507 $lng = $this->lng;
1508 $tpl = $this->tpl;
1509
1510 $this->checkPermission("write");
1511 $ilTabs->activateTab("edit_content");
1512
1513 $this->addContentSubTabs("sorting");
1514
1515 // sort by order setting
1516 switch ($this->object->getOrder()) {
1520 return $this->listItemsObject();
1521
1523 // sub-tabs
1524 break;
1525 }
1526
1527 include_once("./Modules/MediaCast/classes/class.ilMediaCastTableGUI.php");
1528 $table_gui = new ilMediaCastTableGUI($this, "editOrder", true);
1529
1530 $table_gui->setTitle($lng->txt("mcst_media_cast"));
1531 $table_gui->setData($this->object->getSortedItemsArray());
1532
1533 $table_gui->addCommandButton("saveOrder", $lng->txt("mcst_save_order"));
1534
1535 $tpl->setContent($table_gui->getHTML());
1536 }
1537
1538 public function saveOrderObject()
1539 {
1540 $lng = $this->lng;
1541
1542 asort($_POST["item_id"]);
1543
1544 $items = array();
1545 foreach (array_keys($_POST["item_id"]) as $id) {
1546 $items[] = $id;
1547 }
1548 $this->object->saveOrder($items);
1549
1550 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
1551 $this->ctrl->redirect($this, "editOrder");
1552 }
1553
1557
1564 public function showContentObject()
1565 {
1566 $tpl = $this->tpl;
1568
1569 // need read events for parent for LP statistics
1570 require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
1572 "mcst",
1573 $this->object->getRefId(),
1574 $this->object->getId(),
1575 $ilUser->getId()
1576 );
1577
1578 // trigger LP update
1579 require_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
1580 ilLPStatusWrapper::_updateStatus($this->object->getId(), $ilUser->getId());
1581
1582 if ($this->object->getViewMode() == ilObjMediaCast::VIEW_GALLERY) {
1583 $this->showGallery();
1584 } else {
1585 $this->listItemsObject(true);
1586 }
1587
1588 $tpl->setPermanentLink($this->object->getType(), $this->object->getRefId());
1589 }
1590
1591 public function showGallery()
1592 {
1593 $tpl = $this->tpl;
1594 $ilTabs = $this->tabs;
1595 $ilCtrl = $this->ctrl;
1596
1597 $tpl->addJavascript("./Modules/MediaCast/js/MediaCast.js");
1598
1599 $ilTabs->activateTab("content");
1600
1601 $this->addContentSubTabs("content");
1602
1603 $ctpl = new ilTemplate("tpl.mcst_content.html", true, true, "Modules/MediaCast");
1604
1605 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1606 require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
1607 foreach ($this->object->getSortedItemsArray() as $item) {
1608 $mob = new ilObjMediaObject($item["mob_id"]);
1609 $med = $mob->getMediaItem("Standard");
1610
1611 $ctpl->setCurrentBlock("item");
1612 $ctpl->setVariable("TITLE", $item["title"]);
1613 $ctpl->setVariable("TIME", $item["playtime"]);
1614 $ctpl->setVariable("ID", $item["id"]);
1615
1616 if ($mob->getVideoPreviewPic() != "") {
1617 $ctpl->setVariable(
1618 "PREVIEW_PIC",
1619 ilUtil::img(ilWACSignedPath::signFile($mob->getVideoPreviewPic()), $item["title"], 320, 240)
1620 );
1621 } else {
1622 $ctpl->setVariable(
1623 "PREVIEW_PIC",
1624 ilUtil::img(ilUtil::getImagePath("mcst_preview.svg"), $item["title"], 320, 240)
1625 );
1626 }
1627
1628 // player
1629 if (is_object($med)) {
1630 include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
1631
1632 // the news id will be used as player id, see also ilMediaCastTableGUI
1633 $mpl = new ilMediaPlayerGUI(
1634 $item["id"],
1635 $ilCtrl->getLinkTarget($this, "handlePlayerEvent", "", true, false)
1636 );
1637
1638 if (strcasecmp("Reference", $med->getLocationType()) == 0) {
1639 $mpl->setFile(ilWACSignedPath::signFile($med->getLocation()));
1640 } else {
1641 $path_to_file = ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
1642 $mpl->setFile(ilWACSignedPath::signFile($path_to_file));
1643 }
1644 $mpl->setMimeType($med->getFormat());
1645 //$mpl->setDisplayHeight($med->getHeight());
1646 //$mpl->setDisplayHeight("480");
1647 //$mpl->setDisplayWidth("320px");
1648 $mpl->setVideoPreviewPic(ilWACSignedPath::signFile($mob->getVideoPreviewPic()));
1649 $mpl->setTitle($item["title"]);
1650 $mpl->setDescription($item["content"]);
1651 $mpl->setForceAudioPreview(true);
1652 if ($this->object->getDownloadable()) {
1653 $ilCtrl->setParameterByClass("ilobjmediacastgui", "item_id", $item["id"]);
1654 $ilCtrl->setParameterByClass("ilobjmediacastgui", "purpose", "Standard");
1655 $mpl->setDownloadLink($ilCtrl->getLinkTargetByClass("ilobjmediacastgui", "downloadItem"));
1656 }
1657 $med_alt = $mob->getMediaItem("VideoAlternative");
1658 if (is_object($med_alt)) {
1659 $mpl->setAlternativeVideoFile(ilWACSignedPath::signFile(ilObjMediaObject::_getURL($mob->getId()) . "/" .
1660 $med_alt->getLocation()));
1661 $mpl->setAlternativeVideoMimeType($med_alt->getFormat());
1662 }
1663
1664 $ctpl->setVariable("PLAYER", $mpl->getPreviewHtml());
1665 }
1666
1667
1668 $ctpl->parseCurrentBlock();
1669 }
1670
1671 $feed_icon_html = $this->getFeedIconsHTML();
1672
1673 if ($feed_icon_html != "") {
1674 $feed_icon_html = '<p>' . $feed_icon_html . '</p>';
1675 }
1676
1677 $tpl->setContent($feed_icon_html . $ctpl->get());
1678 }
1679
1686 public function convertFileObject()
1687 {
1688 $ilCtrl = $this->ctrl;
1689
1690 $this->checkPermission("write");
1691
1692 $this->mcst_item = new ilNewsItem($_GET["item_id"]);
1693 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1694 $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1695
1696 $target_purpose = ilUtil::stripSlashes($_POST["target_purpose"]);
1697 $target_format = ilUtil::stripSlashes($_POST["target_format"]);
1698
1699 try {
1700 include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
1701 $med = $mob->getMediaItem("Standard");
1702 $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $med->getLocation();
1703 $new_file = ilFFmpeg::convert($mob_file, $target_format);
1705 $pi = pathinfo($new_file);
1706 $med = $mob->getMediaItem($target_purpose);
1707 if (!is_object($med)) {
1708 $med = new ilMediaItem();
1709 $med->setMobId($mob->getId());
1710 $mob->addMediaItem($med);
1711 $mob->update();
1712 $med->setPurpose($target_purpose);
1713 }
1714 $med->setFormat($target_format);
1715 $med->setLocation($pi["basename"]);
1716 $med->setLocationType("LocalFile");
1717 $med->update();
1718
1719 $add = (is_array($ret) && count($ret) > 0)
1720 ? "<br />" . implode("<br />", $ret)
1721 : "";
1722
1723 ilUtil::sendInfo($this->lng->txt("mcst_converted_file") . $add, true);
1724 } catch (ilException $e) {
1726 $add = (is_array($ret) && count($ret) > 0)
1727 ? "<br />" . implode("<br />", $ret)
1728 : "";
1729 ilUtil::sendFailure($e->getMessage() . $add, true);
1730 }
1731
1732
1733 $ilCtrl->redirect($this, "editCastItem");
1734 }
1735
1743 {
1744 $ilCtrl = $this->ctrl;
1745
1746 $this->checkPermission("write");
1747
1748 $this->mcst_item = new ilNewsItem($_GET["item_id"]);
1749 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1750 $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1751
1752 try {
1753 $sec = (int) $_POST["sec"];
1754 if ($sec < 0) {
1755 $sec = 0;
1756 }
1757 if ($mob->getVideoPreviewPic() != "") {
1758 $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
1759 }
1760 include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
1761 $med = $mob->getMediaItem("Standard");
1762 $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $med->getLocation();
1763 $new_file = ilFFmpeg::extractImage(
1764 $mob_file,
1765 "mob_vpreview.png",
1766 ilObjMediaObject::_getDirectory($mob->getId()),
1767 $sec
1768 );
1769
1770 if ($new_file != "") {
1771 ilUtil::sendInfo($this->lng->txt("mcst_image_extracted"), true);
1772 } else {
1773 ilUtil::sendFailure($this->lng->txt("mcst_no_extraction_possible"), true);
1774 }
1775 } catch (ilException $e) {
1776 if (DEVMODE == 1) {
1778 $add = (is_array($ret) && count($ret) > 0)
1779 ? "<br />" . implode("<br />", $ret)
1780 : "";
1781 }
1782 ilUtil::sendFailure($e->getMessage() . $add, true);
1783 }
1784
1785
1786 $ilCtrl->redirect($this, "editCastItem");
1787 }
1788
1795 public function handlePlayerEventObject()
1796 {
1797 if ($_GET["event"] == "play") {
1798 $player = explode("_", $_GET["player"]);
1799 $news_id = (int) $player[1];
1800 include_once("./Services/News/classes/class.ilNewsItem.php");
1801 $item = new ilNewsItem($news_id);
1802 $item->increasePlayCounter();
1803
1804 $mob_id = $item->getMobId();
1805 if ($mob_id) {
1807 $this->object->handleLPUpdate($ilUser->getId(), $mob_id);
1808 }
1809 }
1810 exit;
1811 }
1812
1819 {
1820 $mob_id = (int) $_GET["mob_id"];
1821 if ($mob_id > 0) {
1823 $this->object->handleLPUpdate($ilUser->getId(), $mob_id);
1824 }
1825 exit;
1826 }
1827
1832 protected function afterUpload($mob_id)
1833 {
1834 $mob = new ilObjMediaObject($mob_id);
1835 $med_item = $mob->getMediaItem("Standard");
1836 $med_item->determineDuration();
1837
1838 $this->addMobsToCast([$mob_id]);
1839 }
1840
1846 protected function afterUrlSaving($mob_id, $long_desc)
1847 {
1848 $this->addMobsToCast([$mob_id], $long_desc);
1849 }
1850
1856 protected function addMobsToCast($mob_ids, $long_desc = "")
1857 {
1860
1861 $item_ids = [];
1862 foreach ($mob_ids as $mob_id) {
1863 $item_ids[] = $this->object->addMobToCast($mob_id, $user->getId(), $long_desc);
1864 }
1865
1866 if (count($item_ids) == 1) {
1867 $ctrl->setParameter($this, "item_id", $item_ids[0]);
1868 $ctrl->setParameter($this, "pupose", "Standard");
1869 $ctrl->redirect($this, "editCastItem");
1870 }
1871 $ctrl->redirect($this, "listItems");
1872 }
1873
1874
1879 protected function afterPoolInsert($mob_ids)
1880 {
1881 $this->addMobsToCast($mob_ids);
1882 }
1883
1884 protected function handleAutoplayTriggerObject()
1885 {
1886 $this->user->writePref("mcst_autoplay", (int) $_GET["autoplay"]);
1887 exit;
1888 }
1889}
user()
Definition: user.php:4
$section
Definition: Utf8Test.php:83
$location
Definition: buildRTE.php:44
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class FileNotFoundException Indicates that a file is missing or not found.
Class IOException Indicates general problems with the input or output operations.
Definition: IOException.php:13
Class LegacyPathHelper The legacy path helper provides convenient functions for the integration of th...
const IL_CAL_DATETIME
error($a_errmsg)
set error message @access public
const NEWS_AUDIO
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
static _recordReadEvent( $a_type, $a_ref_id, $obj_id, $usr_id, $isCatchupWriteEvents=true, $a_ext_rc=false, $a_ext_time=false)
Records a read event and catches up with write events.
This class represents a checkbox property in a property form.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
Confirmation screen class.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
This class represents a duration (typical hh:mm:ss) property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Export User Interface Class.
static enabled()
Checks, whether FFmpeg support is enabled (path is set in the setup)
static convert($a_file, $a_target_mime, $a_target_dir="", $a_target_filename="")
Convert file to target mime type.
static getLastReturnValues()
Get last return values.
static supportsImageExtraction($a_mime)
Check if mime type supports image extraction.
static extractImage( $a_file, $a_target_filename, $a_target_dir="", $a_sec=1)
Extract image from video file.
This class represents a file property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
This class represents an image file property in a property form.
Class ilInfoScreenGUI.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static checkAccess($a_ref_id, $a_allow_only_read=true)
check access to learning progress
Class ilObjUserTrackingGUI.
Analyzes media files.
static _getInstance()
get singleton instance
TableGUI class for table NewsForContext.
setAllSuffixes($a_val)
Set All suffixes.
Class ilMediaItem Media Item, component of a media object (file or reference)
User interface for media player.
static _lookupRSSPeriod()
This class represents a non editable value in a property form.
This class represents a number property in a property form.
Class ilObjMediaCastGUI.
initAddCastItemForm($a_mode="create")
Init add cast item form.
convertFileObject()
Convert file object.
determinePlaytimeObject()
Delete news items.
getDuration($file)
get duration from form or from file analyzer
saveCastItemObject()
Save new cast item.
afterUrlSaving($mob_id, $long_desc)
After mob upload.
editCastItemObject()
Edit media cast item.
updateMediaItem($mob, &$mediaItem)
update media item from form
getMediaItems($id)
get MediaItems for id and updates local variable mcst_item
handlePlayerEventObject()
Handle player event.
executeCommand()
execute command
infoScreen()
show information screen
addLocatorItems()
should be overwritten to add object specific items (repository items are preloaded)
addContentSubTabs($a_active="content")
Add content subtabs.
extractPreviewImageObject()
Extract preview image.
getCastItemValues()
Get cast item values into form.
afterSave(ilObject $newObj)
save object @access public
saveSettingsObject()
Save Settings.
downloadItemObject()
Download news media item.
__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output=true)
Constructor @access public.
static isAudio($extension)
detect audio mimetype
afterPoolInsert($mob_ids)
After pool insert.
updateCastItemObject()
Update cast item.
listItemsObject($a_presentation_mode=false)
List items of media cast.
initSettingsForm()
Init Settings Form.
editSettingsObject()
Edit settings.
deleteItemsObject()
Delete news items.
initCreationForms($a_new_type)
Init creation froms.
afterUpload($mob_id)
After mob upload.
infoScreenObject()
this one is called from the info button in the repository not very nice to set cmdClass/Cmd manually,...
addMobsToCast($mob_ids, $long_desc="")
After mob upload.
getFeedIconsHTML()
Get feed icons HTML.
addCastItemObject()
Add media cast item.
setTabs()
get tabs @access public
createMediaItemForPurpose($mob, $purpose)
handle media item for given purpose
confirmDeletionItemsObject()
Confirmation Screen.
getMediaItem($id)
get MediaItem for id and updates local variable mcst_item
Class ilObjMediaObject.
static getMimeType($a_file, $a_external=null)
get mime type for file
static _getDirectory($a_mob_id)
Get absolute directory.
static _getURL($a_mob_id)
get directory for files of media object (static)
GUI class for the workflow of copying objects.
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
initImportForm($a_new_type)
Init object import form.
prepareOutput($a_show_subobjects=true)
prepare output
initCreateForm($a_new_type)
Init object creation form.
static _gotoRepositoryNode($a_ref_id, $a_cmd="frameset")
Goto repository root.
static _gotoRepositoryRoot($a_raise_error=false)
Goto repository root.
fillCloneTemplate($a_tpl_varname, $a_type)
Fill object clone template This method can be called from any object GUI class that wants to offer ob...
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
addHeaderAction()
Add header action menu.
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
getRefId()
get reference id @access public
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
static get($a_type, $a_href="")
Get icon html.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a regular expression input property in a property form.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
static signFile($path_to_file)
const CLIENT_ID
Definition: constants.php:39
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24
help()
Definition: help.php:2
$ilUser
Definition: imgupload.php:18
Interface Filesystem The filesystem interface provides the public interface for the Filesystem servic...
Definition: Filesystem.php:22
exit
Definition: login.php:29
$format
Definition: metadata.php:218
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
$url