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