ILIAS  Release_3_10_x_branch Revision 61812
 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  if(!$this->__checkSession($sid))
53  {
54  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
55  }
56  include_once './include/inc.header.php';
57  global $rbacsystem, $tree, $ilLog;
58 
59  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
60  {
61  return $this->__raiseError('No valid target given.', 'Client');
62  }
63 
65  {
66  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
67  }
68 
69  // Check access
70  $allowed_types = array('cat','grp','crs','fold');
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(!$rbacsystem->checkAccess('create',$target_id,"exc"))
77  {
78  return $this->__raiseError('No permission to create exercises 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/Exercise/classes/class.ilObjExercise.php';
83  include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
84  include_once './Modules/Exercise/classes/class.ilExerciseException.php';
85 
86 
87  $exercise = new ilObjExercise();
88  $exercise->create();
89  $exercise->createReference();
90  $exercise->putInTree($target_id);
91  $exercise->setPermissions($target_id);
92  $exercise->saveData();
93 
94  // we need this as workaround because file and member objects need to be initialised
95  $exercise->read();
96 
97  $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml);
98  try
99  {
100  return $exerciseXMLParser->start() && $exercise->update() ? $exercise->getRefId() : -1;
101  } catch(ilExerciseException $exception) {
102  return $this->__raiseError($exception->getMessage(),
103  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
104  }
105  }
106 
107 
117  function updateExercise ($sid, $ref_id, $exercise_xml) {
118  if(!$this->__checkSession($sid))
119  {
120  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
121  }
122  include_once './include/inc.header.php';
123  global $rbacsystem, $tree, $ilLog;
124 
126  {
127  return $this->__raiseError('Cannot perform update since exercise has been deleted.', 'CLIENT_OBJECT_DELETED');
128  }
129  // get obj_id
130  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
131  {
132  return $this->__raiseError('No exercise found for id: '.$ref_id,
133  'CLIENT_OBJECT_NOT_FOUND');
134  }
135 
136  // Check access
137  $permission_ok = false;
138  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
139  {
140  if($rbacsystem->checkAccess('edit',$ref_id))
141  {
142  $permission_ok = true;
143  break;
144  }
145  }
146 
147  if(!$permission_ok)
148  {
149  return $this->__raiseError('No permission to edit the exercise with id: '.$ref_id,
150  'Server');
151  }
152 
153 
154  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
155 
156  if (!is_object($exercise) || $exercise->getType()!= "exc")
157  {
158  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
159  'CLIENT_OBJECT_NOI_FOUND');
160  }
161 
162  include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
163  include_once './Modules/Exercise/classes/class.ilExerciseException.php';
164  $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml, $obj_id);
165 
166  try
167  {
168  return $exerciseXMLParser->start() && $exercise->update();
169  } catch(ilExerciseException $exception) {
170  return $this->__raiseError($exception->getMessage(),
171  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
172  }
173  return false;
174  }
175 
186  function getExerciseXML ($sid, $ref_id, $attachFileContentsMode) {
187  if(!$this->__checkSession($sid))
188  {
189  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
190  }
191  if(!strlen($ref_id))
192  {
193  return $this->__raiseError('No ref id given. Aborting!',
194  'Client');
195  }
196  include_once './include/inc.header.php';
197  global $rbacsystem, $tree, $ilLog;
198 
199  // get obj_id
200  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
201  {
202  return $this->__raiseError('No exercise found for id: '.$ref_id,
203  'Client');
204  }
205 
207  {
208  return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'Client');
209  }
210 
211 
212 
213  // Check access
214  $permission_ok = false;
215  $write_permission_ok = false;
216  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
217  {
218  if($rbacsystem->checkAccess('edit',$ref_id))
219  {
220  $write_permission_ok = true;
221  break;
222  }
223  if($rbacsystem->checkAccess('read',$ref_id))
224  {
225  $permission_ok = true;
226  break;
227  }
228 
229  }
230 
231  if(!$permission_ok && !$write_permission_ok)
232  {
233  return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
234  'Server');
235  }
236 
237  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
238 
239  if (!is_object($exercise) || $exercise->getType()!= "exc")
240  {
241  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
242  'Server');
243  }
244  // store into xml result set
245  include_once './Modules/Exercise/classes/class.ilExerciseXMLWriter.php';
246 
247  // create writer
248  $xmlWriter = new ilExerciseXMLWriter();
249  $xmlWriter->setExercise($exercise);
250  $xmlWriter->setAttachMembers($write_permission_ok);
251  $xmlWriter->setAttachFileContents($attachFileContentsMode);
252  $xmlWriter->start();
253 
254  return $xmlWriter->getXML();
255  }
256 }
257 ?>