ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 require_once "./Services/Object/classes/class.ilObjectGUI.php";
6 
19 {
23  protected $tabs;
24 
28  protected $log;
29 
33  protected $error;
34 
38  protected $help;
39 
40 
41  private $additionalPurposes = array("VideoPortable", "AudioPortable");
42  private $purposeSuffixes = array();
43  private $mimeTypes = array();
44 
49  public function __construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
50  {
51  global $DIC;
52 
53  $this->ctrl = $DIC->ctrl();
54  $this->lng = $DIC->language();
55  $this->user = $DIC->user();
56  $this->tabs = $DIC->tabs();
57  $this->tpl = $DIC["tpl"];
58  $this->access = $DIC->access();
59  $this->toolbar = $DIC->toolbar();
60  $this->log = $DIC["ilLog"];
61  $this->error = $DIC["ilErr"];
62  $this->help = $DIC["ilHelp"];
63  $this->locator = $DIC["ilLocator"];
64  $ilCtrl = $DIC->ctrl();
65  $lng = $DIC->language();
66 
67  $this->type = "mcst";
68  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
69  $lng->loadLanguageModule("mcst");
70  $lng->loadLanguageModule("news");
71  $lng->loadLanguageModule("rep");
72 
73  $ilCtrl->saveParameter($this, "item_id");
74 
75  include_once("./Modules/MediaCast/classes/class.ilMediaCastSettings.php");
77  $this->purposeSuffixes = $settings->getPurposeSuffixes();
78  $this->mimeTypes = array();
79  $mime_types = $settings->getMimeTypes();
80  foreach ($mime_types as $mt) {
81  $this->mimeTypes[$mt] = $mt;
82  }
83 
84  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
85  foreach (ilMimeTypeUtil::getExt2MimeMap() as $mt) {
86  $this->mimeTypes[$mt] = $mt;
87  }
88  asort($this->mimeTypes);
89  }
90 
91  public function executeCommand()
92  {
94  $ilTabs = $this->tabs;
95 
96  $next_class = $this->ctrl->getNextClass($this);
97  $cmd = $this->ctrl->getCmd();
98  $this->prepareOutput();
99 
100  switch ($next_class) {
101  case "ilinfoscreengui":
102  if (!$this->checkPermissionBool("read")) {
103  $this->checkPermission("visible");
104  }
105  $this->infoScreen(); // forwards command
106  break;
107 
108  case "ilexportgui":
109 // $this->prepareOutput();
110  $ilTabs->activateTab("export");
111  include_once("./Services/Export/classes/class.ilExportGUI.php");
112  $exp_gui = new ilExportGUI($this);
113  $exp_gui->addFormat("xml");
114  $ret = $this->ctrl->forwardCommand($exp_gui);
115 // $this->tpl->show();
116  break;
117 
118  case 'ilpermissiongui':
119  $ilTabs->activateTab("id_permissions");
120  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
121  $perm_gui = new ilPermissionGUI($this);
122  $ret = $this->ctrl->forwardCommand($perm_gui);
123  break;
124 
125  case 'ilobjectcopygui':
126  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
127  $cp = new ilObjectCopyGUI($this);
128  $cp->setType('mcst');
129  $this->ctrl->forwardCommand($cp);
130  break;
131 
132  case "ilcommonactiondispatchergui":
133  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
135  $this->ctrl->forwardCommand($gui);
136  break;
137 
138  case "illearningprogressgui":
139  $ilTabs->activateTab('learning_progress');
140  require_once 'Services/Tracking/classes/class.ilLearningProgressGUI.php';
141  $new_gui = new ilLearningProgressGUI(
143  $this->object->getRefId(),
144  $_GET['user_id'] ? $_GET['user_id'] : $ilUser->getId()
145  );
146  $this->ctrl->forwardCommand($new_gui);
147  $this->tabs_gui->setTabActive('learning_progress');
148  break;
149 
150  default:
151  if (!$cmd) {
152  $cmd = "infoScreen";
153  }
154  $cmd .= "Object";
155  if ($cmd != "infoScreenObject") {
156  $this->checkPermission("read");
157  } else {
158  $this->checkPermission("visible");
159  }
160  $this->$cmd();
161 
162  break;
163  }
164 
165  $this->addHeaderAction();
166 
167  return true;
168  }
169 
170  protected function initCreationForms($a_new_type)
171  {
172  $forms = array(self::CFORM_NEW => $this->initCreateForm($a_new_type),
173  self::CFORM_IMPORT => $this->initImportForm($a_new_type),
174  self::CFORM_CLONE => $this->fillCloneTemplate(null, $a_new_type));
175 
176  return $forms;
177  }
178 
183  public function afterSave(ilObject $newObj)
184  {
185  // always send a message
186  ilUtil::sendSuccess($this->lng->txt("object_added"), true);
187  ilUtil::redirect("ilias.php?baseClass=ilMediaCastHandlerGUI&ref_id=" . $newObj->getRefId() . "&cmd=editSettings");
188  }
189 
193  public function listItemsObject($a_presentation_mode = false)
194  {
195  $tpl = $this->tpl;
196  $lng = $this->lng;
197  $ilAccess = $this->access;
198  $ilTabs = $this->tabs;
199  $ilToolbar = $this->toolbar;
200 
201  $this->checkPermission("read");
202 
203  if ($a_presentation_mode) {
204  $this->addContentSubTabs("content");
205  } else {
206  $this->addContentSubTabs("manage");
207  }
208 
209  $med_items = $this->object->getSortedItemsArray();
210 
211  include_once("./Modules/MediaCast/classes/class.ilMediaCastTableGUI.php");
212  if ($a_presentation_mode) {
213  $table_gui = new ilMediaCastTableGUI($this, "showContent", false, true);
214  } else {
215  $table_gui = new ilMediaCastTableGUI($this, "listItems");
216  }
217 
218  $table_gui->setData($med_items);
219 
220  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]) && !$a_presentation_mode) {
221  $ilToolbar->addButton($lng->txt("add"), $this->ctrl->getLinkTarget($this, "addCastItem"));
222 
223  $table_gui->addMultiCommand("confirmDeletionItems", $lng->txt("delete"));
224  $table_gui->setSelectAllCheckbox("item_id");
225  }
226 
227  $feed_icon_html = $this->getFeedIconsHTML();
228  if ($feed_icon_html != "") {
229  $table_gui->setHeaderHTML($feed_icon_html);
230  }
231 
232  $tpl->setContent($table_gui->getHTML());
233  }
234 
241  public function getFeedIconsHTML()
242  {
243  $lng = $this->lng;
244 
245  $html = "";
246 
247  include_once("./Services/Block/classes/class.ilBlockSetting.php");
248  $public_feed = ilBlockSetting::_lookup(
249  "news",
250  "public_feed",
251  0,
252  $this->object->getId()
253  );
254 
255  // rss icon/link
256  if ($public_feed) {
257  $news_set = new ilSetting("news");
258  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
259 
260  if ($enable_internal_rss) {
261  // create dummy object in db (we need an id)
262  $items = $this->object->getItemsArray();
263  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
264  $html = "";
265  foreach (ilObjMediaCast::$purposes as $purpose) {
266  foreach ($items as $id => $item) {
267  $mob = new ilObjMediaObject($item["mob_id"]);
268  $mob->read();
269  if ($mob->hasPurposeItem($purpose)) {
270  if ($html == "") {
271  $html = " ";
272  }
273  $url = ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&" . "ref_id=" . $_GET["ref_id"] . "&purpose=$purpose";
274  $title = $lng->txt("news_feed_url");
275 
276  include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
277  switch (strtolower($purpose)) {
278  case "audioportable":
281  break;
282 
283  case "videoportable":
286  break;
287 
288  default:
289  $type1 = ilRSSButtonGUI::ICON_RSS;
291  break;
292  }
293  $row1 .= "&nbsp;" . ilRSSButtonGUI::get($type1, $url);
294  if ($this->object->getPublicFiles()) {
295  $url = preg_replace("/https?/i", "itpc", $url);
296  $title = $lng->txt("news_feed_url");
297 
298  include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
299  $row2 .= "&nbsp;" . ilRSSButtonGUI::get($type2, $url);
300  }
301  break;
302  }
303  }
304  }
305  if ($html != "") {
306  $html .= $row1;
307  if ($row2 != "") {
308  $html .= $row2;
309  }
310  }
311  }
312  }
313  return $html;
314  }
315 
316 
320  public function addCastItemObject()
321  {
322  $tpl = $this->tpl;
323 
324  $this->checkPermission("write");
325 
326  $this->initAddCastItemForm();
327  $tpl->setContent($this->form_gui->getHTML());
328  }
329 
333  public function editCastItemObject()
334  {
335  $tpl = $this->tpl;
336  $ilToolbar = $this->toolbar;
338 
339  $this->checkPermission("write");
340 
341  // conversion toolbar
342  include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
343  if (ilFFmpeg::enabled()) {
344  $this->mcst_item = new ilNewsItem($_GET["item_id"]);
345  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
346  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
347 
348  $conv_cnt = 0;
349  // we had other purposes as source as well, but
350  // currently only "Standard" is implemented in the convertFile method
351  foreach (array("Standard") as $p) {
352  /*
353  $med = $mob->getMediaItem($p);
354  if (is_object($med))
355  {
356  $options = ilFFmpeg::getPossibleTargetMimeTypes($med->getFormat());
357  if (count($options) > 0)
358  {
359  if ($conv_cnt > 0)
360  {
361  $ilToolbar->addSeparator();
362  }
363 
364  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
365  $si = new ilSelectInputGUI($this->lng->txt("mcst_conv_".
366  strtolower($p)."_to"), "target_format");
367  $si->setOptions($options);
368  $ilToolbar->addInputItem($si, true);
369 
370  $si = new ilSelectInputGUI(", ".$this->lng->txt("mcst_target").": ",
371  "target_purpose");
372  $si->setOptions(array("Standard" => $this->lng->txt("mcst_purpose_standard"),
373  "VideoAlternative" => $this->lng->txt("mcst_purpose_videoalternative")
374  ));
375  $si->setValue($p);
376  $ilToolbar->addInputItem($si, true);
377 
378  $ilToolbar->addFormButton($this->lng->txt("mcst_convert"), "convertFile");
379 
380  $conv_cnt++;
381  }
382  }
383  */
384 
385  $med = $mob->getMediaItem($p);
386  if (is_object($med)) {
387  if (ilFFmpeg::supportsImageExtraction($med->getFormat())) {
388  // second
389  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
390  $ni = new ilTextInputGUI($this->lng->txt("mcst_second"), "sec");
391  $ni->setMaxLength(4);
392  $ni->setSize(4);
393  $ni->setValue(1);
394  $ilToolbar->addInputItem($ni, true);
395 
396  $ilToolbar->addFormButton($this->lng->txt("mcst_extract_preview_image"), "extractPreviewImage");
397  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
398  }
399  }
400 
401  /*if ($conv_cnt > 0)
402  {
403  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
404  }*/
405  }
406  }
407 
408  $this->initAddCastItemForm("edit");
409  $this->getCastItemValues();
410  $tpl->setContent($this->form_gui->getHTML());
411  }
412 
416  public function initAddCastItemForm($a_mode = "create")
417  {
418  $lng = $this->lng;
420  $ilTabs = $this->tabs;
421 
422  $this->checkPermission("write");
423  $ilTabs->activateTab("edit_content");
424 
425  $lng->loadLanguageModule("mcst");
426 
427  $news_set = new ilSetting("news");
428  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
429 
430  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
431  $this->form_gui = new ilPropertyFormGUI();
432  $this->form_gui->setMultipart(true);
433 
434  // Property Title
435  $text_input = new ilTextInputGUI($lng->txt("title"), "title");
436  $text_input->setMaxLength(200);
437  $this->form_gui->addItem($text_input);
438 
439  // Property Content
440  $text_area = new ilTextAreaInputGUI($lng->txt("description"), "description");
441  $text_area->setRequired(false);
442  $this->form_gui->addItem($text_area);
443 
444  // Property Visibility
445  if ($enable_internal_rss) {
446  $radio_group = new ilRadioGroupInputGUI($lng->txt("access_scope"), "visibility");
447  $radio_option = new ilRadioOption($lng->txt("access_users"), "users");
448  $radio_group->addOption($radio_option);
449  $radio_option = new ilRadioOption($lng->txt("access_public"), "public");
450  $radio_group->addOption($radio_option);
451  $radio_group->setInfo($lng->txt("mcst_visibility_info"));
452  $radio_group->setRequired(true);
453  $radio_group->setValue($this->object->getDefaultAccess() == 0 ? "users" : "public");
454  $this->form_gui->addItem($radio_group);
455  }
456 
457  // Duration
458  $dur = new ilDurationInputGUI($lng->txt("mcst_duration"), "duration");
459  $dur->setInfo($lng->txt("mcst_duration_info"));
460  $dur->setShowDays(false);
461  $dur->setShowHours(true);
462  $dur->setShowSeconds(true);
463  $this->form_gui->addItem($dur);
464 
465  foreach (ilObjMediaCast::$purposes as $purpose) {
466  if ($purpose == "VideoAlternative" &&
467  $a_mode == "create") {
468  continue;
469  }
470 
472  $section->setTitle($lng->txt("mcst_" . strtolower($purpose) . "_title"));
473  $this->form_gui->addItem($section);
474  if ($a_mode != "create") {
475  $value = new ilHiddenInputGUI("value_" . $purpose);
476  $label = new ilNonEditableValueGUI($lng->txt("value"));
477  $label->setPostVar("label_value_" . $purpose);
478  $label->setInfo($lng->txt("mcst_current_value_info"));
479  $this->form_gui->addItem($label);
480  $this->form_gui->addItem($value);
481  }
482  $file = new ilFileInputGUI($lng->txt("file"), "file_" . $purpose);
483  $file->setSuffixes($this->purposeSuffixes[$purpose]);
484  $this->form_gui->addItem($file);
485  $text_input = new ilRegExpInputGUI($lng->txt("url"), "url_" . $purpose);
486  $text_input->setPattern("/https?\:\/\/.+/i");
487  $text_input->setInfo($lng->txt("mcst_reference_info"));
488  $this->form_gui->addItem($text_input);
489  if ($purpose != "Standard") {
490  $clearCheckBox = new ilCheckboxInputGUI();
491  $clearCheckBox->setPostVar("delete_" . $purpose);
492  $clearCheckBox->setTitle($lng->txt("mcst_clear_purpose_title"));
493  $this->form_gui->addItem($clearCheckBox);
494  } else {
495 
496  // mime type selection
497  $mimeTypeSelection = new ilSelectInputGUI();
498  $mimeTypeSelection->setPostVar("mimetype_" . $purpose);
499  $mimeTypeSelection->setTitle($lng->txt("mcst_mimetype"));
500  $mimeTypeSelection->setInfo($lng->txt("mcst_mimetype_info"));
501  $options = array("" => $lng->txt("mcst_automatic_detection"));
502  $options = array_merge($options, $this->mimeTypes);
503  $mimeTypeSelection->setOptions($options);
504  $this->form_gui->addItem($mimeTypeSelection);
505 
506  // preview picure
507  $pp = new ilImageFileInputGUI($lng->txt("mcst_preview_picture"), "preview_pic");
508  $pp->setSuffixes(array("png", "jpeg", "jpg"));
509  $pp->setInfo($lng->txt("mcst_preview_picture_info") . " mp4, mp3, png, jp(e)g, gif");
510  $this->form_gui->addItem($pp);
511  }
512  }
513 
514  // save/cancel button
515  if ($a_mode == "create") {
516  $this->form_gui->setTitle($lng->txt("mcst_add_new_item"));
517  $this->form_gui->addCommandButton("saveCastItem", $lng->txt("save"));
518  } else {
519  $this->form_gui->setTitle($lng->txt("mcst_edit_item"));
520  $this->form_gui->addCommandButton("updateCastItem", $lng->txt("save"));
521  }
522  $this->form_gui->addCommandButton("listItems", $lng->txt("cancel"));
523  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveCastItem"));
524  }
525 
529  public function getCastItemValues()
530  {
531  $lng = $this->lng;
532 
533  // get mob
534  $this->mcst_item = new ilNewsItem($_GET["item_id"]);
535  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
536  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
537 
538  // preview
539  $ppic = $mob->getVideoPreviewPic();
540  if ($ppic != "") {
541  $i = $this->form_gui->getItemByPostVar("preview_pic");
542  $i->setImage($ppic);
543  }
544 
545 
546  $values = array();
547  $mediaItems = $this->getMediaItems($_GET["item_id"]);
548  if (count($mediaItems) > 0) {
549  foreach ($mediaItems as $med) {
550  if (!isset($values["title"])) {
551  // first item, so set title, description, ...
552  $values["title"] = $this->mcst_item->getTitle();
553  $values["description"] = $this->mcst_item->getContent();
554  $values["visibility"] = $this->mcst_item->getVisibility();
555  $length = explode(":", $this->mcst_item->getPlaytime());
556  $values["duration"] = array("hh" => $length[0], "mm" => $length[1], "ss" => $length[2]);
557  }
558 
559  $values["value_" . $med->getPurpose()] = (strlen($med->getLocation())> 100) ? "..." . substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
560  $values["label_value_" . $med->getPurpose()] = (strlen($med->getLocation())> 100) ? "..." . substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
561  $values["mimetype_" . $med->getPurpose()] = $med->getFormat();
562  }
563  }
564  foreach (ilObjMediaCast::$purposes as $purpose) {
565  if (!isset($values["value_" . $purpose])) {
566  $values["label_value_" . $purpose] = $lng->txt("none");
567  $values["value_" . $purpose] = $lng->txt("none");
568  }
569  }
570  $this->form_gui->setValuesByArray($values);
571  }
572 
576  public function saveCastItemObject()
577  {
578  $tpl = $this->tpl;
581  $lng = $this->lng;
582  $ilTabs = $this->tabs;
583 
584  $this->checkPermission("write");
585  $ilTabs->activateTab("edit_content");
586 
587  $this->initAddCastItemForm();
588 
589  if (!$this->form_gui->checkInput() ||
590  ($_POST["url_Standard"] == "" && !$_FILES['file_Standard']['tmp_name'])) {
591  if (($_POST["url_Standard"] == "" && !$_FILES['file_Standard']['tmp_name'])) {
592  ilUtil::sendFailure($lng->txt("mcst_input_either_file_or_url"));
593  }
594  $this->populateFormFromPost();
595  } else {
596  // create dummy object in db (we need an id)
597  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
598  $mob = new ilObjMediaObject();
599  $mob->create();
600 
601  //handle standard purpose
602  $file = $this->createMediaItemForPurpose($mob, "Standard");
603 
604  // set title and description
605  // set title to basename of file if left empty
606  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
607  $description = $this->form_gui->getInput("description");
608  $mob->setTitle($title);
609  $mob->setDescription($description);
610 
611  // save preview pic
612  $prevpic = $this->form_gui->getInput("preview_pic");
613  if ($prevpic["size"] > 0) {
614  $mob->uploadVideoPreviewPic($prevpic);
615  }
616 
617  // determine duration for standard purpose
618  $duration = $this->getDuration($file);
619 
620  // handle other purposes
621  foreach ($this->additionalPurposes as $purpose) {
622  // check if some purpose has been uploaded
623  $file_gui = $this->form_gui->getInput("file_" . $purpose);
624  $url_gui = $this->form_gui->getInput("url_" . $purpose);
625  if ($url_gui || $file_gui["size"] > 0) {
626  $this->createMediaItemForPurpose($mob, $purpose);
627  }
628  }
629 
630  $mob->update();
631 
632  if ($prevpic["size"] == 0) {
633  // re-read media object
634  $mob = new ilObjMediaObject($mob->getId());
635  $mob->generatePreviewPic(320, 240);
636  }
637 
638  //
639  // @todo: save usage
640  //
641 
642  $news_set = new ilSetting("news");
643  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
644 
645  // create new media cast item
646  include_once("./Services/News/classes/class.ilNewsItem.php");
647  $mc_item = new ilNewsItem();
648  $mc_item->setMobId($mob->getId());
649  $mc_item->setContentType(NEWS_AUDIO);
650  $mc_item->setContextObjId($this->object->getId());
651  $mc_item->setContextObjType($this->object->getType());
652  $mc_item->setUserId($ilUser->getId());
653  $mc_item->setPlaytime($duration);
654  $mc_item->setTitle($title);
655  $mc_item->setContent($description);
656  $mc_item->setLimitation(false);
657  if ($enable_internal_rss) {
658  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
659  } else {
660  $mc_item->setVisibility("users");
661  }
662  $mc_item->create();
663 
664  $ilCtrl->redirect($this, "listItems");
665  }
666  }
667 
674  private function getDuration($file)
675  {
676  $duration = isset($this->form_gui)
677  ? $this->form_gui->getInput("duration")
678  : array("hh"=>0, "mm"=>0, "ss"=>0);
679  if ($duration["hh"] == 0 && $duration["mm"] == 0 && $duration["ss"] == 0 && is_file($file)) {
680  include_once("./Services/MediaObjects/classes/class.ilMediaAnalyzer.php");
681  $ana = new ilMediaAnalyzer();
682  $ana->setFile($file);
683  $ana->analyzeFile();
684  $dur = $ana->getPlaytimeString();
685  $dur = explode(":", $dur);
686  $duration["mm"] = $dur[0];
687  $duration["ss"] = $dur[1];
688  }
689  $duration = str_pad($duration["hh"], 2, "0", STR_PAD_LEFT) . ":" .
690  str_pad($duration["mm"], 2, "0", STR_PAD_LEFT) . ":" .
691  str_pad($duration["ss"], 2, "0", STR_PAD_LEFT);
692  return $duration;
693  }
694 
701  private function createMediaItemForPurpose($mob, $purpose)
702  {
703  $mediaItem = new ilMediaItem();
704  $mob->addMediaItem($mediaItem);
705  $mediaItem->setPurpose($purpose);
706  return $this->updateMediaItem($mob, $mediaItem);
707  }
708 
716  private function updateMediaItem($mob, &$mediaItem)
717  {
718  $purpose = $mediaItem->getPurpose();
719  $url_gui = $this->form_gui->getInput("url_" . $purpose);
720  $file_gui = $this->form_gui->getInput("file_" . $purpose);
721  if ($url_gui) {
722  // http
723  $file = $this->form_gui->getInput("url_" . $purpose);
724  $title = basename($file);
725  $location = $this->form_gui->getInput("url_" . $purpose);
726  $locationType = "Reference";
727  } elseif ($file_gui["size"] > 0) {
728  // lokal
729  // determine and create mob directory, move uploaded file to directory
730  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
731  if (!is_dir($mob_dir)) {
732  $mob->createDirectory();
733  }
734 
735  $file_name = ilUtil::getASCIIFilename($_FILES['file_' . $purpose]['name']);
736  $file_name = str_replace(" ", "_", $file_name);
737 
738  $file = $mob_dir . "/" . $file_name;
739  $title = $file_name;
740  $locationType = "LocalFile";
741  $location = $title;
742  ilUtil::moveUploadedFile($_FILES['file_' . $purpose]['tmp_name'], $file_name, $file);
743  ilUtil::renameExecutables($mob_dir);
744  }
745 
746  // check if not automatic mimetype detection
747  if ($_POST["mimetype_" . $purpose] != "") {
748  $mediaItem->setFormat($_POST["mimetype_" . $purpose]);
749  } elseif ($mediaItem->getLocation() != "") {
750  $format = ilObjMediaObject::getMimeType($mediaItem->getLocation(), ($locationType == "Reference"));
751  $mediaItem->setFormat($format);
752  }
753 
754  if (isset($file)) {
755  // get mime type, if not already set!
756  if (!isset($format)) {
757  $format = ilObjMediaObject::getMimeType($file, ($locationType == "Reference"));
758  }
759 
760  // set real meta and object data
761  $mediaItem->setFormat($format);
762  $mediaItem->setLocation($location);
763  $mediaItem->setLocationType($locationType);
764  $mediaItem->setHAlign("Left");
765  $mediaItem->setHeight(self::isAudio($format)?0:180);
766  }
767 
768  if ($purpose == "Standard") {
769  if (isset($title)) {
770  $mob->setTitle($title);
771  }
772  if (isset($format)) {
773  $mob->setDescription($format);
774  }
775  }
776 
777  return $file;
778  }
779 
783  public function updateCastItemObject()
784  {
787  $ilLog = $this->log;
788 
789  $this->checkPermission("write");
790 
791  $this->initAddCastItemForm("edit");
792 
793  if ($this->form_gui->checkInput()) {
794  // create new media cast item
795  include_once("./Services/News/classes/class.ilNewsItem.php");
796  $mc_item = new ilNewsItem($_GET["item_id"]);
797  $mob_id = $mc_item->getMobId();
798 
799  // create dummy object in db (we need an id)
800  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
801  $mob = new ilObjMediaObject($mob_id);
802 
803 
804  foreach (ilObjMediaCast::$purposes as $purpose) {
805  if ($this->form_gui->getInput("delete_" . $purpose)) {
806  $mob->removeMediaItem($purpose);
807  $ilLog->write("Mcst: deleting purpose $purpose");
808  continue;
809  }
810  $media_item = $mob->getMediaItem($purpose);
811  $url_gui = $this->form_gui->getInput("url_" . $purpose);
812  $file_gui = $this->form_gui->getInput("file_" . $purpose);
813 
814  if ($media_item == null) {
815  if ($purpose != "Standard" &&
816  ($url_gui || $file_gui["size"]>0)) {
817  // check if we added an additional purpose when updating
818  // either by url or by file
819  $file = $this->createMediaItemForPurpose($mob, $purpose);
820  }
821  } else {
822  $file = $this->updateMediaItem($mob, $media_item);
823  }
824 
825  if ($purpose == "Standard") {
826  $duration = $this->getDuration($file);
827  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
828  $description = $this->form_gui->getInput("description");
829 
830  $mob->setTitle($title);
831  $mob->setDescription($description);
832 
833  $prevpic = $this->form_gui->getInput("preview_pic");
834  if ($prevpic["size"] > 0) {
835  $mob->uploadVideoPreviewPic($prevpic);
836  } else {
837  $prevpici = $this->form_gui->getItemByPostVar("preview_pic");
838  if ($prevpici->getDeletionFlag()) {
839  $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
840  }
841  }
842  }
843  }
844 
845  // set real meta and object data
846  $mob->update();
847 
848  //
849  // @todo: save usage
850  //
851 
852  $news_set = new ilSetting("news");
853  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
854 
855  $mc_item->setUserId($ilUser->getId());
856  if (isset($duration)) {
857  $mc_item->setPlaytime($duration);
858  }
859  $mc_item->setTitle($title);
860  $mc_item->setContent($description);
861  if ($enable_internal_rss) {
862  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
863  }
864  $mc_item->update();
865 
866  $ilCtrl->redirect($this, "listItems");
867  } else {
868  $this->populateFormFromPost();
869  }
870  }
871 
875  public function confirmDeletionItemsObject()
876  {
878  $lng = $this->lng;
879  $tpl = $this->tpl;
880  $ilTabs = $this->tabs;
881 
882  $this->checkPermission("write");
883  $ilTabs->activateTab("edit_content");
884 
885  if (!is_array($_POST["item_id"])) {
886  $this->listItemsObject();
887  return;
888  }
889 
890  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
891  $c_gui = new ilConfirmationGUI();
892 
893  // set confirm/cancel commands
894  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteItems"));
895  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
896  $c_gui->setCancel($lng->txt("cancel"), "listItems");
897  $c_gui->setConfirm($lng->txt("confirm"), "deleteItems");
898 
899  // add items to delete
900  include_once("./Services/News/classes/class.ilNewsItem.php");
901  foreach ($_POST["item_id"] as $item_id) {
902  $item = new ilNewsItem($item_id);
903  $c_gui->addItem(
904  "item_id[]",
905  $item_id,
906  $item->getTitle(),
907  ilUtil::getImagePath("icon_mcst.svg")
908  );
909  }
910 
911  $tpl->setContent($c_gui->getHTML());
912  }
913 
917  public function deleteItemsObject()
918  {
920 
921  $this->checkPermission("write");
922 
923  // delete all selected news items
924  foreach ($_POST["item_id"] as $item_id) {
925  $mc_item = new ilNewsItem($item_id);
926  $mc_item->delete();
927  }
928 
929  $ilCtrl->redirect($this, "listItems");
930  }
931 
935  public function downloadItemObject()
936  {
938  $this->checkPermission("read");
939 
940  $news_item = new ilNewsItem($_GET["item_id"]);
941  if (!$news_item->deliverMobFile($_GET["purpose"], (int) $_GET["presentation"])) {
942  $ilCtrl->redirect($this, "listItems");
943  } else {
945  $this->object->handleLPUpdate($ilUser->getId(), $news_item->getMobId());
946  }
947  exit;
948  }
949 
953  public function determinePlaytimeObject()
954  {
956  $lng = $this->lng;
957 
958  $mc_item = new ilNewsItem($_GET["item_id"]);
959  $mob = $mc_item->getMobId();
960  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
961  $mob = new ilObjMediaObject($mob);
962  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
963  $m_item = $mob->getMediaItem("Standard");
964  $file = $mob_dir . "/" . $m_item->getLocation();
965  $duration = $this->getDuration($file);
966  if ($duration != "00:00:00") {
967  $mc_item->setPlaytime($duration);
968  $mc_item->update();
969  ilUtil::sendSuccess($lng->txt("mcst_set_playtime"), true);
970  } else {
971  ilUtil::sendFailure($lng->txt("mcst_unable_to_determin_playtime"), true);
972  }
973 
974  $ilCtrl->redirect($this, "listItems");
975  }
976 
982  public function infoScreenObject()
983  {
984  if (!$this->checkPermissionBool("read")) {
985  $this->checkPermission("visible");
986  }
987  $this->ctrl->setCmd("showSummary");
988  $this->ctrl->setCmdClass("ilinfoscreengui");
989  $this->infoScreen();
990  }
991 
995  public function infoScreen()
996  {
997  $ilAccess = $this->access;
999  $ilTabs = $this->tabs;
1000 
1001  $ilTabs->activateTab("id_info");
1002 
1003  if (!$this->checkPermissionBool("read")) {
1004  $this->checkPermission("visible");
1005  }
1006 
1007  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1008  $info = new ilInfoScreenGUI($this);
1009 
1010  $info->enablePrivateNotes();
1011 
1012  // general information
1013  $this->lng->loadLanguageModule("meta");
1014  $this->lng->loadLanguageModule("mcst");
1015  $med_items = $this->object->getItemsArray();
1016  $info->addSection($this->lng->txt("meta_general"));
1017  $info->addProperty(
1018  $this->lng->txt("mcst_nr_items"),
1019  (int) count($med_items)
1020  );
1021 
1022  if (count($med_items) > 0) {
1023  $cur = current($med_items);
1024  $last = ilDatePresentation::formatDate(new ilDateTime($cur["creation_date"], IL_CAL_DATETIME));
1025  } else {
1026  $last = "-";
1027  }
1028 
1029  $info->addProperty($this->lng->txt("mcst_last_submission"), $last);
1030 
1031  // forward the command
1032  $this->ctrl->forwardCommand($info);
1033  }
1034 
1039  public function setTabs()
1040  {
1041  $ilAccess = $this->access;
1042  $ilTabs = $this->tabs;
1043  $lng = $this->lng;
1044  $ilHelp = $this->help;
1045 
1046  $ilHelp->setScreenIdComponent("mcst");
1047 
1048  // list items
1049  if ($ilAccess->checkAccess('read', "", $this->object->getRefId())) {
1050  $ilTabs->addTab(
1051  "content",
1052  $lng->txt("content"),
1053  $this->ctrl->getLinkTarget($this, "showContent")
1054  );
1055  }
1056 
1057  // info screen
1058  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId()) ||
1059  $ilAccess->checkAccess('read', "", $this->object->getRefId())) {
1060  $ilTabs->addTab(
1061  "id_info",
1062  $lng->txt("info_short"),
1063  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary")
1064  );
1065  }
1066 
1067  // settings
1068  if ($ilAccess->checkAccess('write', "", $this->object->getRefId())) {
1069  $ilTabs->addTab(
1070  "id_settings",
1071  $lng->txt("settings"),
1072  $this->ctrl->getLinkTarget($this, "editSettings")
1073  );
1074  }
1075 
1076  require_once 'Services/Tracking/classes/class.ilLearningProgressAccess.php';
1077  if (ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
1078  $ilTabs->addTab(
1079  'learning_progress',
1080  $lng->txt('learning_progress'),
1081  $this->ctrl->getLinkTargetByClass(array(__CLASS__, 'illearningprogressgui'), '')
1082  );
1083  }
1084 
1085  // export
1086  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1087  $ilTabs->addTab(
1088  "export",
1089  $lng->txt("export"),
1090  $this->ctrl->getLinkTargetByClass("ilexportgui", "")
1091  );
1092  }
1093 
1094  // edit permissions
1095  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
1096  $ilTabs->addTab(
1097  "id_permissions",
1098  $lng->txt("perm_settings"),
1099  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm")
1100  );
1101  }
1102  }
1103 
1110  public function addContentSubTabs($a_active = "content")
1111  {
1112  $ilTabs = $this->tabs;
1113  $ilAccess = $this->access;
1114  $lng = $this->lng;
1115 
1116  $ilTabs->addSubTab(
1117  "content",
1118  $lng->txt("view"),
1119  $this->ctrl->getLinkTarget($this, "showContent")
1120  );
1121 
1122  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) {
1123  $ilTabs->addSubTab(
1124  "manage",
1125  $lng->txt("mcst_manage"),
1126  $this->ctrl->getLinkTarget($this, "listItems")
1127  );
1128 
1129  if ($this->object->getOrder() == ilObjMediaCast::ORDER_MANUAL) {
1130  $ilTabs->addSubTab(
1131  "sorting",
1132  $lng->txt("mcst_ordering"),
1133  $this->ctrl->getLinkTarget($this, "editOrder")
1134  );
1135  }
1136  }
1137 
1138  $ilTabs->activateSubTab($a_active);
1139  $ilTabs->activateTab("content");
1140  }
1141 
1142 
1146  public function editSettingsObject()
1147  {
1148  $tpl = $this->tpl;
1149  $ilTabs = $this->tabs;
1150 
1151  $this->checkPermission("write");
1152  $ilTabs->activateTab("id_settings");
1153 
1154  $this->initSettingsForm();
1155  $tpl->setContent($this->form_gui->getHtml());
1156  }
1157 
1161  public function initSettingsForm()
1162  {
1163  $tpl = $this->tpl;
1164  $lng = $this->lng;
1165  $ilCtrl = $this->ctrl;
1166 
1167  $lng->loadLanguageModule("mcst");
1168 
1169  require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1170  $this->form_gui = new ilPropertyFormGUI();
1171  $this->form_gui->setTitle($lng->txt("mcst_settings"));
1172 
1173  // Title
1174  $tit = new ilTextInputGUI($lng->txt("title"), "title");
1175  $tit->setValue($this->object->getTitle());
1176  $tit->setRequired(true);
1177  $this->form_gui->addItem($tit);
1178 
1179  // description
1180  $des = new ilTextAreaInputGUI($lng->txt("description"), "description");
1181  $des->setValue($this->object->getLongDescription());
1182  $this->form_gui->addItem($des);
1183 
1184  $sh = new ilFormSectionHeaderGUI();
1185  $sh->setTitle($lng->txt("rep_activation_availability"));
1186  $this->form_gui->addItem($sh);
1187 
1188  // Online
1189  $online = new ilCheckboxInputGUI($lng->txt("online"), "online");
1190  $online->setChecked($this->object->getOnline());
1191  $this->form_gui->addItem($online);
1192 
1193  // presentation
1194  $sh = new ilFormSectionHeaderGUI();
1195  $sh->setTitle($lng->txt("obj_presentation"));
1196  $this->form_gui->addItem($sh);
1197 
1198  // Sorting
1199  $sort = new ilRadioGroupInputGUI($lng->txt("mcst_ordering"), "order");
1200  $sort->addOption(new ilRadioOption(
1201  $lng->txt("mcst_ordering_title"),
1203  ));
1204  $sort->addOption(new ilRadioOption(
1205  $lng->txt("mcst_ordering_creation_date_asc"),
1207  ));
1208  $sort->addOption(new ilRadioOption(
1209  $lng->txt("mcst_ordering_creation_date_desc"),
1211  ));
1212  $sort->addOption(new ilRadioOption(
1213  $lng->txt("mcst_ordering_manual"),
1215  ));
1216  $sort->setValue($this->object->getOrder());
1217  $this->form_gui->addItem($sort);
1218 
1219  // view mode
1220  $options = array(
1221  ilObjMediaCast::VIEW_LIST => $lng->txt("mcst_list"),
1222  ilObjMediaCast::VIEW_GALLERY => $lng->txt("mcst_gallery")
1223  );
1224  $si = new ilRadioGroupInputGUI($this->lng->txt("mcst_viewmode"), "viewmode");
1225  $si->addOption(new ilRadioOption(
1226  $lng->txt("mcst_list"),
1228  ));
1229  $si->addOption(new ilRadioOption(
1230  $lng->txt("mcst_gallery"),
1232  ));
1233 
1234  // $si->setOptions($options);
1235  $si->setValue($this->object->getViewMode());
1236  $this->form_gui->addItem($si);
1237 
1238 
1239  // Downloadable
1240  $downloadable = new ilCheckboxInputGUI($lng->txt("mcst_downloadable"), "downloadable");
1241  $downloadable->setChecked($this->object->getDownloadable());
1242  $downloadable->setInfo($lng->txt("mcst_downloadable_info"));
1243  $this->form_gui->addItem($downloadable);
1244 
1245  $news_set = new ilSetting("news");
1246  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1247 
1248  //Default Visibility
1249  if ($enable_internal_rss) {
1250  // webfeed
1251  $sh = new ilFormSectionHeaderGUI();
1252  $sh->setTitle($lng->txt("mcst_webfeed"));
1253  $this->form_gui->addItem($sh);
1254 
1255  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "defaultaccess");
1256  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "0");
1257  $radio_option->setInfo($lng->txt("news_news_item_def_visibility_users_info"));
1258  $radio_group->addOption($radio_option);
1259  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "1");
1260  $radio_option->setInfo($lng->txt("news_news_item_def_visibility_public_info"));
1261  $radio_group->addOption($radio_option);
1262  $radio_group->setRequired(false);
1263  $radio_group->setValue($this->object->getDefaultAccess());
1264  #$ch->addSubItem($radio_group);
1265  $this->form_gui->addItem($radio_group);
1266 
1267  //Extra Feed
1268  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1269  $public_feed = ilBlockSetting::_lookup("news", "public_feed", 0, $this->object->getId());
1270  $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"), "extra_feed");
1271  $ch->setInfo($lng->txt("news_public_feed_info"));
1272  $ch->setChecked($public_feed);
1273  $this->form_gui->addItem($ch);
1274 
1275  // keep minimal x number of items
1276  $ni = new ilNumberInputGUI($this->lng->txt("news_keep_minimal_x_items"), "keep_rss_min");
1277  $ni->setMaxValue(100);
1278  $ni->setMinValue(0);
1279  $ni->setMaxLength(3);
1280  $ni->setSize(3);
1281  $ni->setInfo($this->lng->txt("news_keep_minimal_x_items_info") . " (" .
1282  ilNewsItem::_lookupRSSPeriod() . " " . (ilNewsItem::_lookupRSSPeriod() == 1 ? $lng->txt("day") : $lng->txt("days")) . ")");
1283  $ni->setValue((int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $this->object->getId()));
1284  $ch->addSubItem($ni);
1285 
1286  // Include Files in Pubic Items
1287  $incl_files = new ilCheckboxInputGUI($lng->txt("mcst_incl_files_in_rss"), "public_files");
1288  $incl_files->setChecked($this->object->getPublicFiles());
1289  $incl_files->setInfo($lng->txt("mcst_incl_files_in_rss_info"));
1290  #$ch->addSubItem($incl_files);
1291  $this->form_gui->addItem($incl_files);
1292  }
1293 
1294  // Form action and save button
1295  $this->form_gui->addCommandButton("saveSettings", $lng->txt("save"));
1296  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveSettings"));
1297  }
1298 
1302  public function saveSettingsObject()
1303  {
1304  $ilCtrl = $this->ctrl;
1305  $ilTabs = $this->tabs;
1306 
1307  $this->checkPermission("write");
1308  $ilTabs->activateTab("id_settings");
1309 
1310  $this->initSettingsForm();
1311  if ($this->form_gui->checkInput()) {
1312  $news_set = new ilSetting("news");
1313  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1314 
1315  $this->object->setTitle($this->form_gui->getInput("title"));
1316  $this->object->setDescription($this->form_gui->getInput("description"));
1317  $this->object->setOnline($this->form_gui->getInput("online"));
1318  $this->object->setDownloadable($this->form_gui->getInput("downloadable"));
1319  $this->object->setOrder($this->form_gui->getInput("order"));
1320  $this->object->setViewMode($this->form_gui->getInput("viewmode"));
1321 
1322  if ($enable_internal_rss) {
1323  $this->object->setPublicFiles($this->form_gui->getInput("public_files"));
1324  $this->object->setDefaultAccess($this->form_gui->getInput("defaultaccess"));
1325  }
1326  $this->object->update();
1327 
1328  if ($enable_internal_rss) {
1329  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1331  "news",
1332  "public_feed",
1333  $this->form_gui->getInput("extra_feed"),
1334  0,
1335  $this->object->getId()
1336  );
1337 
1339  "news",
1340  "keep_rss_min",
1341  $this->form_gui->getInput("keep_rss_min"),
1342  0,
1343  $this->object->getId()
1344  );
1345  }
1346 
1347  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1348  $ilCtrl->redirect($this, "editSettings");
1349  } else {
1350  $this->form_gui->setValuesByPost();
1351  $this->tpl->setContent($this->form_gui->getHTML());
1352  }
1353  }
1354 
1355  // add media cast to locator
1356  public function addLocatorItems()
1357  {
1358  $ilLocator = $this->locator;
1359 
1360  if (is_object($this->object)) {
1361  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listItems"), "", $_GET["ref_id"]);
1362  }
1363  }
1364 
1365  public static function _goto($a_target)
1366  {
1367  global $DIC;
1368 
1369  $ilAccess = $DIC->access();
1370  $ilErr = $DIC["ilErr"];
1371  $lng = $DIC->language();
1372 
1373  if ($ilAccess->checkAccess("read", "", $a_target)) {
1374  $_GET["cmd"] = "showContent";
1375  $_GET["ref_id"] = $a_target;
1376  $_GET["baseClass"] = "ilmediacasthandlergui";
1377  $_GET["cmdClass"] = "ilobjmediacastgui";
1378  include("ilias.php");
1379  exit;
1380  } elseif ($ilAccess->checkAccess("visible", "", $a_target)) {
1381  ilObjectGUI::_gotoRepositoryNode($a_target, "infoScreen");
1382  } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
1383  ilUtil::sendFailure(sprintf(
1384  $lng->txt("msg_no_perm_read_item"),
1386  ));
1388  }
1389 
1390  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1391  }
1392 
1399  protected static function isAudio($extension)
1400  {
1401  return strpos($extension, "audio") !== false;
1402  }
1403 
1410  protected function getMediaItem($id)
1411  {
1412  include_once("./Services/News/classes/class.ilNewsItem.php");
1413  $this->mcst_item = new ilNewsItem($id);
1414  // create dummy object in db (we need an id)
1415  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1416  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1417  return $mob->getMediaItem("Standard");
1418  }
1419 
1426  protected function getMediaItems($id)
1427  {
1428  include_once("./Services/News/classes/class.ilNewsItem.php");
1429  $this->mcst_item = new ilNewsItem($id);
1430  // create dummy object in db (we need an id)
1431  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1432  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1433  return $mob->getMediaItems();
1434  }
1435 
1436  private function populateFormFromPost()
1437  {
1438  $tpl = $this->tpl;
1439  //issue: we have to display the current settings
1440  // problem: POST does not contain values of disabled textfields
1441  // solution: use hidden field and label to display-> here we need to synchronize the labels
1442  // with the values from the hidden fields.
1443  foreach (ilObjMediaCast::$purposes as $purpose) {
1444  if ($_POST["value_" . $purpose]) {
1445  $_POST["label_value_" . $purpose] = $_POST["value_" . $purpose];
1446  }
1447  }
1448 
1449  $this->form_gui->setValuesByPost();
1450  $tpl->setContent($this->form_gui->getHTML());
1451  }
1452 
1453  protected function editOrderObject()
1454  {
1455  $ilTabs = $this->tabs;
1456  $lng = $this->lng;
1457  $tpl = $this->tpl;
1458 
1459  $this->checkPermission("write");
1460  $ilTabs->activateTab("edit_content");
1461 
1462  $this->addContentSubTabs("sorting");
1463 
1464  // sort by order setting
1465  switch ($this->object->getOrder()) {
1469  return $this->listItemsObject();
1470 
1472  // sub-tabs
1473  break;
1474  }
1475 
1476  include_once("./Modules/MediaCast/classes/class.ilMediaCastTableGUI.php");
1477  $table_gui = new ilMediaCastTableGUI($this, "editOrder", true);
1478 
1479  $table_gui->setTitle($lng->txt("mcst_media_cast"));
1480  $table_gui->setData($this->object->getSortedItemsArray());
1481 
1482  $table_gui->addCommandButton("saveOrder", $lng->txt("mcst_save_order"));
1483 
1484  $tpl->setContent($table_gui->getHTML());
1485  }
1486 
1487  public function saveOrderObject()
1488  {
1489  $lng = $this->lng;
1490 
1491  asort($_POST["item_id"]);
1492 
1493  $items = array();
1494  foreach (array_keys($_POST["item_id"]) as $id) {
1495  $items[] = $id;
1496  }
1497  $this->object->saveOrder($items);
1498 
1499  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
1500  $this->ctrl->redirect($this, "editOrder");
1501  }
1502 
1506 
1513  public function showContentObject()
1514  {
1515  $ilUser = $this->user;
1516 
1517  // need read events for parent for LP statistics
1518  require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
1520  "mcst",
1521  $this->object->getRefId(),
1522  $this->object->getId(),
1523  $ilUser->getId()
1524  );
1525 
1526  if ($this->object->getViewMode() == ilObjMediaCast::VIEW_GALLERY) {
1527  $this->showGallery();
1528  } else {
1529  $this->listItemsObject(true);
1530  }
1531  global $tpl;
1532  $tpl->setPermanentLink($this->object->getType(), $this->object->getRefId());
1533  }
1534 
1535  public function showGallery()
1536  {
1537  $tpl = $this->tpl;
1538  $ilTabs = $this->tabs;
1539  $ilCtrl = $this->ctrl;
1540 
1541  $tpl->addJavascript("./Modules/MediaCast/js/MediaCast.js");
1542 
1543  $ilTabs->activateTab("content");
1544 
1545  $this->addContentSubTabs("content");
1546 
1547  $ctpl = new ilTemplate("tpl.mcst_content.html", true, true, "Modules/MediaCast");
1548 
1549  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1550  require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
1551  foreach ($this->object->getSortedItemsArray() as $item) {
1552  $mob = new ilObjMediaObject($item["mob_id"]);
1553  $med = $mob->getMediaItem("Standard");
1554 
1555  $ctpl->setCurrentBlock("item");
1556  $ctpl->setVariable("TITLE", $item["title"]);
1557  $ctpl->setVariable("TIME", $item["playtime"]);
1558  $ctpl->setVariable("ID", $item["id"]);
1559 
1560  if ($mob->getVideoPreviewPic() != "") {
1561  $ctpl->setVariable(
1562  "PREVIEW_PIC",
1563  ilUtil::img(ilWACSignedPath::signFile($mob->getVideoPreviewPic()), $item["title"], 320, 240)
1564  );
1565  } else {
1566  $ctpl->setVariable(
1567  "PREVIEW_PIC",
1568  ilUtil::img(ilUtil::getImagePath("mcst_preview.svg"), $item["title"], 320, 240)
1569  );
1570  }
1571 
1572  // player
1573  if (is_object($med)) {
1574  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
1575 
1576  // the news id will be used as player id, see also ilMediaCastTableGUI
1577  $mpl = new ilMediaPlayerGUI(
1578  $item["id"],
1579  $ilCtrl->getLinkTarget($this, "handlePlayerEvent", "", true, false)
1580  );
1581 
1582  if (strcasecmp("Reference", $med->getLocationType()) == 0) {
1583  ilWACSignedPath::signFolderOfStartFile($med->getLocation());
1584  $mpl->setFile($med->getLocation());
1585  } else {
1586  $path_to_file = ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
1588  $mpl->setFile($path_to_file);
1589  }
1590  $mpl->setMimeType($med->getFormat());
1591  //$mpl->setDisplayHeight($med->getHeight());
1592  $mpl->setDisplayHeight("480");
1593  $mpl->setDisplayWidth("640");
1594  $mpl->setVideoPreviewPic(ilWACSignedPath::signFile($mob->getVideoPreviewPic()));
1595  $mpl->setTitle($item["title"]);
1596  $mpl->setDescription($item["content"]);
1597  $mpl->setForceAudioPreview(true);
1598  if ($this->object->getDownloadable()) {
1599  $ilCtrl->setParameterByClass("ilobjmediacastgui", "item_id", $item["id"]);
1600  $ilCtrl->setParameterByClass("ilobjmediacastgui", "purpose", "Standard");
1601  $mpl->setDownloadLink($ilCtrl->getLinkTargetByClass("ilobjmediacastgui", "downloadItem"));
1602  }
1603  $med_alt = $mob->getMediaItem("VideoAlternative");
1604  if (is_object($med_alt)) {
1605  $mpl->setAlternativeVideoFile(ilWACSignedPath::signFile(ilObjMediaObject::_getURL($mob->getId()) . "/" .
1606  $med_alt->getLocation()));
1607  $mpl->setAlternativeVideoMimeType($med_alt->getFormat());
1608  }
1609 
1610  $ctpl->setVariable("PLAYER", $mpl->getPreviewHtml());
1611  }
1612 
1613 
1614  $ctpl->parseCurrentBlock();
1615  }
1616 
1617  $feed_icon_html = $this->getFeedIconsHTML();
1618 
1619  if ($feed_icon_html != "") {
1620  $feed_icon_html = '<p>' . $feed_icon_html . '</p>';
1621  }
1622 
1623  $tpl->setContent($feed_icon_html . $ctpl->get());
1624  }
1625 
1632  public function convertFileObject()
1633  {
1634  $ilCtrl = $this->ctrl;
1635 
1636  $this->checkPermission("write");
1637 
1638  $this->mcst_item = new ilNewsItem($_GET["item_id"]);
1639  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1640  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1641 
1642  $target_purpose = ilUtil::stripSlashes($_POST["target_purpose"]);
1643  $target_format = ilUtil::stripSlashes($_POST["target_format"]);
1644 
1645  try {
1646  include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
1647  $med = $mob->getMediaItem("Standard");
1648  $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $med->getLocation();
1649  $new_file = ilFFmpeg::convert($mob_file, $target_format);
1651  $pi = pathinfo($new_file);
1652  $med = $mob->getMediaItem($target_purpose);
1653  if (!is_object($med)) {
1654  $med = new ilMediaItem();
1655  $med->setMobId($mob->getId());
1656  $mob->addMediaItem($med);
1657  $mob->update();
1658  $med->setPurpose($target_purpose);
1659  }
1660  $med->setFormat($target_format);
1661  $med->setLocation($pi["basename"]);
1662  $med->setLocationType("LocalFile");
1663  $med->update();
1664 
1665  $add = (is_array($ret) && count($ret) > 0)
1666  ? "<br />" . implode($ret, "<br />")
1667  : "";
1668 
1669  ilUtil::sendInfo($this->lng->txt("mcst_converted_file") . $add, true);
1670  } catch (ilException $e) {
1672  $add = (is_array($ret) && count($ret) > 0)
1673  ? "<br />" . implode($ret, "<br />")
1674  : "";
1675  ilUtil::sendFailure($e->getMessage() . $add, true);
1676  }
1677 
1678 
1679  $ilCtrl->redirect($this, "editCastItem");
1680  }
1681 
1688  public function extractPreviewImageObject()
1689  {
1690  $ilCtrl = $this->ctrl;
1691 
1692  $this->checkPermission("write");
1693 
1694  $this->mcst_item = new ilNewsItem($_GET["item_id"]);
1695  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1696  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1697 
1698  try {
1699  $sec = (int) $_POST["sec"];
1700  if ($sec < 0) {
1701  $sec = 0;
1702  }
1703  if ($mob->getVideoPreviewPic() != "") {
1704  $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
1705  }
1706  include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
1707  $med = $mob->getMediaItem("Standard");
1708  $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $med->getLocation();
1709  $new_file = ilFFmpeg::extractImage(
1710  $mob_file,
1711  "mob_vpreview.png",
1712  ilObjMediaObject::_getDirectory($mob->getId()),
1713  $sec
1714  );
1715 
1716  if ($new_file != "") {
1717  ilUtil::sendInfo($this->lng->txt("mcst_image_extracted"), true);
1718  } else {
1719  ilUtil::sendFailure($this->lng->txt("mcst_no_extraction_possible"), true);
1720  }
1721  } catch (ilException $e) {
1722  if (DEVMODE == 1) {
1724  $add = (is_array($ret) && count($ret) > 0)
1725  ? "<br />" . implode($ret, "<br />")
1726  : "";
1727  }
1728  ilUtil::sendFailure($e->getMessage() . $add, true);
1729  }
1730 
1731 
1732  $ilCtrl->redirect($this, "editCastItem");
1733  }
1734 
1741  public function handlePlayerEventObject()
1742  {
1743  if ($_GET["event"] == "play") {
1744  $player = explode("_", $_GET["player"]);
1745  $news_id = (int) $player[1];
1746  include_once("./Services/News/classes/class.ilNewsItem.php");
1747  $item = new ilNewsItem($news_id);
1748  $item->increasePlayCounter();
1749 
1750  $mob_id = $item->getMobId();
1751  if ($mob_id) {
1752  $ilUser = $this->user;
1753  $this->object->handleLPUpdate($ilUser->getId(), $mob_id);
1754  }
1755  }
1756  exit;
1757  }
1758 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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 duration (typical hh:mm:ss) property in a property form.
This class represents an option in a radio group.
updateMediaItem($mob, &$mediaItem)
update media item from form
static get($a_type, $a_href="")
Get icon html.
static getLastReturnValues()
Get last return values.
getVideoPreviewPic($a_filename_only=false)
Get video preview pic.
static getMimeType($a_file, $a_external=null)
get mime type for file
Class ilInfoScreenGUI.
$format
Definition: metadata.php:141
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
& getMediaItem($a_purpose)
get item for media purpose
static _lookupRSSPeriod()
getDuration($file)
get duration from form or from file analyzer
const IL_CAL_DATETIME
This class represents a selection list property in a property form.
This class represents a property form user interface.
GUI class for the workflow of copying objects.
global $DIC
Definition: saml.php:7
static convert($a_file, $a_target_mime, $a_target_dir="", $a_target_filename="")
Convert file to target mime type.
initSettingsForm()
Init Settings Form.
$_GET["client_id"]
$location
Definition: buildRTE.php:44
This class represents a section header in a property form.
This class represents a file property in a property form.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
setPostVar($a_postvar)
Set Post Variable.
if(!array_key_exists('StateId', $_REQUEST)) $id
setValue($a_value)
Set Value.
static _gotoRepositoryRoot($a_raise_error=false)
Goto repository root.
This class represents a checkbox property in a property form.
static _lookupTitle($a_id)
lookup object title
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...
setInfo($a_info)
Set Info.
static _getURL($a_mob_id)
get directory for files of media object (static)
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
user()
Definition: user.php:4
static _getDirectory($a_mob_id)
get directory for files of media object (static)
getMediaItem($id)
get MediaItem for id and updates local variable mcst_item
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$section
Definition: Utf8Test.php:83
static signFolderOfStartFile($start_file_path)
getFeedIconsHTML()
Get feed icons HTML.
setChecked($a_checked)
Set Checked.
Export User Interface Class.
static checkAccess($a_ref_id, $a_allow_only_read=true)
check access to learning progress
initImportForm($a_new_type)
Init object import form.
setPattern($pattern)
set pattern
This class represents a hidden form property in a property form.
deleteItemsObject()
Delete news items.
prepareOutput($a_show_subobjects=true)
prepare output
initAddCastItemForm($a_mode="create")
Init add cast item form.
createMediaItemForPurpose($mob, $purpose)
handle media item for given purpose
static extractImage( $a_file, $a_target_filename, $a_target_dir="", $a_sec=1)
Extract image from video file.
This class represents a property in a property form.
addOption($a_option)
Add Option.
getCastItemValues()
Get cast item values into form.
addCastItemObject()
Add media cast item.
Class ilObjMediaCastGUI.
static _gotoRepositoryNode($a_ref_id, $a_cmd="frameset")
Goto repository root.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
This class represents a number property in a property form.
saveSettingsObject()
Save Settings.
updateCastItemObject()
Update cast item.
Class ilObjectGUI Basic methods of all Output classes.
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
listItemsObject($a_presentation_mode=false)
List items of media cast.
static isAudio($extension)
detect audio mimetype
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
This class represents a regular expression input property in a property form.
addContentSubTabs($a_active="content")
Add content subtabs.
Class ilMediaItem.
This class represents a text property in a property form.
Date and time handling
$ilUser
Definition: imgupload.php:18
handlePlayerEventObject()
Handle player event.
Class ilObjMediaObject.
setMaxLength($a_maxlength)
Set Max Length.
initCreateForm($a_new_type)
Init object creation form.
generatePreviewPic($a_width, $a_height)
Upload video preview picture.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static signFile($path_to_file)
convertFileObject()
Convert file object.
showContentObject()
Show content.
confirmDeletionItemsObject()
Confirmation Screen.
Create styles array
The data for the language used.
setMaxValue($a_maxvalue, $a_display_always=false)
Set Maximum Value.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
afterSave(ilObject $newObj)
save object public
saveCastItemObject()
Save new cast item.
This class represents an image file property in a property form.
determinePlaytimeObject()
Delete news items.
User interface for media player.
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
This class represents a non editable value in a property form.
Create new PHPExcel object
obj_idprivate
Analyzes media files.
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
& getMediaItems()
get all media items
downloadItemObject()
Download news media item.
getMediaItems($id)
get MediaItems for id and updates local variable mcst_item
This class represents a text area property in a property form.
editSettingsObject()
Edit settings.
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
getRefId()
get reference id public
infoScreen()
show information screen
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
const NEWS_AUDIO
TableGUI class for table NewsForContext.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
$url
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
extractPreviewImageObject()
Extract preview image.
static enabled()
Checks, whether FFmpeg support is enabled (path is set in the setup)
static _getInstance()
get singleton instance
$info
Definition: index.php:5
setValue($a_value)
Set Value.
static redirect($a_script)
__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output=true)
Constructor public.
addHeaderAction()
Add header action menu.
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
Class ilObjUserTrackingGUI.
$_POST["username"]
$html
Definition: example_001.php:87
infoScreenObject()
this one is called from the info button in the repository not very nice to set cmdClass/Cmd manually...
setRequired($a_required)
Set Required.
editCastItemObject()
Edit media cast item.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
Confirmation screen class.
static supportsImageExtraction($a_mime)
Check if mime type supports image extraction.