/**
  * Extract preview image
  *
  * @param
  * @return
  */
 function extractPreviewImageObject()
 {
     global $ilCtrl;
     $this->checkPermission("write");
     $this->mcst_item = new ilNewsItem($_GET["item_id"]);
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php";
     $mob = new ilObjMediaObject($this->mcst_item->getMobId());
     try {
         $sec = (int) $_POST["sec"];
         if ($sec < 0) {
             $sec = 0;
         }
         if ($mob->getVideoPreviewPic() != "") {
             $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
         }
         include_once "./Services/MediaObjects/classes/class.ilFFmpeg.php";
         $med = $mob->getMediaItem("Standard");
         $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $med->getLocation();
         $new_file = ilFFmpeg::extractImage($mob_file, "mob_vpreview.png", ilObjMediaObject::_getDirectory($mob->getId()), $sec);
         if ($new_file != "") {
             ilUtil::sendInfo($this->lng->txt("mcst_image_extracted"), true);
         } else {
             ilUtil::sendFailure($this->lng->txt("mcst_no_extraction_possible"), true);
         }
     } catch (ilException $e) {
         if (DEVMODE == 1) {
             $ret = ilFFmpeg::getLastReturnValues();
             $add = is_array($ret) && count($ret) > 0 ? "<br />" . implode($ret, "<br />") : "";
         }
         ilUtil::sendFailure($e->getMessage() . $add, true);
     }
     $ilCtrl->redirect($this, "editCastItem");
 }
 /**
  * Function to parse incoming data from form input value $value. returns the string/number/etc. to store in the database.
  *
  * @param                             $value
  * @param ilDataCollectionRecordField $record_field
  *
  * @return int|string
  */
 public function parseValue($value, ilDataCollectionRecordField $record_field)
 {
     $return = false;
     if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_FILE) {
         $file = $value;
         if (is_array($file) && $file['tmp_name']) {
             $file_obj = new ilObjFile();
             $file_obj->setType("file");
             $file_obj->setTitle($file["name"]);
             $file_obj->setFileName($file["name"]);
             $file_obj->setFileType(ilMimeTypeUtil::getMimeType("", $file["name"], $file["type"]));
             $file_obj->setFileSize($file["size"]);
             $file_obj->setMode("object");
             $file_obj->create();
             $file_obj->getUploadFile($file["tmp_name"], $file["name"]);
             $file_id = $file_obj->getId();
             $return = $file_id;
         } else {
             $return = $record_field->getValue();
         }
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_MOB) {
         if ($value == -1) {
             return 0;
         }
         $media = $value;
         if (is_array($media) && $media['tmp_name']) {
             $mob = new ilObjMediaObject();
             $mob->setTitle($media['name']);
             $mob->create();
             $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
             if (!is_dir($mob_dir)) {
                 $mob->createDirectory();
             }
             $media_item = new ilMediaItem();
             $mob->addMediaItem($media_item);
             $media_item->setPurpose("Standard");
             $file_name = ilUtil::getASCIIFilename($media['name']);
             $file_name = str_replace(" ", "_", $file_name);
             $file = $mob_dir . "/" . $file_name;
             $title = $file_name;
             $location = $file_name;
             ilUtil::moveUploadedFile($media['tmp_name'], $file_name, $file);
             ilUtil::renameExecutables($mob_dir);
             // Check image/video
             $format = ilObjMediaObject::getMimeType($file);
             if ($format == 'image/jpeg') {
                 list($width, $height, $type, $attr) = getimagesize($file);
                 $arr_properties = $record_field->getField()->getProperties();
                 $new_width = $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH];
                 $new_height = $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT];
                 if ($new_width || $new_height) {
                     //only resize if it is bigger, not if it is smaller
                     if ($new_height < $height && $new_width < $width) {
                         //resize proportional
                         if (!$new_height || !$new_width) {
                             $format = ilObjMediaObject::getMimeType($file);
                             $wh = ilObjMediaObject::_determineWidthHeight("", "", $format, "File", $file, "", true, false, $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH], (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]);
                         } else {
                             $wh['width'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH];
                             $wh['height'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT];
                         }
                         $location = ilObjMediaObject::_resizeImage($file, $wh['width'], $wh['height'], false);
                     }
                 }
             }
             ilObjMediaObject::_saveUsage($mob->getId(), "dcl:html", $record_field->getRecord()->getTable()->getCollectionObject()->getId());
             $media_item->setFormat($format);
             $media_item->setLocation($location);
             $media_item->setLocationType("LocalFile");
             // FSX MediaPreview
             include_once "./Services/MediaObjects/classes/class.ilFFmpeg.php";
             if (ilFFmpeg::supportsImageExtraction($format)) {
                 $med = $mob->getMediaItem("Standard");
                 $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $med->getLocation();
                 $a_target_dir = ilObjMediaObject::_getDirectory($mob->getId());
                 try {
                     $new_file = ilFFmpeg::extractImage($mob_file, "mob_vpreview.png", $a_target_dir, 1);
                 } catch (ilFFmpegException $e) {
                     ilUtil::sendFailure($e->getMessage(), true);
                 }
             }
             $mob->update();
             $return = $mob->getId();
         } else {
             $return = $record_field->getValue();
         }
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) {
         return $value["date"] . " " . $value["time"];
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) {
         $return = $value ? 1 : 0;
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_TEXT) {
         $arr_properties = $record_field->getField()->getProperties();
         if ($arr_properties[ilDataCollectionField::PROPERTYID_TEXTAREA]) {
             $return = nl2br($value);
         } else {
             $return = $value;
         }
     } else {
         if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) {
             $return = $value == '' ? NULL : $value;
             //SW, Ilias Mantis #0011799: Return null otherwise '' is casted to 0 in DB
         } else {
             $return = $value;
         }
     }
     return $return;
 }