ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilDclMobRecordFieldModel.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 protected function handleFileUpload(array $value, bool $has_save_confirmation): int
26 {
27 $mob = new ilObjMediaObject();
28 $mob->setTitle($value[self::FILE_NAME]);
29 $mob->create();
30 $mob->createDirectory();
31 $target_file_path = ilObjMediaObject::_getRelativeDirectory($mob->getId());
32
33 if ($has_save_confirmation) {
35 $this->http->wrapper()->post()->retrieve('ilfilehash', $this->refinery->kindlyTo()->string()),
36 'field_' . $this->getField()->getId(),
37 $value[self::FILE_NAME],
38 $value[self::FILE_TYPE]
39 );
40 $this->getField()->getFileSystem()->write($target_file_path . '/' . str_replace(' ', '_', $value[self::FILE_NAME]), file_get_contents($move_file));
41 } else {
42 $this->upload->moveFilesTo(ilObjMediaObject::_getRelativeDirectory($mob->getId()), Location::WEB);
43 }
44
45 $file = $this->getField()->getFileSystem()->listContents(ilObjMediaObject::_getRelativeDirectory($mob->getId()))[0];
46 $format = $this->getField()->getFileSystem()->getMimeType($file->getPath());
47
49 $mob->getId(),
50 'dcl:html',
51 $this->getRecord()->getTable()->getCollectionObject()->getId()
52 );
53 $media_item = new ilMediaItem();
54 $media_item->setPurpose('Standard');
55 $media_item->setFormat($format);
56 $media_item->setLocation(basename($file->getPath()));
57 $media_item->setLocationType('LocalFile');
58 $mob->addMediaItem($media_item);
59
61 $dir = ilObjMediaObject::_getDirectory($mob->getId());
62 ilFFmpeg::extractImage($dir . '/' . basename($file->getPath()), 'mob_vpreview.png', $dir);
63 }
64
65 $mob->update();
66 return $mob->getId();
67 }
68
74 public function parseExportValue($value)
75 {
76 $file = $value;
77 if (is_numeric($file)) {
78 $mob = new ilObjMediaObject($file);
79 return $mob->getTitle();
80 }
81
82 return $file;
83 }
84
89 public function parseSortingValue($value, bool $link = true): string
90 {
91 $mob = new ilObjMediaObject($value);
92
93 return $mob->getTitle();
94 }
95
96 protected function removeData(): void
97 {
98 if (ilObjMediaObject::_exists($this->value)) {
99 $mob = new ilObjMediaObject($this->value);
100 $this->getField()->getFileSystem()->deleteDir(ilObjMediaObject::_getRelativeDirectory($mob->getId()));
101 $mob->delete();
102 }
103 }
104
105 public function afterClone(): void
106 {
107 if ($this->value !== null) {
108 $value = null;
109 if (ilObjMediaObject::_exists($this->value)) {
110 $origin = new ilObjMediaObject($this->value);
111 $path = $origin::_getRelativeDirectory($origin->getId()) . '/' . $origin->getTitle();
112 if ($this->getField()->getFileSystem()->has($path)) {
113 $new = $origin->duplicate();
114 $new->createDirectory();
115 $new_path = $origin::_getRelativeDirectory($new->getId()) . '/' . $new->getTitle();
116 $this->getField()->getFileSystem()->copy($path, $new_path);
117 $value = $new->getId();
118 }
119 }
120 $this->setValue($value, true);
121 $this->doUpdate();
122 }
123 }
124}
setValue($value, bool $omit_parsing=false)
Set value for record field.
@noinspection AutoloadingIssuesInspection
parseExportValue($value)
Function to parse incoming data from form input value $value.
handleFileUpload(array $value, bool $has_save_confirmation)
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)
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.
Class ilMediaItem Media Item, component of a media object (file or reference)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _getRelativeDirectory(int $a_mob_id)
Get relative (to webspace dir) directory.
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.
Interface Location.
Definition: Location.php:33
$path
Definition: ltiservices.php:30
static http()
Fetches the global http state from ILIAS.
has(string $class_name)