ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 $fileXMLParser->updateFileContents();
191
192 return $file->update();
193 }
194 }
195 catch(ilFileException $exception)
196 {
197 return $this->__raiseError($exception->getMessage(),
198 $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
199 }
200 return false;
201 }
202
213 function getFileXML ($sid, $ref_id, $attachFileContentsMode)
214 {
215 $this->initAuth($sid);
216 $this->initIlias();
217
218 if(!$this->__checkSession($sid))
219 {
220 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
221 }
222 if(!strlen($ref_id))
223 {
224 return $this->__raiseError('No ref id given. Aborting!',
225 'Client');
226 }
227 global $rbacsystem, $tree, $ilLog, $ilAccess;
228
229
230 // get obj_id
231 if(!$obj_id = ilObject::_lookupObjectId($ref_id))
232 {
233 return $this->__raiseError('No File found for id: '.$ref_id,
234 'Client');
235 }
236
238 {
239 return $this->__raiseError("Object with ID $ref_id has been deleted.", 'Client');
240 }
241
242 // Check access
243 $permission_ok = false;
244 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
245 {
246 if($ilAccess->checkAccess('read','',$ref_id))
247 {
248 $permission_ok = true;
249 break;
250 }
251 }
252
253 if(!$permission_ok)
254 {
255 return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
256 'Server');
257 }
258
260
261 if (!is_object($file) || $file->getType()!= "file")
262 {
263 return $this->__raiseError('Wrong obj id or type for File with id '.$ref_id,
264 'Server');
265 }
266 // store into xml result set
267 include_once './Modules/File/classes/class.ilFileXMLWriter.php';
268
269 // create writer
270 $xmlWriter = new ilFileXMLWriter();
271 $xmlWriter->setFile($file);
272 $xmlWriter->setAttachFileContents($attachFileContentsMode);
273 $xmlWriter->start();
274
275 return $xmlWriter->getXML();
276 }
277}
278?>
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