ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
14 {
15  public function parseValue($value)
16  {
17  if ($value == -1) { //marked for deletion.
18  return 0;
19  }
20 
21  $media = $value;
22  $has_save_confirmation = ($this->getRecord()->getTable()->getSaveConfirmation() && !isset($_GET['record_id']));
23  $is_confirmed = (bool) (isset($_POST['save_confirmed']));
24 
25  if (is_array($media) && $media['tmp_name'] != "" && (!$has_save_confirmation || $is_confirmed)) {
26  $mob = new ilObjMediaObject();
27  $mob->setTitle($media['name']);
28  $mob->create();
29  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
30  if (!is_dir($mob_dir)) {
31  $mob->createDirectory();
32  }
33  $media_item = new ilMediaItem();
34  $mob->addMediaItem($media_item);
35  $media_item->setPurpose("Standard");
36  $file_name = ilUtil::getASCIIFilename($media['name']);
37  $file_name = str_replace(" ", "_", $file_name);
38  $file = $mob_dir . "/" . $file_name;
39  $title = $file_name;
40  $location = $file_name;
41  if ($has_save_confirmation) {
42  $move_file = ilDclPropertyFormGUI::getTempFilename($_POST['ilfilehash'], 'field_' . $this->getField()->getId(), $media["name"], $media["type"]);
43  ilUtil::moveUploadedFile($move_file, $file_name, $file);
44  } else {
45  ilUtil::moveUploadedFile($media['tmp_name'], $file_name, $file);
46  }
47 
48  ilUtil::renameExecutables($mob_dir);
49  // Check image/video
51 
52  if ($format == 'image/jpeg') {
53  list($width, $height, $type, $attr) = getimagesize($file);
54  $field = $this->getField();
55  $new_width = $field->getProperty(ilDclBaseFieldModel::PROP_WIDTH);
56  $new_height = $field->getProperty(ilDclBaseFieldModel::PROP_HEIGHT);
57  if ($new_width || $new_height) {
58  //only resize if it is bigger, not if it is smaller
59  if ($new_height < $height && $new_width < $width) {
60  //resize proportional
61  if (!$new_height || !$new_width) {
63  $wh
64  = 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 {
97  if (is_array($media) && isset($media['tmp_name']) && $media['tmp_name'] != '') {
98  $return = $media;
99  } else {
100  $return = $this->getValue();
101  }
102  }
103 
104  return $return;
105  }
106 
107 
115  public function parseExportValue($value)
116  {
117  $file = $value;
118  if (is_numeric($file)) {
119  $mob = new ilObjMediaObject($file, false);
120  $mob_name = $mob->getTitle();
121 
122  return $mob_name;
123  }
124 
125  return $file;
126  }
127 
128 
132  public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
133  {
134  if (is_array($this->getValue())) {
135  foreach ($this->getValue() as $key => $value) {
136  $confirmation->addHiddenItem('field_' . $this->field->getId() . '[' . $key . ']', $value);
137  }
138  }
139  }
140 
141 
151  public function parseSortingValue($value, $link = true)
152  {
153  $mob = new ilObjMediaObject($value, false);
154 
155  return $mob->getTitle();
156  }
157 
158 
162  public function setValueFromForm($form)
163  {
164  $value = $form->getInput("field_" . $this->getField()->getId());
165  if ($form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) {
166  $value = -1;
167  }
168  $this->setValue($value);
169  }
170 
171 
172  public function afterClone()
173  {
177 
178  if (!$record_field || !$record_field->getValue()) {
179  return;
180  }
181 
182  $mob_old = new ilObjMediaObject($record_field->getValue());
183  $mob_new = $mob_old->duplicate();
184 
185  $this->setValue($mob_new->getId(), true);
186  $this->doUpdate();
187  }
188 }
static getCloneOf($id, $type)
addHiddenItem($a_post_var, $a_value)
Add hidden item.
static getMimeType($a_file, $a_external=null)
get mime type for file
$format
Definition: metadata.php:141
$type
static _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop=false)
resize image and return new image file ("_width_height" string appended)
$_GET["client_id"]
$location
Definition: buildRTE.php:44
setValue($value, $omit_parsing=false)
Set value for record field.
addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
parseSortingValue($value, $link=true)
Returns sortable value for the specific field-types.
parseExportValue($value)
Function to parse incoming data from form input value $value.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static _getDirectory($a_mob_id)
Get absolute directory.
static extractImage( $a_file, $a_target_filename, $a_target_dir="", $a_sec=1)
Extract image from video file.
if(isset($_POST['submit'])) $form
doUpdate()
Update object in database.
Class ilMediaItem.
Class ilObjMediaObject.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getRecordFieldCache($record, $field)
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
Class ilDclMobRecordFieldModel.
duplicate()
Duplicate media object, return new media object.
static enabled()
Checks, whether FFmpeg support is enabled (path is set in the setup)
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 _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
$key
Definition: croninfo.php:18
$_POST["username"]
Confirmation screen class.
static supportsImageExtraction($a_mime)
Check if mime type supports image extraction.
static getTempFilename($a_hash, $a_field, $a_name, $a_type, $a_index=null, $a_sub_index=null)
return temp-filename