ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilSoapFileAdministration.php
Go to the documentation of this file.
1<?php
2 /*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22 */
23
24
33include_once './webservice/soap/classes/class.ilSoapAdministration.php';
34
36{
38 {
39 parent::ilSoapAdministration();
40 }
41
51 function addFile ($sid, $target_id, $file_xml) {
52
53 $this->initAuth($sid);
54 $this->initIlias();
55
56 if(!$this->__checkSession($sid))
57 {
58 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
59 }
60 global $rbacsystem, $tree, $ilLog, $ilAccess;
61
62 if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
63 {
64 return $this->__raiseError('No valid target given.', 'Client');
65 }
66
67
69 {
70 return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
71 }
72
73 // Check access
74 $allowed_types = array('cat','grp','crs','fold','root');
75 if(!in_array($target_obj->getType(), $allowed_types))
76 {
77 return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
78 }
79
80 if(!$ilAccess->checkAccess('create','',$target_id,"file"))
81 {
82 return $this->__raiseError('No permission to create Files in target '.$target_id.'!', 'Client');
83 }
84
85 // create object, put it into the tree and use the parser to update the settings
86 include_once './Modules/File/classes/class.ilFileXMLParser.php';
87 include_once './Modules/File/classes/class.ilFileException.php';
88 include_once './Modules/File/classes/class.ilObjFile.php';
89
90 $file = new ilObjFile();
91 try
92 {
93
94 $fileXMLParser = new ilFileXMLParser($file, $file_xml);
95
96 if ($fileXMLParser->start())
97 {
98 global $ilLog;
99
100 $ilLog->write(__METHOD__.': File type: '.$file->getFileType());
101
102 $file->create();
103 $file->createReference();
104 $file->putInTree($target_id);
105 $file->setPermissions($target_id);
106
107 // we now can save the file contents since we know the obj id now.
108 $fileXMLParser->setFileContents();
109 #$file->update();
110
111 return $file->getRefId();
112 }
113 else
114 {
115 return $this->__raiseError("Could not add file", "Server");
116 }
117 }
118 catch(ilFileException $exception) {
119 return $this->__raiseError($exception->getMessage(), $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
120 }
121 }
122
123
133 function updateFile ($sid, $ref_id, $file_xml)
134 {
135 $this->initAuth($sid);
136 $this->initIlias();
137
138 if(!$this->__checkSession($sid))
139 {
140 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
141 }
142 global $rbacsystem, $tree, $ilLog, $ilAccess;
143
145 {
146 return $this->__raiseError('Cannot perform update since file has been deleted.', 'CLIENT_OBJECT_DELETED');
147 }
148 // get obj_id
149 if(!$obj_id = ilObject::_lookupObjectId($ref_id))
150 {
151 return $this->__raiseError('No File found for id: '.$ref_id,
152 'Client');
153 }
154
155 // Check access
156 $permission_ok = false;
157 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
158 {
159 if($ilAccess->checkAccess('write','',$ref_id))
160 {
161 $permission_ok = true;
162 break;
163 }
164 }
165
166 if(!$permission_ok)
167 {
168 return $this->__raiseError('No permission to edit the File with id: '.$ref_id,
169 'Server');
170 }
171
172
174
175 if (!is_object($file) || $file->getType()!= "file")
176 {
177 return $this->__raiseError('Wrong obj id or type for File with id '.$ref_id,
178 'Server');
179 }
180
181 include_once './Modules/File/classes/class.ilFileXMLParser.php';
182 include_once './Modules/File/classes/class.ilFileException.php';
183 $fileXMLParser = new ilFileXMLParser($file, $file_xml, $obj_id);
184
185 try
186 {
187
188 if ($fileXMLParser->start())
189 {
190 $file->setVersion($file->getVersion() + 1);
191 $fileXMLParser->updateFileContents();
192
193 return $file->update();
194 }
195 }
196 catch(ilFileException $exception)
197 {
198 return $this->__raiseError($exception->getMessage(),
199 $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
200 }
201 return false;
202 }
203
214 function getFileXML ($sid, $ref_id, $attachFileContentsMode)
215 {
216 $this->initAuth($sid);
217 $this->initIlias();
218
219 if(!$this->__checkSession($sid))
220 {
221 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
222 }
223 if(!strlen($ref_id))
224 {
225 return $this->__raiseError('No ref id given. Aborting!',
226 'Client');
227 }
228 global $rbacsystem, $tree, $ilLog, $ilAccess;
229
230
231 // get obj_id
232 if(!$obj_id = ilObject::_lookupObjectId($ref_id))
233 {
234 return $this->__raiseError('No File found for id: '.$ref_id,
235 'Client');
236 }
237
239 {
240 return $this->__raiseError("Object with ID $ref_id has been deleted.", 'Client');
241 }
242
243 // Check access
244 $permission_ok = false;
245 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
246 {
247 if($ilAccess->checkAccess('read','',$ref_id))
248 {
249 $permission_ok = true;
250 break;
251 }
252 }
253
254 if(!$permission_ok)
255 {
256 return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
257 'Server');
258 }
259
261
262 if (!is_object($file) || $file->getType()!= "file")
263 {
264 return $this->__raiseError('Wrong obj id or type for File with id '.$ref_id,
265 'Server');
266 }
267 // store into xml result set
268 include_once './Modules/File/classes/class.ilFileXMLWriter.php';
269
270 // create writer
271 $xmlWriter = new ilFileXMLWriter();
272 $xmlWriter->setFile($file);
273 $xmlWriter->setAttachFileContents($attachFileContentsMode);
274 $xmlWriter->start();
275
276 return $xmlWriter->getXML();
277 }
278}
279?>
print $file
Class to report exception.
Exercise XML Parser which completes/updates a given file by an xml string.
XML writer class.
Class ilObjFile.
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
_isInTrash($a_ref_id)
checks wether object is in trash
static _lookupObjectId($a_ref_id)
lookup object id
static _getAllReferences($a_id)
get all reference ids of object
__raiseError($a_message, $a_code)
updateFile($sid, $ref_id, $file_xml)
update a File with id.
addFile($sid, $target_id, $file_xml)
add an File with id.
getFileXML($sid, $ref_id, $attachFileContentsMode)
get File xml
$target_id
Definition: goto.php:88
$ref_id
Definition: sahs_server.php:39