ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclMobRecordFieldModel.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public function parseValue($value)
24 {
25 if ($value === -1) {
26 return null;
27 }
28
29 $media = $value;
30
31 $has_record_id = $this->http->wrapper()->query()->has('record_id');
32 $is_confirmed = $this->http->wrapper()->post()->has('save_confirmed');
33 $has_save_confirmation = ($this->getRecord()->getTable()->getSaveConfirmation() && !$has_record_id);
34
35 if (($media['tmp_name'] ?? '') !== '' && (!$has_save_confirmation || $is_confirmed)) {
36 $mob = new ilObjMediaObject();
37 $mob->setTitle($media['name']);
38 $mob->create();
39 $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
40 if (!is_dir($mob_dir)) {
41 $mob->createDirectory();
42 }
43 $media_item = new ilMediaItem();
44 $mob->addMediaItem($media_item);
45 $media_item->setPurpose('Standard');
46 $file_name = ilFileUtils::getASCIIFilename($media['name']);
47 $file_name = str_replace(' ', '_', $file_name);
48 $target_file_path = $mob_dir . '/' . $file_name;
49 $location = $file_name;
50
51 if ($has_save_confirmation) {
52 $ilfilehash = $this->http->wrapper()->post()->retrieve(
53 'ilfilehash',
54 $this->refinery->kindlyTo()->string()
55 );
56
58 $ilfilehash,
59 'field_' . $this->getField()->getId(),
60 $media['name'],
61 $media['type']
62 );
63 } else {
64 if (!$this->upload->hasBeenProcessed()) {
65 $this->upload->process();
66 }
67
68 if (!$this->upload->hasUploads()) {
69 throw new ilException($this->lng->txt('upload_error_file_not_found'));
70 }
71 $move_file = $media['tmp_name'];
72 }
73
74 ilFileUtils::rename($move_file, $target_file_path);
75 chmod($target_file_path, 0640);
77
78 $format = ilObjMediaObject::getMimeType($target_file_path);
79
81 $mob->getId(),
82 'dcl:html',
83 $this->getRecord()->getTable()->getCollectionObject()->getId()
84 );
85 $media_item->setFormat($format);
86 $media_item->setLocation($location);
87 $media_item->setLocationType('LocalFile');
88
90 $med = $mob->getMediaItem('Standard');
91 $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . '/' . $med->getLocation();
92 $a_target_dir = ilObjMediaObject::_getDirectory($mob->getId());
93 ilFFmpeg::extractImage($mob_file, 'mob_vpreview.png', $a_target_dir);
94 }
95
96 $mob->update();
97 $return = $mob->getId();
98 if ($this->value !== null) {
99 $this->removeData();
100 }
101 } else {
102 if (($media['tmp_name'] ?? '') !== '') {
103 $return = $media;
104 } else {
105 $return = $this->getValue();
106 }
107 }
108
109 return $return;
110 }
111
117 public function parseExportValue($value)
118 {
119 $file = $value;
120 if (is_numeric($file)) {
121 $mob = new ilObjMediaObject($file);
122 return $mob->getTitle();
123 }
124
125 return $file;
126 }
127
132 public function parseSortingValue($value, bool $link = true): string
133 {
134 $mob = new ilObjMediaObject($value);
135
136 return $mob->getTitle();
137 }
138
139 protected function removeData(): void
140 {
141 $mob = new ilObjMediaObject($this->value);
143 $mob->getId(),
144 'dcl:html',
145 $this->getRecord()->getTable()->getCollectionObject()->getId()
146 );
147 $mob->delete();
148 }
149
150 public function afterClone(): void
151 {
155
156 if (!$record_field->getValue()) {
157 return;
158 }
159
160 $mob_old = new ilObjMediaObject($record_field->getValue());
161 $mob_new = $mob_old->duplicate();
162
163 $this->setValue($mob_new->getId(), true);
164 $this->doUpdate();
165 }
166}
$location
Definition: buildRTE.php:22
setValue($value, bool $omit_parsing=false)
Set value for record field.
doUpdate()
Update object in database.
static getRecordFieldCache(object $record, object $field)
static getCloneOf(int $id, string $type)
@noinspection AutoloadingIssuesInspection
parseValue($value)
Function to parse incoming data from form input value $value.
parseExportValue($value)
Function to parse incoming data from form input value $value.
parseSortingValue($value, bool $link=true)
Returns sortable value for the specific field-types.
static getTempFilename(string $a_hash, string $a_field, string $a_name, string $a_type, ?string $a_index=null, ?string $a_sub_index=null)
Base class for ILIAS Exception handling.
static enabled()
Checks, whether FFmpeg support is enabled (path is set in the setup)
static extractImage(string $a_file, string $a_target_filename, string $a_target_dir="", int $a_sec=1)
Extract image from video file.
static supportsImageExtraction(string $a_mime)
Check if mime type supports image extraction.
static getASCIIFilename(string $a_filename)
static rename(string $a_source, string $a_target)
static renameExecutables(string $a_dir)
Class ilMediaItem Media Item, component of a media object (file or reference)
static _removeUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Remove usage of mob in another container.
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
static _getDirectory(int $a_mob_id)
Get absolute directory.
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 http()
Fetches the global http state from ILIAS.