ILIAS  release_7 Revision v7.30-3-g800a261c036
trait.ilObjFileMetadata.php
Go to the documentation of this file.
1<?php
2
8{
12 protected $no_meta_data_creation;
13
21 public function createProperties($a_upload = false)
22 {
23 global $DIC;
24
25 if ($a_upload) {
26 return true;
27 }
28
29 // New Item
30 $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($_GET['ref_id']);
31 if ($default_visibility === "public") {
32 ilBlockSetting::_write("news", "public_notifications", 1, 0, $this->getId());
33 }
34
35 // log creation
36 $this->log->debug("ilObjFile::createProperties, ID: " . $this->getId() . ", Name: "
37 . $this->getFileName() . ", Type: " . $this->getFileType() . ", Size: "
38 . $this->getFileSize() . ", Mode: " . $this->getMode() . ", Name(Bytes): "
39 . implode(":", ilStr::getBytesForString($this->getFileName())));
40 $this->log->logStack(ilLogLevel::DEBUG);
41
42 $DIC->database()->insert('file_data', $this->getArrayForDatabase());
43
44 // no meta data handling for file list files
45 if ($this->getMode() != self::MODE_FILELIST) {
46 $this->createMetaData();
47 }
48 }
49
53 public function setNoMetaDataCreation($a_status)
54 {
55 $this->no_meta_data_creation = (bool) $a_status;
56 }
57
58 protected function beforeCreateMetaData()
59 {
60 return !(bool) $this->no_meta_data_creation;
61 }
62
63 protected function beforeUpdateMetaData()
64 {
65 return !(bool) $this->no_meta_data_creation;
66 }
67
71 protected function doCreateMetaData()
72 {
73 // add technical section with file size and format
74 $md_obj = new ilMD($this->getId(), 0, $this->getType());
75 $technical = $md_obj->addTechnical();
76 $technical->setSize($this->getFileSize());
77 $technical->save();
78 $format = $technical->addFormat();
79 $format->setFormat($this->getFileType());
80 $format->save();
81 $technical->update();
82 }
83
84 protected function beforeMDUpdateListener($a_element)
85 {
86 // Check file extension
87 // Removing the file extension is not allowed
88 include_once 'Services/MetaData/classes/class.ilMD.php';
89 $md = new ilMD($this->getId(), 0, $this->getType());
90 if (!is_object($md_gen = $md->getGeneral())) {
91 return false;
92 }
93 $title = $this->checkFileExtension($this->getFileName(), $md_gen->getTitle());
94 $md_gen->setTitle($title);
95 $md_gen->update();
96
97 return true;
98 }
99
100 protected function doMDUpdateListener($a_element)
101 {
102 // handling for technical section
103 include_once 'Services/MetaData/classes/class.ilMD.php';
104
105 switch ($a_element) {
106 case 'Technical':
107
108 // Update Format (size is not stored in db)
109 $md = new ilMD($this->getId(), 0, $this->getType());
110 if (!is_object($md_technical = $md->getTechnical())) {
111 return false;
112 }
113
114 foreach ($md_technical->getFormatIds() as $id) {
115 $md_format = $md_technical->getFormat($id);
116 $this->setFileType($md_format->getFormat());
117 break;
118 }
119
120 break;
121 }
122
123 return true;
124 }
125
129 protected function doUpdateMetaData()
130 {
131 // add technical section with file size and format
132 $md_obj = new ilMD($this->getId(), 0, $this->getType());
133 if (!is_object($technical = $md_obj->getTechnical())) {
134 $technical = $md_obj->addTechnical();
135 $technical->save();
136 }
137 $technical->setSize($this->getFileSize());
138
139 $format_ids = $technical->getFormatIds();
140 if (count($format_ids) > 0) {
141 $format = $technical->getFormat($format_ids[0]);
142 $format->setFormat($this->getFileType());
143 $format->update();
144 } else {
145 $format = $technical->addFormat();
146 $format->setFormat($this->getFileType());
147 $format->save();
148 }
149 $technical->update();
150 }
151}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
static getBytesForString($a_str)
Return string as byte array Note: Use this for debugging purposes only.
global $DIC
Definition: goto.php:24
$format
Definition: metadata.php:218
doUpdateMetaData()
update meta data
beforeUpdateMetaData()
beforeCreateMetaData()
doCreateMetaData()
create file object meta data
beforeMDUpdateListener($a_element)
setNoMetaDataCreation($a_status)
trait ilObjFileMetadata
Trait ilObjFileMetadata.
doMDUpdateListener($a_element)
createProperties($a_upload=false)
The basic properties of a file object are stored in table object_data.