ILIAS  Release_4_1_x_branch Revision 61804
 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','root');
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  if ($exerciseXMLParser->start()) {
104  $exerciseXMLParser->getAssignment()->update();
105  return $exercise->update() ? $exercise->getRefId() : -1;
106  }
107  throw new ilExerciseException ("Could not parse XML");
108  } catch(ilExerciseException $exception) {
109  return $this->__raiseError($exception->getMessage(),
110  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
111  }
112  }
113 
114 
124  function updateExercise ($sid, $ref_id, $exercise_xml)
125  {
126  $this->initAuth($sid);
127  $this->initIlias();
128 
129  if(!$this->__checkSession($sid))
130  {
131  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
132  }
133  global $rbacsystem, $tree, $ilLog;
134 
136  {
137  return $this->__raiseError('Cannot perform update since exercise has been deleted.', 'CLIENT_OBJECT_DELETED');
138  }
139  // get obj_id
140  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
141  {
142  return $this->__raiseError('No exercise found for id: '.$ref_id,
143  'CLIENT_OBJECT_NOT_FOUND');
144  }
145 
146  // Check access
147  $permission_ok = false;
148  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
149  {
150  if($rbacsystem->checkAccess('edit',$ref_id))
151  {
152  $permission_ok = true;
153  break;
154  }
155  }
156 
157  if(!$permission_ok)
158  {
159  return $this->__raiseError('No permission to edit the exercise with id: '.$ref_id,
160  'Server');
161  }
162 
163 
164  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
165 
166  if (!is_object($exercise) || $exercise->getType()!= "exc")
167  {
168  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
169  'CLIENT_OBJECT_NOI_FOUND');
170  }
171 
172  include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
173  include_once './Modules/Exercise/classes/class.ilExerciseException.php';
174  $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml, $obj_id);
175 
176  try
177  {
178  if ($exerciseXMLParser->start()) {
179  $exerciseXMLParser->getAssignment()->update();
180  return $exercise->update();
181  }
182  throw new ilExerciseException ("Could not parse XML");
183  } catch(ilExerciseException $exception) {
184  return $this->__raiseError($exception->getMessage(),
185  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
186  }
187  return false;
188  }
189 
200  function getExerciseXML ($sid, $ref_id, $attachFileContentsMode) {
201 
202  $this->initAuth($sid);
203  $this->initIlias();
204 
205  if(!$this->__checkSession($sid))
206  {
207  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
208  }
209  if(!strlen($ref_id))
210  {
211  return $this->__raiseError('No ref id given. Aborting!',
212  'Client');
213  }
214  global $rbacsystem, $tree, $ilLog;
215 
216  // get obj_id
217  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
218  {
219  return $this->__raiseError('No exercise found for id: '.$ref_id,
220  'Client');
221  }
222 
224  {
225  return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'Client');
226  }
227 
228 
229 
230  // Check access
231  $permission_ok = false;
232  $write_permission_ok = false;
233  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
234  {
235  if($rbacsystem->checkAccess('edit',$ref_id))
236  {
237  $write_permission_ok = true;
238  break;
239  }
240  if($rbacsystem->checkAccess('read',$ref_id))
241  {
242  $permission_ok = true;
243  break;
244  }
245 
246  }
247 
248  if(!$permission_ok && !$write_permission_ok)
249  {
250  return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
251  'Server');
252  }
253 
254  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
255 
256  if (!is_object($exercise) || $exercise->getType()!= "exc")
257  {
258  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
259  'Server');
260  }
261  // store into xml result set
262  include_once './Modules/Exercise/classes/class.ilExerciseXMLWriter.php';
263 
264  // create writer
265  $xmlWriter = new ilExerciseXMLWriter();
266  $xmlWriter->setExercise($exercise);
267  $xmlWriter->setAttachMembers($write_permission_ok);
268  $xmlWriter->setAttachFileContents($attachFileContentsMode);
269  $xmlWriter->start();
270 
271  return $xmlWriter->getXML();
272  }
273 }
274 ?>