ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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) {
64  } else {
65  $wh['width'] = (int) $field->getProperty(ilDclBaseFieldModel::PROP_WIDTH);
66  $wh['height'] = (int) $field->getProperty(ilDclBaseFieldModel::PROP_HEIGHT);
67  }
68 
69  $location = ilObjMediaObject::_resizeImage($file, $wh['width'], $wh['height'], false);
70  }
71  }
72  }
73 
74  ilObjMediaObject::_saveUsage($mob->getId(), "dcl:html", $this->getRecord()->getTable()->getCollectionObject()->getId());
75  $media_item->setFormat($format);
76  $media_item->setLocation($location);
77  $media_item->setLocationType("LocalFile");
78 
79  // FSX MediaPreview
80  include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
82  $med = $mob->getMediaItem("Standard");
83  $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $med->getLocation();
84  $a_target_dir = ilObjMediaObject::_getDirectory($mob->getId());
85  try {
86  $new_file = ilFFmpeg::extractImage($mob_file, "mob_vpreview.png", $a_target_dir, 1);
87  } catch (Exception $e) {
88  ilUtil::sendFailure($e->getMessage(), true);
89  }
90  }
91 
92  $mob->update();
93  $return = $mob->getId();
94  // handover for save-confirmation
95  } elseif (is_array($media) && isset($media['tmp_name']) && $media['tmp_name'] != '') {
96  $return = $media;
97  } else {
98  $return = $this->getValue();
99  }
100 
101  return $return;
102  }
103 
104 
112  public function parseExportValue($value)
113  {
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  {
129  if (is_array($this->getValue())) {
130  foreach ($this->getValue() as $key=>$value) {
131  $confirmation->addHiddenItem('field_' . $this->field->getId() . '[' . $key . ']', $value);
132  }
133  }
134  }
135 
136 
146  public function parseSortingValue($value, $link = true)
147  {
148  $mob = new ilObjMediaObject($value, false);
149  return $mob->getTitle();
150  }
151 
152 
156  public function setValueFromForm($form)
157  {
158  $value = $form->getInput("field_" . $this->getField()->getId());
159  if ($form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) {
160  $value = -1;
161  }
162  $this->setValue($value);
163  }
164 
165 
166  public function afterClone()
167  {
171 
172  if (!$record_field || !$record_field->getValue()) {
173  return;
174  }
175 
176  $mob_old = new ilObjMediaObject($record_field->getValue());
177  $mob_new = $mob_old->duplicate();
178 
179  $this->setValue($mob_new->getId(), true);
180  $this->doUpdate();
181  }
182 }
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 directory for files of media object (static)
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.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
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