ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
trait.ilObjFileMetadata.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected ?bool $no_meta_data_creation = null;
27 
28  protected function updateFileData(): void
29  {
30  global $DIC;
31  $check_existing = $DIC->database()->queryF(
32  'SELECT file_id FROM file_data WHERE file_id = %s',
33  ['integer'],
34  [$this->getId()]
35  );
36  if ($check_existing->numRows() === 0) {
37  $DIC->database()->insert('file_data', $this->getArrayForDatabase());
38  } else {
39  $DIC->database()->update(
40  'file_data',
41  $this->getArrayForDatabase(),
42  ['file_id' => ['integer', $this->getId()]]
43  );
44  }
45  }
46 
54  public function createProperties(bool $a_upload = false): void
55  {
56  global $DIC;
57 
58  // New Item
59  if (isset($this->ref_id)) {
60  $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($this->ref_id);
61  if ($default_visibility === "public") {
62  ilBlockSetting::_write("news", "public_notifications", 1, 0, $this->getId());
63  }
64  }
65  $this->updateFileData();
66 
67  //add metadata to database
68  $metadata = [
69  'meta_lifecycle_id' => ['integer', $DIC->database()->nextId('il_meta_lifecycle')],
70  'rbac_id' => ['integer', $this->getId()],
71  'obj_id' => ['integer', $this->getId()],
72  'obj_type' => ['text', "file"],
73  'meta_version' => ['integer', (int) $this->getVersion()],
74  ];
75  $DIC->database()->insert('il_meta_lifecycle', $metadata);
76 
77  // no meta data handling for file list files
78  if ($this->getMode() !== self::MODE_FILELIST) {
79  $this->createMetaData();
80  }
81  }
82 
83  public function setNoMetaDataCreation(bool $a_status)
84  {
85  $this->no_meta_data_creation = $a_status;
86  }
87 
88  protected function beforeCreateMetaData(): bool
89  {
90  return !(bool) $this->no_meta_data_creation;
91  }
92 
93  protected function beforeUpdateMetaData(): bool
94  {
95  return !(bool) $this->no_meta_data_creation;
96  }
97 
101  protected function doCreateMetaData(): void
102  {
103  return; // add technical section with file size and format
104  $md_obj = new ilMD($this->getId(), 0, $this->getType());
105  $technical = $md_obj->addTechnical();
106  $technical->setSize($this->getFileSize());
107  $technical->save();
108  $format = $technical->addFormat();
109  $format->setFormat($this->getFileType());
110  $format->save();
111  $technical->update();
112  }
113 
114  protected function beforeMDUpdateListener(string $a_element): bool
115  {
116  // Check file extension
117  // Removing the file extension is not allowed
118  $md = new ilMD($this->getId(), 0, $this->getType());
119  if (!is_object($md_gen = $md->getGeneral())) {
120  return false;
121  }
122  $title = $this->appendSuffixToTitle($md_gen->getTitle(), $this->getFileName());
123  $md_gen->setTitle($title);
124  $md_gen->update();
125 
126  return true;
127  }
128 
129  protected function doMDUpdateListener(string $a_element): void
130  {
131  // handling for technical section
132  switch ($a_element) {
133  case 'Technical':
134 
135  // Update Format (size is not stored in db)
136  $md = new ilMD($this->getId(), 0, $this->getType());
137  if (!is_object($md_technical = $md->getTechnical())) {
138  return;
139  }
140 
141  foreach ($md_technical->getFormatIds() as $id) {
142  $md_format = $md_technical->getFormat($id);
143  $this->setFileType($md_format->getFormat());
144  break;
145  }
146 
147  break;
148  }
149  }
150 
154  protected function doUpdateMetaData(): void
155  {
156  global $DIC;
157  $md_obj = new ilMD($this->getId(), 0, $this->getType());
158  if (!is_object($technical = $md_obj->getTechnical())) {
159  $technical = $md_obj->addTechnical();
160  $technical->save();
161  }
162  $technical->setSize($this->getFileSize());
163 
164  $format_ids = $technical->getFormatIds();
165  if (count($format_ids) > 0) {
166  $format = $technical->getFormat($format_ids[0]);
167  $format->setFormat($this->getFileType());
168  $format->update();
169  } else {
170  $format = $technical->addFormat();
171  $format->setFormat($this->getFileType());
172  $format->save();
173  }
174  $technical->update();
175 
176  $meta_version_column = ['meta_version' => ['integer', (int) $this->getVersion()]];
177  $DIC->database()->update('il_meta_lifecycle', $meta_version_column, [
178  'rbac_id' => [
179  'integer',
180  $this->getId(),
181  ],
182  ]);
183  }
184 
188  protected function updateCopyright(): void
189  {
190  $copyright_id = $this->getCopyrightID();
191  if (!ilMDSettings::_getInstance()->isCopyrightSelectionActive() || $copyright_id === null) {
192  return;
193  }
194 
195  $md_obj = new ilMD($this->getId(), 0, $this->getType());
196  $rights = $md_obj->getRights();
197  if ($rights === null) {
198  $rights = $md_obj->addRights();
199  $rights->save();
200  }
201 
202  $rights->setCopyrightAndOtherRestrictions("Yes");
203  $rights->setDescription('il_copyright_entry__' . IL_INST_ID . '__' . $copyright_id);
204  $rights->update();
205  }
206 
207 }
setNoMetaDataCreation(bool $a_status)
static _getDefaultVisibilityForRefId(int $a_ref_id)
Get default visibility for reference id.
const IL_INST_ID
Definition: constants.php:40
$technical
beforeUpdateMetaData()
doUpdateMetaData()
update meta data
doMDUpdateListener(string $a_element)
global $DIC
Definition: feed.php:28
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)
$rights
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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