ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilDclMobRecordFieldModel Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilDclMobRecordFieldModel:
+ Collaboration diagram for ilDclMobRecordFieldModel:

Public Member Functions

 __construct (ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
 
 parseValue ($value)
 
 parseExportValue ($value)
 Function to parse incoming data from form input value $value. More...
 
 addHiddenItemsToConfirmation (ilConfirmationGUI $confirmation)
 
 parseSortingValue ($value, bool $link=true)
 Returns sortable value for the specific field-types. More...
 
 setValueFromForm (ilPropertyFormGUI $form)
 
 afterClone ()
 
- Public Member Functions inherited from ilDclBaseRecordFieldModel
 __construct (ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
 
 doCreate ()
 Creates an Id and a database entry. More...
 
 doUpdate ()
 Update object in database. More...
 
 delete ()
 Delete record field in database. More...
 
 getValue ()
 
 getValueForRepresentation ()
 
 serializeData ($value)
 Serialize data before storing to db. More...
 
 deserializeData ($value)
 Deserialize data before applying to field. More...
 
 setValue ($value, bool $omit_parsing=false)
 Set value for record field. More...
 
 setValueFromForm (ilPropertyFormGUI $form)
 
 getFormulaValue ()
 
 parseExportValue ($value)
 Function to parse incoming data from form input value $value. More...
 
 getValueFromExcel (ilExcel $excel, int $row, int $col)
 
 parseValue ($value)
 Function to parse incoming data from form input value $value. More...
 
 getExportValue ()
 
 fillExcelExport (ilExcel $worksheet, int &$row, int &$col)
 
 getPlainText ()
 
 getSortingValue (bool $link=true)
 
 addHiddenItemsToConfirmation (ilConfirmationGUI $confirmation)
 
 parseSortingValue ($value, bool $link=true)
 Returns sortable value for the specific field-types. More...
 
 cloneStructure (ilDclBaseRecordFieldModel $old_record_field)
 
 afterClone ()
 
 getField ()
 
 getId ()
 
 getRecord ()
 
 getRecordRepresentation ()
 
 setRecordRepresentation (ilDclBaseRecordRepresentation $record_representation)
 
 getFieldRepresentation ()
 
 setFieldRepresentation (ilDclBaseFieldRepresentation $field_representation)
 

Private Attributes

ilGlobalTemplateInterface $main_tpl
 
ILIAS FileUpload FileUpload $upload
 

Additional Inherited Members

- Protected Member Functions inherited from ilDclBaseRecordFieldModel
 doRead ()
 Read object data from database. More...
 
 loadValue ()
 Load the value. More...
 
- Protected Attributes inherited from ilDclBaseRecordFieldModel
int $id = null
 
ilDclBaseFieldModel $field
 
ilDclBaseRecordModel $record
 
ilDclBaseRecordRepresentation $record_representation = null
 
ilDclBaseFieldRepresentation $field_representation = null
 
 $value
 
ilObjUser $user
 
ilCtrl $ctrl
 
ilDBInterface $db
 
ilLanguage $lng
 
ILIAS HTTP Services $http
 
ILIAS Refinery Factory $refinery
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Definition at line 19 of file class.ilDclMobRecordFieldModel.php.

Constructor & Destructor Documentation

◆ __construct()

ilDclMobRecordFieldModel::__construct ( ilDclBaseRecordModel  $record,
ilDclBaseFieldModel  $field 
)

Definition at line 24 of file class.ilDclMobRecordFieldModel.php.

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\Repository\upload().

25  {
26  parent::__construct($record, $field);
27  global $DIC;
28  $this->upload = $DIC->upload();
29  $this->main_tpl = $DIC->ui()->mainTemplate();
30  }
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ addHiddenItemsToConfirmation()

ilDclMobRecordFieldModel::addHiddenItemsToConfirmation ( ilConfirmationGUI  $confirmation)

Definition at line 185 of file class.ilDclMobRecordFieldModel.php.

References ILIAS\LTI\ToolProvider\$key, ilDclBaseRecordFieldModel\$value, ilConfirmationGUI\addHiddenItem(), and ilDclBaseRecordFieldModel\getValue().

185  : void
186  {
187  if (is_array($this->getValue())) {
188  foreach ($this->getValue() as $key => $value) {
189  $confirmation->addHiddenItem('field_' . $this->field->getId() . '[' . $key . ']', $value);
190  }
191  }
192  }
addHiddenItem(string $a_post_var, string $a_value)
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ afterClone()

ilDclMobRecordFieldModel::afterClone ( )

Definition at line 214 of file class.ilDclMobRecordFieldModel.php.

References ilDclBaseRecordFieldModel\$field, ilDclBaseRecordFieldModel\$record, ilDclBaseRecordFieldModel\doUpdate(), ilObjMediaObject\duplicate(), ilDclCache\getCloneOf(), ilDclBaseRecordFieldModel\getField(), ilObject\getId(), ilDclBaseRecordFieldModel\getId(), ilDclBaseRecordFieldModel\getRecord(), ilDclCache\getRecordFieldCache(), ilDclBaseRecordFieldModel\setValue(), ilDclCache\TYPE_FIELD, and ilDclCache\TYPE_RECORD.

214  : void
215  {
219 
220  if (!$record_field || !$record_field->getValue()) {
221  return;
222  }
223 
224  $mob_old = new ilObjMediaObject($record_field->getValue());
225  $mob_new = $mob_old->duplicate();
226 
227  $this->setValue($mob_new->getId(), true);
228  $this->doUpdate();
229  }
setValue($value, bool $omit_parsing=false)
Set value for record field.
doUpdate()
Update object in database.
static getCloneOf(int $id, string $type)
duplicate()
Duplicate media object, return new media object.
static getRecordFieldCache(object $record, object $field)
+ Here is the call graph for this function:

◆ parseExportValue()

ilDclMobRecordFieldModel::parseExportValue (   $value)

Function to parse incoming data from form input value $value.

returns the int|string to store in the database.

Parameters
int | string$value
Returns
int|string

Definition at line 172 of file class.ilDclMobRecordFieldModel.php.

References ilDclBaseRecordFieldModel\$value.

173  {
174  $file = $value;
175  if (is_numeric($file)) {
176  $mob = new ilObjMediaObject($file);
177  $mob_name = $mob->getTitle();
178 
179  return $mob_name;
180  }
181 
182  return $file;
183  }

◆ parseSortingValue()

ilDclMobRecordFieldModel::parseSortingValue (   $value,
bool  $link = true 
)

Returns sortable value for the specific field-types.

Parameters
int$value

Definition at line 198 of file class.ilDclMobRecordFieldModel.php.

References ilDclBaseRecordFieldModel\$value.

198  : string
199  {
200  $mob = new ilObjMediaObject($value);
201 
202  return $mob->getTitle();
203  }

◆ parseValue()

ilDclMobRecordFieldModel::parseValue (   $value)
Parameters
array | int$value
Returns
array|string
Exceptions
ilException
ilFileUtilsException
ilMediaObjectsException

Definition at line 39 of file class.ilDclMobRecordFieldModel.php.

References Vendor\Package\$e, ilDclBaseRecordFieldModel\$field, $format, $location, $type, ilDclBaseRecordFieldModel\$value, ilObjMediaObject\_determineWidthHeight(), ilObjMediaObject\_getDirectory(), ilObjMediaObject\_resizeImage(), ilObjMediaObject\_saveUsage(), ilFFmpeg\enabled(), ilFFmpeg\extractImage(), ilFileUtils\getASCIIFilename(), ilDclBaseRecordFieldModel\getField(), ilDclBaseRecordFieldModel\getId(), ilObjMediaObject\getMimeType(), ilDclBaseFieldModel\getProperty(), ilDclBaseRecordFieldModel\getRecord(), ilDclPropertyFormGUI\getTempFilename(), ilDclBaseRecordFieldModel\getValue(), ILIAS\FileDelivery\http(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ilDclBaseFieldModel\PROP_HEIGHT, ilDclBaseFieldModel\PROP_WIDTH, ILIAS\Repository\refinery(), ilFileUtils\rename(), ilFileUtils\renameExecutables(), ilFFmpeg\supportsImageExtraction(), and ILIAS\Repository\upload().

40  {
41  if ($value === -1) { //marked for deletion.
42  return null;
43  }
44 
45  $media = $value;
46 
47  $has_record_id = $this->http->wrapper()->query()->has('record_id');
48  $is_confirmed = $this->http->wrapper()->post()->has('save_confirmed');
49  $has_save_confirmation = ($this->getRecord()->getTable()->getSaveConfirmation() && !$has_record_id);
50 
51  if (is_array($media)
52  && isset($media['tmp_name'])
53  && $media['tmp_name'] !== ""
54  && (!$has_save_confirmation || $is_confirmed)
55  ) {
56  $mob = new ilObjMediaObject();
57  $mob->setTitle($media['name']);
58  $mob->create();
59  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
60  if (!is_dir($mob_dir)) {
61  $mob->createDirectory();
62  }
63  $media_item = new ilMediaItem();
64  $mob->addMediaItem($media_item);
65  $media_item->setPurpose("Standard");
66  $file_name = ilFileUtils::getASCIIFilename($media['name']);
67  $file_name = str_replace(" ", "_", $file_name);
68  $target_file_path = $mob_dir . "/" . $file_name;
69  $title = $file_name;
70  $location = $file_name;
71 
72  if ($has_save_confirmation) {
73  $ilfilehash = $this->http->wrapper()->post()->retrieve(
74  'ilfilehash',
75  $this->refinery->kindlyTo()->string()
76  );
77 
79  $ilfilehash,
80  'field_' . $this->getField()->getId(),
81  $media["name"],
82  $media["type"]
83  );
84  } else {
85  if (false === $this->upload->hasBeenProcessed()) {
86  $this->upload->process();
87  }
88 
89  if (false === $this->upload->hasUploads()) {
90  throw new ilException($this->lng->txt('upload_error_file_not_found'));
91  }
92  $move_file = $media['tmp_name'];
93  }
94 
95  ilFileUtils::rename($move_file, $target_file_path);
97 
98  // Check image/video
99  $format = ilObjMediaObject::getMimeType($target_file_path);
100 
101  if ($format == 'image/jpeg') {
102  list($width, $height, $type, $attr) = getimagesize($target_file_path);
103  $field = $this->getField();
106  if ($new_width || $new_height) {
107  //only resize if it is bigger, not if it is smaller
108  if ($new_height < $height && $new_width < $width) {
109  //resize proportional
110  if (!$new_height || !$new_width) {
111  $format = ilObjMediaObject::getMimeType($target_file_path);
112  $wh
114  $format,
115  "File",
116  $target_file_path,
117  "",
118  true,
119  false,
122  );
123  } else {
126  }
127 
128  $location = ilObjMediaObject::_resizeImage($target_file_path, $wh['width'], $wh['height']);
129  }
130  }
131  }
132 
134  $mob->getId(),
135  "dcl:html",
136  $this->getRecord()->getTable()->getCollectionObject()->getId()
137  );
138  $media_item->setFormat($format);
139  $media_item->setLocation($location);
140  $media_item->setLocationType("LocalFile");
141 
143  $med = $mob->getMediaItem("Standard");
144  $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $med->getLocation();
145  $a_target_dir = ilObjMediaObject::_getDirectory($mob->getId());
146  try {
147  $new_file = ilFFmpeg::extractImage($mob_file, "mob_vpreview.png", $a_target_dir, 1);
148  } catch (Exception $e) {
149  $this->main_tpl->setOnScreenMessage('failure', $e->getMessage(), true);
150  }
151  }
152 
153  $mob->update();
154  $return = $mob->getId();
155  // handover for save-confirmation
156  } else {
157  if (is_array($media) && isset($media['tmp_name']) && $media['tmp_name'] != '') {
158  $return = $media;
159  } else {
160  $return = $this->getValue();
161  }
162  }
163 
164  return $return;
165  }
static _determineWidthHeight(string $a_format, string $a_type, string $a_file, string $a_reference, bool $a_constrain_proportions, bool $a_use_original, ?int $a_user_width=null, ?int $a_user_height=null)
$type
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
static _resizeImage(string $a_file, int $a_width, int $a_height, bool $a_constrain_prop=false)
Resize image and return new image file ("_width_height" string appended)
static extractImage(string $a_file, string $a_target_filename, string $a_target_dir="", int $a_sec=1)
Extract image from video file.
static getASCIIFilename(string $a_filename)
static renameExecutables(string $a_dir)
static supportsImageExtraction(string $a_mime)
Check if mime type supports image extraction.
static _getDirectory(int $a_mob_id)
Get absolute directory.
static http()
Fetches the global http state from ILIAS.
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$format
Definition: metadata.php:235
getProperty(string $key)
Returns a certain property of a field.
static rename(string $a_source, string $a_target)
static enabled()
Checks, whether FFmpeg support is enabled (path is set in the setup)
static getTempFilename(string $a_hash, string $a_field, string $a_name, string $a_type, ?string $a_index=null, ?string $a_sub_index=null)
+ Here is the call graph for this function:

◆ setValueFromForm()

ilDclMobRecordFieldModel::setValueFromForm ( ilPropertyFormGUI  $form)

Definition at line 205 of file class.ilDclMobRecordFieldModel.php.

References ilDclBaseRecordFieldModel\$value, ilDclBaseRecordFieldModel\getField(), ilDclBaseRecordFieldModel\getId(), ilPropertyFormGUI\getInput(), ilPropertyFormGUI\getItemByPostVar(), and ilDclBaseRecordFieldModel\setValue().

205  : void
206  {
207  $value = $form->getInput("field_" . $this->getField()->getId());
208  if ($form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) {
209  $value = -1;
210  }
211  $this->setValue($value);
212  }
getItemByPostVar(string $a_post_var)
setValue($value, bool $omit_parsing=false)
Set value for record field.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
+ Here is the call graph for this function:

Field Documentation

◆ $main_tpl

ilGlobalTemplateInterface ilDclMobRecordFieldModel::$main_tpl
private

Definition at line 21 of file class.ilDclMobRecordFieldModel.php.

◆ $upload

ILIAS FileUpload FileUpload ilDclMobRecordFieldModel::$upload
private

Definition at line 22 of file class.ilDclMobRecordFieldModel.php.


The documentation for this class was generated from the following file: