ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSoapFileAdministration.php
Go to the documentation of this file.
1<?php
23{
27 public function addFile(string $sid, int $target_id, string $file_xml)
28 {
29 $this->initAuth($sid);
30 $this->initIlias();
31
32 if (!$this->checkSession($sid)) {
33 return $this->raiseError($this->getMessage(), $this->getMessageCode());
34 }
35 global $DIC;
36
37 $ilAccess = $DIC['ilAccess'];
38
39 if (!$target_obj = ilObjectFactory::getInstanceByRefId($target_id, false)) {
40 return $this->raiseError('No valid target given.', 'Client');
41 }
42
43 if (ilObject::_isInTrash($target_id)) {
44 return $this->raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
45 }
46
47 $allowed_types = array('cat', 'grp', 'crs', 'fold', 'root');
48 if (!in_array($target_obj->getType(), $allowed_types)) {
49 return $this->raiseError(
50 'No valid target type. Target must be reference id of "course, group, category or folder"',
51 'Client'
52 );
53 }
54
55 if (!$ilAccess->checkAccess('create', '', $target_id, "file")) {
56 return $this->raiseError('No permission to create Files in target ' . $target_id . '!', 'Client');
57 }
58
59 // create object, put it into the tree and use the parser to update the settings
60
61 $file = new ilObjFile();
62 try {
63 $fileXMLParser = new ilFileXMLParser($file, $file_xml);
64
65 if ($fileXMLParser->start()) {
66 global $DIC;
67
68 $ilLog = $DIC['ilLog'];
69
70 $ilLog->write(__METHOD__ . ': File type: ' . $file->getFileType());
71
72 $file->create();
73 $file->createReference();
74 $file->putInTree($target_id);
75 $file->setPermissions($target_id);
76
77 // we now can save the file contents since we know the obj id now.
78 $fileXMLParser->setFileContents();
79 #$file->update();
80
81 return $file->getRefId();
82 }
83
84 return $this->raiseError("Could not add file", "Server");
85 } catch (ilFileException $exception) {
86 return $this->raiseError(
87 $exception->getMessage(),
88 $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server"
89 );
90 }
91 }
92
96 public function updateFile(string $sid, int $requested_ref_id, string $file_xml)
97 {
98 $this->initAuth($sid);
99 $this->initIlias();
100
101 if (!$this->checkSession($sid)) {
102 return $this->raiseError($this->getMessage(), $this->getMessageCode());
103 }
104 global $DIC;
105
106 $rbacsystem = $DIC['rbacsystem'];
107 $tree = $DIC['tree'];
108 $ilLog = $DIC['ilLog'];
109 $ilAccess = $DIC['ilAccess'];
110
112 return $this->raiseError('Cannot perform update since file has been deleted.', 'CLIENT_OBJECT_DELETED');
113 }
114
116 return $this->raiseError(
117 'No File found for id: ' . $requested_ref_id,
118 'Client'
119 );
120 }
121
122 $permission_ok = false;
123 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
124 if ($ilAccess->checkAccess('write', '', $ref_id)) {
125 $permission_ok = true;
126 break;
127 }
128 }
129
130 if (!$permission_ok) {
131 return $this->raiseError(
132 'No permission to edit the File with id: ' . $requested_ref_id,
133 'Server'
134 );
135 }
136
138 $file = ilObjectFactory::getInstanceByObjId($obj_id, false);
139
140 if (!is_object($file) || $file->getType() !== "file") {
141 return $this->raiseError(
142 'Wrong obj id or type for File with id ' . $requested_ref_id,
143 'Server'
144 );
145 }
146
147 $fileXMLParser = new ilFileXMLParser($file, $file_xml, $obj_id);
148
149 try {
150 if ($fileXMLParser->start()) {
151 $fileXMLParser->updateFileContents();
152
153 return $file->update();
154 }
155 } catch (ilFileException $exception) {
156 return $this->raiseError(
157 $exception->getMessage(),
158 $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server"
159 );
160 }
161 return false;
162 }
163
167 public function getFileXML(string $sid, int $requested_ref_id, int $attachFileContentsMode)
168 {
169 $this->initAuth($sid);
170 $this->initIlias();
171
172 if (!$this->checkSession($sid)) {
173 return $this->raiseError($this->getMessage(), $this->getMessageCode());
174 }
175
176 if (!($requested_ref_id > 0)) {
177 return $this->raiseError(
178 'No ref id given. Aborting!',
179 'Client'
180 );
181 }
182
183 global $DIC;
184
185 $rbacsystem = $DIC['rbacsystem'];
186 $tree = $DIC['tree'];
187 $ilLog = $DIC['ilLog'];
188 $ilAccess = $DIC['ilAccess'];
189
191 return $this->raiseError(
192 'No File found for id: ' . $requested_ref_id,
193 'Client'
194 );
195 }
196
198 return $this->raiseError("Object with ID $requested_ref_id has been deleted.", 'Client');
199 }
200
201 $permission_ok = false;
202 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
203 if ($ilAccess->checkAccess('read', '', $ref_id)) {
204 $permission_ok = true;
205 break;
206 }
207 }
208
209 if (!$permission_ok) {
210 return $this->raiseError(
211 'No permission to edit the object with id: ' . $requested_ref_id,
212 'Server'
213 );
214 }
215
217 $file = ilObjectFactory::getInstanceByObjId($obj_id, false);
218
219 if (!is_object($file) || $file->getType() !== "file") {
220 return $this->raiseError(
221 'Wrong obj id or type for File with id ' . $requested_ref_id,
222 'Server'
223 );
224 }
225
226
227 $xmlWriter = new ilFileXMLWriter();
228 $xmlWriter->setFile($file);
229 $xmlWriter->setAttachFileContents($attachFileContentsMode);
230 $xmlWriter->start();
231
232 return $xmlWriter->getXML();
233 }
234}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFile.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjectId(int $ref_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _isInTrash(int $ref_id)
raiseError(string $a_message, $a_code)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addFile(string $sid, int $target_id, string $file_xml)
$requested_ref_id
Definition: feed.php:40
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26