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