ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilDclMobRecordFieldModel.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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);
76 
77  $format = ilObjMediaObject::getMimeType($target_file_path);
78 
80  $mob->getId(),
81  'dcl:html',
82  $this->getRecord()->getTable()->getCollectionObject()->getId()
83  );
84  $media_item->setFormat($format);
85  $media_item->setLocation($location);
86  $media_item->setLocationType('LocalFile');
87 
89  $med = $mob->getMediaItem('Standard');
90  $mob_file = ilObjMediaObject::_getDirectory($mob->getId()) . '/' . $med->getLocation();
91  $a_target_dir = ilObjMediaObject::_getDirectory($mob->getId());
92  ilFFmpeg::extractImage($mob_file, 'mob_vpreview.png', $a_target_dir);
93  }
94 
95  $mob->update();
96  $return = $mob->getId();
97  if ($this->value !== null) {
98  $this->removeData();
99  }
100  } else {
101  if (($media['tmp_name'] ?? '') !== '') {
102  $return = $media;
103  } else {
104  $return = $this->getValue();
105  }
106  }
107 
108  return $return;
109  }
110 
116  public function parseExportValue($value)
117  {
118  $file = $value;
119  if (is_numeric($file)) {
120  $mob = new ilObjMediaObject($file);
121  return $mob->getTitle();
122  }
123 
124  return $file;
125  }
126 
131  public function parseSortingValue($value, bool $link = true): string
132  {
133  $mob = new ilObjMediaObject($value);
134 
135  return $mob->getTitle();
136  }
137 
138  protected function removeData(): void
139  {
140  $mob = new ilObjMediaObject($this->value);
142  $mob->getId(),
143  'dcl:html',
144  $this->getRecord()->getTable()->getCollectionObject()->getId()
145  );
146  $mob->delete();
147  }
148 
149  public function afterClone(): void
150  {
154 
155  if (!$record_field->getValue()) {
156  return;
157  }
158 
159  $mob_old = new ilObjMediaObject($record_field->getValue());
160  $mob_new = $mob_old->duplicate();
161 
162  $this->setValue($mob_new->getId(), true);
163  $this->doUpdate();
164  }
165 }
setValue($value, bool $omit_parsing=false)
Set value for record field.
$location
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 extractImage(string $a_file, string $a_target_filename, string $a_target_dir="", int $a_sec=1)
Extract image from video file.
parseExportValue($value)
Function to parse incoming data from form input value $value.
static getASCIIFilename(string $a_filename)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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
doUpdate()
Update object in database.
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.
parseSortingValue($value, bool $link=true)
Returns sortable value for the specific field-types.
static getCloneOf(int $id, string $type)
duplicate()
Duplicate media object, return new media object.
static rename(string $a_source, string $a_target)
static getRecordFieldCache(object $record, object $field)
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)