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