ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
46  function addExercise ($sid, $target_id, $exercise_xml)
47  {
48  $this->initAuth($sid);
49  $this->initIlias();
50 
51  if(!$this->__checkSession($sid))
52  {
53  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
54  }
55  global $rbacsystem, $tree, $ilLog;
56 
57  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
58  {
59  return $this->__raiseError('No valid target given.', 'Client');
60  }
61 
63  {
64  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_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  {
71  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
72  }
73 
74  if(!$rbacsystem->checkAccess('create',$target_id,"exc"))
75  {
76  return $this->__raiseError('No permission to create exercises in target '.$target_id.'!', 'Client');
77  }
78 
79  // create object, put it into the tree and use the parser to update the settings
80  include_once './Modules/Exercise/classes/class.ilObjExercise.php';
81  include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
82  include_once './Modules/Exercise/exceptions/class.ilExerciseException.php';
83 
84 
85  $exercise = new ilObjExercise();
86  $exercise->create();
87  $exercise->createReference();
88  $exercise->putInTree($target_id);
89  $exercise->setPermissions($target_id);
90  $exercise->saveData();
91 
92  // we need this as workaround because file and member objects need to be initialised
93  $exercise->read();
94 
95  $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml);
96  try
97  {
98  if ($exerciseXMLParser->start()) {
99  $exerciseXMLParser->getAssignment()->update();
100  return $exercise->update() ? $exercise->getRefId() : -1;
101  }
102  throw new ilExerciseException ("Could not parse XML");
103  } catch(ilExerciseException $exception) {
104  return $this->__raiseError($exception->getMessage(),
105  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
106  }
107  }
108 
109 
119  function updateExercise ($sid, $ref_id, $exercise_xml)
120  {
121  $this->initAuth($sid);
122  $this->initIlias();
123 
124  if(!$this->__checkSession($sid))
125  {
126  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
127  }
128  global $rbacsystem, $tree, $ilLog;
129 
131  {
132  return $this->__raiseError('Cannot perform update since exercise has been deleted.', 'CLIENT_OBJECT_DELETED');
133  }
134  // get obj_id
135  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
136  {
137  return $this->__raiseError('No exercise found for id: '.$ref_id,
138  'CLIENT_OBJECT_NOT_FOUND');
139  }
140 
141  // Check access
142  $permission_ok = false;
143  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
144  {
145  if($rbacsystem->checkAccess('edit',$ref_id))
146  {
147  $permission_ok = true;
148  break;
149  }
150  }
151 
152  if(!$permission_ok)
153  {
154  return $this->__raiseError('No permission to edit the exercise with id: '.$ref_id,
155  'Server');
156  }
157 
158 
159  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
160 
161  if (!is_object($exercise) || $exercise->getType()!= "exc")
162  {
163  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
164  'CLIENT_OBJECT_NOI_FOUND');
165  }
166 
167  include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
168  include_once './Modules/Exercise/exceptions/class.ilExerciseException.php';
169  $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml, $obj_id);
170 
171  try
172  {
173  if ($exerciseXMLParser->start()) {
174  $exerciseXMLParser->getAssignment()->update();
175  return $exercise->update();
176  }
177  throw new ilExerciseException ("Could not parse XML");
178  } catch(ilExerciseException $exception) {
179  return $this->__raiseError($exception->getMessage(),
180  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
181  }
182  return false;
183  }
184 
195  function getExerciseXML ($sid, $ref_id, $attachFileContentsMode) {
196 
197  $this->initAuth($sid);
198  $this->initIlias();
199 
200  if(!$this->__checkSession($sid))
201  {
202  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
203  }
204  if(!strlen($ref_id))
205  {
206  return $this->__raiseError('No ref id given. Aborting!',
207  'Client');
208  }
209  global $rbacsystem, $tree, $ilLog;
210 
211  // get obj_id
212  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
213  {
214  return $this->__raiseError('No exercise found for id: '.$ref_id,
215  'Client');
216  }
217 
219  {
220  return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'Client');
221  }
222 
223 
224 
225  // Check access
226  $permission_ok = false;
227  $write_permission_ok = false;
228  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
229  {
230  if($rbacsystem->checkAccess('write',$ref_id)) // #14299
231  {
232  $write_permission_ok = true;
233  break;
234  }
235  if($rbacsystem->checkAccess('read',$ref_id))
236  {
237  $permission_ok = true;
238  break;
239  }
240 
241  }
242 
243  if(!$permission_ok && !$write_permission_ok)
244  {
245  return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
246  'Server');
247  }
248 
249  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
250 
251  if (!is_object($exercise) || $exercise->getType()!= "exc")
252  {
253  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
254  'Server');
255  }
256  // store into xml result set
257  include_once './Modules/Exercise/classes/class.ilExerciseXMLWriter.php';
258 
259  // create writer
260  $xmlWriter = new ilExerciseXMLWriter();
261  $xmlWriter->setExercise($exercise);
262  $xmlWriter->setAttachMembers($write_permission_ok);
263  $xmlWriter->setAttachFileContents($attachFileContentsMode);
264  $xmlWriter->start();
265 
266  return $xmlWriter->getXML();
267  }
268 }
269 ?>
static _isInTrash($a_ref_id)
checks wether object is in trash
$target_id
Definition: goto.php:51
static _getAllReferences($a_id)
get all reference ids of object
static _lookupObjectId($a_ref_id)
lookup object id
Class ilObjExercise.
__raiseError($a_message, $a_code)
updateExercise($sid, $ref_id, $exercise_xml)
update a exercise with id.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
addExercise($sid, $target_id, $exercise_xml)
add an exercise with id.
$ref_id
Definition: sahs_server.php:39
initAuth($sid)
Init authentication.
Exercise XML Parser which completes/updates a given exercise by an xml string.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
getExerciseXML($sid, $ref_id, $attachFileContentsMode)
get exercise xml
Class to report exception.