ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
trait.ilObjFileMetadata.php
Go to the documentation of this file.
1 <?php
2 
21 
28 {
29  protected ?bool $no_meta_data_creation = null;
30 
31  protected function updateFileData(): void
32  {
33  global $DIC;
34  $check_existing = $DIC->database()->queryF(
35  'SELECT file_id FROM file_data WHERE file_id = %s',
36  ['integer'],
37  [$this->getId()]
38  );
39  if ($check_existing->numRows() === 0) {
40  $DIC->database()->insert('file_data', $this->getArrayForDatabase());
41  } else {
42  $DIC->database()->update(
43  'file_data',
44  $this->getArrayForDatabase(),
45  ['file_id' => ['integer', $this->getId()]]
46  );
47  }
48  }
49 
57  public function createProperties(bool $a_upload = false): void
58  {
59  global $DIC;
60 
61  // New Item
62  if (isset($this->ref_id)) {
63  $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($this->ref_id);
64  if ($default_visibility === "public") {
65  ilBlockSetting::_write("news", "public_notifications", 1, 0, $this->getId());
66  }
67  }
68  $this->updateFileData();
69 
70  // no meta data handling for file list files
71  if ($this->getMode() !== self::MODE_FILELIST) {
72  $this->createMetaData();
73  }
74  }
75 
76  public function setNoMetaDataCreation(bool $a_status)
77  {
78  $this->no_meta_data_creation = $a_status;
79  }
80 
81  protected function beforeCreateMetaData(): bool
82  {
83  return !(bool) $this->no_meta_data_creation;
84  }
85 
86  protected function beforeUpdateMetaData(): bool
87  {
88  return !(bool) $this->no_meta_data_creation;
89  }
90 
94  protected function doCreateMetaData(): void
95  {
96  global $DIC;
97 
98  // add file size and format to LOM
99  $manipulator = $DIC->learningObjectMetadata()
100  ->manipulate($this->getId(), 0, $this->getType())
101  ->prepareCreateOrUpdate($this->getPathToSize(), (string) $this->getFileSize())
102  ->prepareCreateOrUpdate($this->getPathToVersion(), (string) $this->getVersion());
103  if ($this->getFileType() !== '') {
104  $manipulator = $manipulator->prepareCreateOrUpdate($this->getPathToFirstFormat(), $this->getFileType());
105  }
106  $manipulator->execute();
107  }
108 
109  protected function beforeMDUpdateListener(string $a_element): bool
110  {
111  global $DIC;
112 
113  // Check file extension
114  // Removing the file extension is not allowed
115  if ($a_element !== 'General') {
116  return true;
117  }
118 
119  $paths = $DIC->learningObjectMetadata()->paths();
120 
121  $title = $DIC->learningObjectMetadata()->read(
122  $this->getId(),
123  0,
124  $this->getType(),
125  $paths->title()
126  )->firstData($paths->title())->value();
127 
128  $title = $this->appendSuffixToTitle($title, $this->getFileName());
129 
130  $DIC->learningObjectMetadata()->manipulate($this->getId(), 0, $this->getType())
131  ->prepareCreateOrUpdate($paths->title(), $title)
132  ->execute();
133 
134  return true;
135  }
136 
137  protected function doMDUpdateListener(string $a_element): void
138  {
139  global $DIC;
140 
141  // handling for technical section
142  if ($a_element !== 'Technical') {
143  return;
144  }
145 
146  $first_format = $DIC->learningObjectMetadata()->read(
147  $this->getId(),
148  0,
149  $this->getType(),
150  $this->getPathToFirstFormat()
151  )->firstData($this->getPathToFirstFormat())->value();
152 
153  $this->setFileType($first_format);
154  }
155 
159  protected function doUpdateMetaData(): void
160  {
161  global $DIC;
162 
163  $manipulator = $DIC->learningObjectMetadata()
164  ->manipulate($this->getId(), 0, $this->getType())
165  ->prepareCreateOrUpdate($this->getPathToSize(), (string) $this->getFileSize())
166  ->prepareCreateOrUpdate($this->getPathToVersion(), (string) $this->getVersion());
167  if ($this->getFileType() !== '') {
168  $manipulator = $manipulator->prepareCreateOrUpdate($this->getPathToFirstFormat(), $this->getFileType());
169  }
170  $manipulator->execute();
171  }
172 
176  protected function updateCopyright(): void
177  {
178  global $DIC;
179 
180  $lom_services = $DIC->learningObjectMetadata();
181 
182  $copyright_id = $this->getCopyrightID();
183  if (!$lom_services->copyrightHelper()->isCopyrightSelectionActive() || $copyright_id === null) {
184  return;
185  }
186 
187  $lom_services->copyrightHelper()->prepareCreateOrUpdateOfCopyrightFromPreset(
188  $lom_services->manipulate($this->getId(), 0, $this->getType()),
189  $copyright_id
190  )->execute();
191  }
192 
193  protected function getPathToSize(): Path
194  {
195  global $DIC;
196 
197  return $DIC->learningObjectMetadata()
198  ->paths()
199  ->custom()
200  ->withNextStep('technical')
201  ->withNextStep('size')
202  ->get();
203  }
204 
205  protected function getPathToFirstFormat(): Path
206  {
207  global $DIC;
208 
209  return $DIC->learningObjectMetadata()
210  ->paths()
211  ->custom()
212  ->withNextStep('technical')
213  ->withNextStep('format')
214  ->withAdditionalFilterAtCurrentStep(FilterType::INDEX, '0')
215  ->get();
216  }
217 
218  protected function getPathToVersion(): Path
219  {
220  global $DIC;
221 
222  return $DIC->learningObjectMetadata()
223  ->paths()
224  ->custom()
225  ->withNextStep('lifeCycle')
226  ->withNextStep('version')
227  ->withNextStep('string')
228  ->get();
229  }
230 }
setNoMetaDataCreation(bool $a_status)
static _getDefaultVisibilityForRefId(int $a_ref_id)
Get default visibility for reference id.
getPathToFirstFormat()
beforeUpdateMetaData()
FilterType
Values should always be all lowercase.
Definition: FilterType.php:26
doUpdateMetaData()
update meta data
doMDUpdateListener(string $a_element)
global $DIC
Definition: shib_login.php:25
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
beforeMDUpdateListener(string $a_element)
createProperties(bool $a_upload=false)
The basic properties of a file object are stored in table object_data.
beforeCreateMetaData()
doCreateMetaData()
create file object meta data
updateCopyright()
update copyright meta data