ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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): void
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 
173  protected function updateCopyright(): void
174  {
175  global $DIC;
176 
177  $lom_services = $DIC->learningObjectMetadata();
178 
179  $copyright_id = $this->getCopyrightID();
180  if (!$lom_services->copyrightHelper()->isCopyrightSelectionActive() || $copyright_id === null) {
181  return;
182  }
183 
184  $lom_services->copyrightHelper()->prepareCreateOrUpdateOfCopyrightFromPreset(
185  $lom_services->manipulate($this->getId(), 0, $this->getType()),
186  $copyright_id
187  )->execute();
188  }
189 
190  protected function getPathToSize(): Path
191  {
192  global $DIC;
193 
194  return $DIC->learningObjectMetadata()
195  ->paths()
196  ->custom()
197  ->withNextStep('technical')
198  ->withNextStep('size')
199  ->get();
200  }
201 
202  protected function getPathToFirstFormat(): Path
203  {
204  global $DIC;
205 
206  return $DIC->learningObjectMetadata()
207  ->paths()
208  ->custom()
209  ->withNextStep('technical')
210  ->withNextStep('format')
211  ->withAdditionalFilterAtCurrentStep(FilterType::INDEX, '0')
212  ->get();
213  }
214 
215  protected function getPathToVersion(): Path
216  {
217  global $DIC;
218 
219  return $DIC->learningObjectMetadata()
220  ->paths()
221  ->custom()
222  ->withNextStep('lifeCycle')
223  ->withNextStep('version')
224  ->withNextStep('string')
225  ->get();
226  }
227 }
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
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