ILIAS  release_8 Revision v8.24
trait.ilObjFileMetadata.php
Go to the documentation of this file.
1<?php
2
9{
10 protected ?bool $no_meta_data_creation = null;
11
12 protected function updateFileData(): void
13 {
14 global $DIC;
15 $check_existing = $DIC->database()->queryF(
16 'SELECT file_id FROM file_data WHERE file_id = %s',
17 ['integer'],
18 [$this->getId()]
19 );
20 if ($check_existing->numRows() === 0) {
21 $DIC->database()->insert('file_data', $this->getArrayForDatabase());
22 } else {
23 $DIC->database()->update(
24 'file_data',
25 $this->getArrayForDatabase(),
26 ['file_id' => ['integer', $this->getId()]]
27 );
28 }
29 }
30
38 public function createProperties(bool $a_upload = false): void
39 {
40 global $DIC;
41
42 // New Item
43 if (isset($this->ref_id)) {
44 $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($this->ref_id);
45 if ($default_visibility === "public") {
46 ilBlockSetting::_write("news", "public_notifications", 1, 0, $this->getId());
47 }
48 }
49 $this->updateFileData();
50
51 // no meta data handling for file list files
52 if ($this->getMode() !== self::MODE_FILELIST) {
53 $this->createMetaData();
54 }
55 }
56
57 public function setNoMetaDataCreation(bool $a_status)
58 {
59 $this->no_meta_data_creation = $a_status;
60 }
61
62 protected function beforeCreateMetaData(): bool
63 {
64 return !(bool) $this->no_meta_data_creation;
65 }
66
67 protected function beforeUpdateMetaData(): bool
68 {
69 return !(bool) $this->no_meta_data_creation;
70 }
71
75 protected function doCreateMetaData(): void
76 {
77 return; // add technical section with file size and format
78 $md_obj = new ilMD($this->getId(), 0, $this->getType());
79 $technical = $md_obj->addTechnical();
80 $technical->setSize($this->getFileSize());
81 $technical->save();
82 $format = $technical->addFormat();
83 $format->setFormat($this->getFileType());
84 $format->save();
85 $technical->update();
86 }
87
88 protected function beforeMDUpdateListener(string $a_element): bool
89 {
90 // Check file extension
91 // Removing the file extension is not allowed
92 $md = new ilMD($this->getId(), 0, $this->getType());
93 if (!is_object($md_gen = $md->getGeneral())) {
94 return false;
95 }
96 $title = $this->appendSuffixToTitle($md_gen->getTitle(), $this->getFileName());
97 $md_gen->setTitle($title);
98 $md_gen->update();
99
100 return true;
101 }
102
103 protected function doMDUpdateListener(string $a_element): void
104 {
105 // handling for technical section
106 switch ($a_element) {
107 case 'Technical':
108
109 // Update Format (size is not stored in db)
110 $md = new ilMD($this->getId(), 0, $this->getType());
111 if (!is_object($md_technical = $md->getTechnical())) {
112 return;
113 }
114
115 foreach ($md_technical->getFormatIds() as $id) {
116 $md_format = $md_technical->getFormat($id);
117 $this->setFileType($md_format->getFormat());
118 break;
119 }
120
121 break;
122 }
123 }
124
128 protected function doUpdateMetaData(): void
129 {
130 return;// add technical section with file size and format
131 $md_obj = new ilMD($this->getId(), 0, $this->getType());
132 if (!is_object($technical = $md_obj->getTechnical())) {
133 $technical = $md_obj->addTechnical();
134 $technical->save();
135 }
136 $technical->setSize($this->getFileSize());
137
138 $format_ids = $technical->getFormatIds();
139 if (count($format_ids) > 0) {
140 $format = $technical->getFormat($format_ids[0]);
141 $format->setFormat($this->getFileType());
142 $format->update();
143 } else {
144 $format = $technical->addFormat();
145 $format->setFormat($this->getFileType());
146 $format->save();
147 }
148 $technical->update();
149 }
150}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
static _getDefaultVisibilityForRefId(int $a_ref_id)
Get default visibility for reference id.
global $DIC
Definition: feed.php:28
$format
Definition: metadata.php:235
createProperties(bool $a_upload=false)
The basic properties of a file object are stored in table object_data.
doUpdateMetaData()
update meta data
beforeMDUpdateListener(string $a_element)
beforeUpdateMetaData()
beforeCreateMetaData()
doMDUpdateListener(string $a_element)
doCreateMetaData()
create file object meta data
setNoMetaDataCreation(bool $a_status)
trait ilObjFileMetadata
Trait ilObjFileMetadata.