ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapExerciseAdministration.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 {
38  {
40  }
41 
51  function addExercise ($sid, $target_id, $exercise_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;
61 
62  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
63  {
64  return $this->__raiseError('No valid target given.', 'Client');
65  }
66 
68  {
69  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
70  }
71 
72  // Check access
73  $allowed_types = array('cat','grp','crs','fold');
74  if(!in_array($target_obj->getType(), $allowed_types))
75  {
76  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
77  }
78 
79  if(!$rbacsystem->checkAccess('create',$target_id,"exc"))
80  {
81  return $this->__raiseError('No permission to create exercises in target '.$target_id.'!', 'Client');
82  }
83 
84  // create object, put it into the tree and use the parser to update the settings
85  include_once './Modules/Exercise/classes/class.ilObjExercise.php';
86  include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
87  include_once './Modules/Exercise/classes/class.ilExerciseException.php';
88 
89 
90  $exercise = new ilObjExercise();
91  $exercise->create();
92  $exercise->createReference();
93  $exercise->putInTree($target_id);
94  $exercise->setPermissions($target_id);
95  $exercise->saveData();
96 
97  // we need this as workaround because file and member objects need to be initialised
98  $exercise->read();
99 
100  $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml);
101  try
102  {
103  return $exerciseXMLParser->start() && $exercise->update() ? $exercise->getRefId() : -1;
104  } catch(ilExerciseException $exception) {
105  return $this->__raiseError($exception->getMessage(),
106  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
107  }
108  }
109 
110 
120  function updateExercise ($sid, $ref_id, $exercise_xml)
121  {
122  $this->initAuth($sid);
123  $this->initIlias();
124 
125  if(!$this->__checkSession($sid))
126  {
127  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
128  }
129  global $rbacsystem, $tree, $ilLog;
130 
132  {
133  return $this->__raiseError('Cannot perform update since exercise has been deleted.', 'CLIENT_OBJECT_DELETED');
134  }
135  // get obj_id
136  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
137  {
138  return $this->__raiseError('No exercise found for id: '.$ref_id,
139  'CLIENT_OBJECT_NOT_FOUND');
140  }
141 
142  // Check access
143  $permission_ok = false;
144  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
145  {
146  if($rbacsystem->checkAccess('edit',$ref_id))
147  {
148  $permission_ok = true;
149  break;
150  }
151  }
152 
153  if(!$permission_ok)
154  {
155  return $this->__raiseError('No permission to edit the exercise with id: '.$ref_id,
156  'Server');
157  }
158 
159 
160  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
161 
162  if (!is_object($exercise) || $exercise->getType()!= "exc")
163  {
164  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
165  'CLIENT_OBJECT_NOI_FOUND');
166  }
167 
168  include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
169  include_once './Modules/Exercise/classes/class.ilExerciseException.php';
170  $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml, $obj_id);
171 
172  try
173  {
174  return $exerciseXMLParser->start() && $exercise->update();
175  } catch(ilExerciseException $exception) {
176  return $this->__raiseError($exception->getMessage(),
177  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
178  }
179  return false;
180  }
181 
192  function getExerciseXML ($sid, $ref_id, $attachFileContentsMode) {
193 
194  $this->initAuth($sid);
195  $this->initIlias();
196 
197  if(!$this->__checkSession($sid))
198  {
199  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
200  }
201  if(!strlen($ref_id))
202  {
203  return $this->__raiseError('No ref id given. Aborting!',
204  'Client');
205  }
206  global $rbacsystem, $tree, $ilLog;
207 
208  // get obj_id
209  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
210  {
211  return $this->__raiseError('No exercise found for id: '.$ref_id,
212  'Client');
213  }
214 
216  {
217  return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'Client');
218  }
219 
220 
221 
222  // Check access
223  $permission_ok = false;
224  $write_permission_ok = false;
225  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
226  {
227  if($rbacsystem->checkAccess('edit',$ref_id))
228  {
229  $write_permission_ok = true;
230  break;
231  }
232  if($rbacsystem->checkAccess('read',$ref_id))
233  {
234  $permission_ok = true;
235  break;
236  }
237 
238  }
239 
240  if(!$permission_ok && !$write_permission_ok)
241  {
242  return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
243  'Server');
244  }
245 
246  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
247 
248  if (!is_object($exercise) || $exercise->getType()!= "exc")
249  {
250  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
251  'Server');
252  }
253  // store into xml result set
254  include_once './Modules/Exercise/classes/class.ilExerciseXMLWriter.php';
255 
256  // create writer
257  $xmlWriter = new ilExerciseXMLWriter();
258  $xmlWriter->setExercise($exercise);
259  $xmlWriter->setAttachMembers($write_permission_ok);
260  $xmlWriter->setAttachFileContents($attachFileContentsMode);
261  $xmlWriter->start();
262 
263  return $xmlWriter->getXML();
264  }
265 }
266 ?>