ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
37
47 function addFile ($sid, $target_id, $file_xml) {
48
49 $this->initAuth($sid);
50 $this->initIlias();
51
52 if(!$this->__checkSession($sid))
53 {
54 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
55 }
56 global $rbacsystem, $tree, $ilLog, $ilAccess;
57
58 if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
59 {
60 return $this->__raiseError('No valid target given.', 'Client');
61 }
62
63
65 {
66 return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
67 }
68
69 // Check access
70 $allowed_types = array('cat','grp','crs','fold','root');
71 if(!in_array($target_obj->getType(), $allowed_types))
72 {
73 return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
74 }
75
76 if(!$ilAccess->checkAccess('create','',$target_id,"file"))
77 {
78 return $this->__raiseError('No permission to create Files in target '.$target_id.'!', 'Client');
79 }
80
81 // create object, put it into the tree and use the parser to update the settings
82 include_once './Modules/File/classes/class.ilFileXMLParser.php';
83 include_once './Modules/File/classes/class.ilFileException.php';
84 include_once './Modules/File/classes/class.ilObjFile.php';
85
86 $file = new ilObjFile();
87 try
88 {
89
90 $fileXMLParser = new ilFileXMLParser($file, $file_xml);
91
92 if ($fileXMLParser->start())
93 {
94 global $ilLog;
95
96 $ilLog->write(__METHOD__.': File type: '.$file->getFileType());
97
98 $file->create();
99 $file->createReference();
100 $file->putInTree($target_id);
101 $file->setPermissions($target_id);
102
103 // we now can save the file contents since we know the obj id now.
104 $fileXMLParser->setFileContents();
105 #$file->update();
106
107 return $file->getRefId();
108 }
109 else
110 {
111 return $this->__raiseError("Could not add file", "Server");
112 }
113 }
114 catch(ilFileException $exception) {
115 return $this->__raiseError($exception->getMessage(), $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
116 }
117 }
118
119
129 function updateFile ($sid, $ref_id, $file_xml)
130 {
131 $this->initAuth($sid);
132 $this->initIlias();
133
134 if(!$this->__checkSession($sid))
135 {
136 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
137 }
138 global $rbacsystem, $tree, $ilLog, $ilAccess;
139
141 {
142 return $this->__raiseError('Cannot perform update since file has been deleted.', 'CLIENT_OBJECT_DELETED');
143 }
144 // get obj_id
145 if(!$obj_id = ilObject::_lookupObjectId($ref_id))
146 {
147 return $this->__raiseError('No File found for id: '.$ref_id,
148 'Client');
149 }
150
151 // Check access
152 $permission_ok = false;
153 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
154 {
155 if($ilAccess->checkAccess('write','',$ref_id))
156 {
157 $permission_ok = true;
158 break;
159 }
160 }
161
162 if(!$permission_ok)
163 {
164 return $this->__raiseError('No permission to edit the File with id: '.$ref_id,
165 'Server');
166 }
167
168
170
171 if (!is_object($file) || $file->getType()!= "file")
172 {
173 return $this->__raiseError('Wrong obj id or type for File with id '.$ref_id,
174 'Server');
175 }
176
177 include_once './Modules/File/classes/class.ilFileXMLParser.php';
178 include_once './Modules/File/classes/class.ilFileException.php';
179 $fileXMLParser = new ilFileXMLParser($file, $file_xml, $obj_id);
180
181 try
182 {
183
184 if ($fileXMLParser->start())
185 {
186 $file->setVersion($file->getVersion() + 1);
187 $fileXMLParser->updateFileContents();
188
189 return $file->update();
190 }
191 }
192 catch(ilFileException $exception)
193 {
194 return $this->__raiseError($exception->getMessage(),
195 $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
196 }
197 return false;
198 }
199
210 function getFileXML ($sid, $ref_id, $attachFileContentsMode)
211 {
212 $this->initAuth($sid);
213 $this->initIlias();
214
215 if(!$this->__checkSession($sid))
216 {
217 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
218 }
219 if(!strlen($ref_id))
220 {
221 return $this->__raiseError('No ref id given. Aborting!',
222 'Client');
223 }
224 global $rbacsystem, $tree, $ilLog, $ilAccess;
225
226
227 // get obj_id
228 if(!$obj_id = ilObject::_lookupObjectId($ref_id))
229 {
230 return $this->__raiseError('No File found for id: '.$ref_id,
231 'Client');
232 }
233
235 {
236 return $this->__raiseError("Object with ID $ref_id has been deleted.", 'Client');
237 }
238
239 // Check access
240 $permission_ok = false;
241 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
242 {
243 if($ilAccess->checkAccess('read','',$ref_id))
244 {
245 $permission_ok = true;
246 break;
247 }
248 }
249
250 if(!$permission_ok)
251 {
252 return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
253 'Server');
254 }
255
257
258 if (!is_object($file) || $file->getType()!= "file")
259 {
260 return $this->__raiseError('Wrong obj id or type for File with id '.$ref_id,
261 'Server');
262 }
263 // store into xml result set
264 include_once './Modules/File/classes/class.ilFileXMLWriter.php';
265
266 // create writer
267 $xmlWriter = new ilFileXMLWriter();
268 $xmlWriter->setFile($file);
269 $xmlWriter->setAttachFileContents($attachFileContentsMode);
270 $xmlWriter->start();
271
272 return $xmlWriter->getXML();
273 }
274}
275?>
An exception for terminatinating execution or to throw for unit testing.
Class to report exception.
Exercise XML Parser which completes/updates a given file by an xml string.
XML writer class.
Class ilObjFile.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjectId($a_ref_id)
lookup object id
static _getAllReferences($a_id)
get all reference ids of object
static _isInTrash($a_ref_id)
checks wether object is in trash
initAuth($sid)
Init authentication.
__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:51
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$ref_id
Definition: sahs_server.php:39