ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclMobRecordFieldModel.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once('./Modules/DataCollection/classes/Fields/Base/class.ilDclBaseRecordFieldModel.php');
6require_once('./Modules/DataCollection/classes/Fields/Fileupload/class.ilDclFileuploadRecordFieldModel.php');
16 public function parseValue($value) {
17 if ($value == -1) //marked for deletion.
18 {
19 return 0;
20 }
21
22 $media = $value;
23 $has_save_confirmation = ($this->getRecord()->getTable()->getSaveConfirmation() && !isset($_GET['record_id']));
24 $is_confirmed = (bool) (isset($_POST['save_confirmed']));
25
26 if (is_array($media) && $media['tmp_name'] != "" && (!$has_save_confirmation || $is_confirmed)) {
27 $mob = new ilObjMediaObject();
28 $mob->setTitle($media['name']);
29 $mob->create();
30 $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
31 if (!is_dir($mob_dir)) {
32 $mob->createDirectory();
33 }
34 $media_item = new ilMediaItem();
35 $mob->addMediaItem($media_item);
36 $media_item->setPurpose("Standard");
37 $file_name = ilUtil::getASCIIFilename($media['name']);
38 $file_name = str_replace(" ", "_", $file_name);
39 $file = $mob_dir . "/" . $file_name;
40 $title = $file_name;
41 $location = $file_name;
42 if($has_save_confirmation) {
43 $move_file = ilDclPropertyFormGUI::getTempFilename($_POST['ilfilehash'], 'field_'.$this->getField()->getId(), $media["name"], $media["type"]);
44 ilUtil::moveUploadedFile($move_file, $file_name, $file, true, "rename");
45 } else {
46 ilUtil::moveUploadedFile($media['tmp_name'], $file_name, $file);
47 }
48
50 // Check image/video
52
53 if ($format == 'image/jpeg') {
54 list($width, $height, $type, $attr) = getimagesize($file);
55 $field = $this->getField();
56 $new_width = $field->getProperty(ilDclBaseFieldModel::PROP_WIDTH);
57 $new_height = $field->getProperty(ilDclBaseFieldModel::PROP_HEIGHT);
58 if ($new_width || $new_height) {
59 //only resize if it is bigger, not if it is smaller
60 if ($new_height < $height && $new_width < $width) {
61 //resize proportional
62 if (!$new_height || !$new_width) {
64 $wh = ilObjMediaObject::_determineWidthHeight($format, "File", $file, "", true, false, $field->getProperty(ilDclBaseFieldModel::PROP_WIDTH), (int)$field->getProperty(ilDclBaseFieldModel::PROP_HEIGHT));
65 } else {
66 $wh['width'] = (int)$field->getProperty(ilDclBaseFieldModel::PROP_WIDTH);
67 $wh['height'] = (int)$field->getProperty(ilDclBaseFieldModel::PROP_HEIGHT);
68 }
69
70 $location = ilObjMediaObject::_resizeImage($file, $wh['width'], $wh['height'], false);
71 }
72 }
73 }
74
75 ilObjMediaObject::_saveUsage($mob->getId(), "dcl:html", $this->getRecord()->getTable()->getCollectionObject()->getId());
76 $media_item->setFormat($format);
77 $media_item->setLocation($location);
78 $media_item->setLocationType("LocalFile");
79
80 // FSX MediaPreview
81 include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
83 $med = $mob->getMediaItem("Standard");
84 $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $med->getLocation();
85 $a_target_dir = ilObjMediaObject::_getDirectory($mob->getId());
86 try {
87 $new_file = ilFFmpeg::extractImage($mob_file, "mob_vpreview.png", $a_target_dir, 1);
88 } catch (Exception $e) {
89 ilUtil::sendFailure($e->getMessage(), true);
90 }
91 }
92
93 $mob->update();
94 $return = $mob->getId();
95 // handover for save-confirmation
96 } else if(is_array($media) && isset($media['tmp_name']) && $media['tmp_name'] != '') {
97 $return = $media;
98 }else {
99 $return = $this->getValue();
100 }
101
102 return $return;
103 }
104
105
113 public function parseExportValue($value) {
114 $file = $value;
115 if (is_numeric($file)) {
116 $mob = new ilObjMediaObject($file, false);
117 $mob_name = $mob->getTitle();
118
119 return $mob_name;
120 }
121 return $file;
122 }
123
127 public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation) {
128 if (is_array($this->getValue())) {
129 foreach($this->getValue() as $key=>$value) {
130 $confirmation->addHiddenItem('field_'.$this->field->getId().'['.$key.']', $value);
131 }
132 }
133 }
134
135
145 public function parseSortingValue($value, $link = true) {
146 $mob = new ilObjMediaObject($value, false);
147 return $mob->getTitle();
148 }
149
150
154 public function setValueFromForm($form) {
155 $value = $form->getInput("field_" . $this->getField()->getId());
156 if ($form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) {
157 $value = - 1;
158 }
159 $this->setValue($value);
160 }
161
162
163 public function afterClone() {
167
168 if (!$record_field || !$record_field->getValue()) {
169 return;
170 }
171
172 $mob_old = new ilObjMediaObject($record_field->getValue());
173 $mob_new = $mob_old->duplicate();
174
175 $this->setValue($mob_new->getId(), true);
176 $this->doUpdate();
177 }
178}
$location
Definition: buildRTE.php:44
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
addHiddenItem($a_post_var, $a_value)
Add hidden item.
setValue($value, $omit_parsing=false)
Set value for record field.
static getRecordFieldCache($record, $field)
static getCloneOf($id, $type)
Class ilDclMobRecordFieldModel.
parseValue($value)
Function to parse incoming data from form input value $value.
parseSortingValue($value, $link=true)
Returns sortable value for the specific field-types.
parseExportValue($value)
Function to parse incoming data from form input value $value.
addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
static getTempFilename($a_hash, $a_field, $a_name, $a_type, $a_index=null, $a_sub_index=null)
return temp-filename
static extractImage($a_file, $a_target_filename, $a_target_dir="", $a_sec=1)
Extract image from video file.
static enabled()
Checks, whether FFmpeg support is enabled (path is set in the setup)
static supportsImageExtraction($a_mime)
Check if mime type supports image extraction.
Class ilMediaItem.
Class ilObjMediaObject.
static getMimeType($a_file, $a_external=false)
get mime type for file
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _getDirectory($a_mob_id)
get directory for files of media object (static)
static _determineWidthHeight($a_format, $a_type, $a_file, $a_reference, $a_constrain_proportions, $a_use_original, $a_user_width, $a_user_height)
Determine width and height.
static _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop=false)
resize image and return new image file ("_width_height" string appended)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file