ILIAS  release_8 Revision v8.24
class.ilSoapExerciseAdministration.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
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
28include_once './webservice/soap/classes/class.ilSoapAdministration.php';
29
31{
35 public function addExercise(string $sid, int $target_id, string $exercise_xml)
36 {
37 $this->initAuth($sid);
38 $this->initIlias();
39
40 if (!$this->checkSession($sid)) {
41 return $this->raiseError($this->getMessage(), $this->getMessageCode());
42 }
43 global $DIC;
44
45 $rbacsystem = $DIC['rbacsystem'];
46 $tree = $DIC['tree'];
47 $ilLog = $DIC['ilLog'];
48
49 if (!$target_obj = ilObjectFactory::getInstanceByRefId($target_id, false)) {
50 return $this->raiseError('No valid target given.', 'Client');
51 }
52
53 if (ilObject::_isInTrash($target_id)) {
54 return $this->raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
55 }
56
57 $allowed_types = array('cat', 'grp', 'crs', 'fold', 'root');
58 if (!in_array($target_obj->getType(), $allowed_types)) {
59 return $this->raiseError(
60 'No valid target type. Target must be reference id of "course, group, category or folder"',
61 'Client'
62 );
63 }
64
65 if (!$rbacsystem->checkAccess('create', $target_id, "exc")) {
66 return $this->raiseError('No permission to create exercises in target ' . $target_id . '!', 'Client');
67 }
68
69 // create object, put it into the tree and use the parser to update the settings
70 include_once './Modules/Exercise/classes/class.ilObjExercise.php';
71 include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
72 include_once './Modules/Exercise/exceptions/class.ilExerciseException.php';
73
75 $exercise->create();
76 $exercise->createReference();
77 $exercise->putInTree($target_id);
78 $exercise->setPermissions($target_id);
79 $exercise->saveData();
80
81 // we need this as workaround because file and member objects need to be initialised
82 $exercise->read();
83
84 $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml);
85 try {
86 if ($exerciseXMLParser->start()) {
87 $exerciseXMLParser->getAssignment()->update();
88 return $exercise->update() ? $exercise->getRefId() : -1;
89 }
90 throw new ilExerciseException("Could not parse XML");
91 } catch (ilExerciseException $exception) {
92 return $this->raiseError(
93 $exception->getMessage(),
94 $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server"
95 );
96 }
97 }
98
102 public function updateExercise(string $sid, int $requested_ref_id, string $exercise_xml)
103 {
104 $this->initAuth($sid);
105 $this->initIlias();
106
107 if (!$this->checkSession($sid)) {
108 return $this->raiseError($this->getMessage(), $this->getMessageCode());
109 }
110 global $DIC;
111
112 $rbacsystem = $DIC['rbacsystem'];
113 $tree = $DIC['tree'];
114 $ilLog = $DIC['ilLog'];
115
117 return $this->raiseError(
118 'Cannot perform update since exercise has been deleted.',
119 'CLIENT_OBJECT_DELETED'
120 );
121 }
122
124 return $this->raiseError(
125 'No exercise found for id: ' . $requested_ref_id,
126 'CLIENT_OBJECT_NOT_FOUND'
127 );
128 }
129
130 $permission_ok = false;
131 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
132 if ($rbacsystem->checkAccess('edit', $ref_id)) {
133 $permission_ok = true;
134 break;
135 }
136 }
137
138 if (!$permission_ok) {
139 return $this->raiseError(
140 'No permission to edit the exercise with id: ' . $requested_ref_id,
141 'Server'
142 );
143 }
144
147
148 if (!is_object($exercise) || $exercise->getType() !== "exc") {
149 return $this->raiseError(
150 'Wrong obj id or type for exercise with id ' . $requested_ref_id,
151 'CLIENT_OBJECT_NOI_FOUND'
152 );
153 }
154
155 include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
156 include_once './Modules/Exercise/exceptions/class.ilExerciseException.php';
157 $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml, $obj_id);
158
159 try {
160 if ($exerciseXMLParser->start()) {
161 $exerciseXMLParser->getAssignment()->update();
162 return $exercise->update();
163 }
164 throw new ilExerciseException("Could not parse XML");
165 } catch (ilExerciseException $exception) {
166 return $this->raiseError(
167 $exception->getMessage(),
168 $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server"
169 );
170 }
171 }
172
176 public function getExerciseXML(string $sid, int $requested_ref_id, int $attachFileContentsMode)
177 {
178 $this->initAuth($sid);
179 $this->initIlias();
180
181 if (!$this->checkSession($sid)) {
182 return $this->raiseError($this->getMessage(), $this->getMessageCode());
183 }
184 if (!$requested_ref_id) {
185 return $this->raiseError(
186 'No ref id given. Aborting!',
187 'Client'
188 );
189 }
190 global $DIC;
191
192 $rbacsystem = $DIC['rbacsystem'];
193 $tree = $DIC['tree'];
194 $ilLog = $DIC['ilLog'];
195
196 // get obj_id
198 return $this->raiseError(
199 'No exercise found for id: ' . $requested_ref_id,
200 'Client'
201 );
202 }
203
205 return $this->raiseError("Parent with ID $requested_ref_id has been deleted.", 'Client');
206 }
207
208 $permission_ok = false;
209 $write_permission_ok = false;
210 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
211 if ($rbacsystem->checkAccess('write', $ref_id)) { // #14299
212 $write_permission_ok = true;
213 break;
214 }
215 if ($rbacsystem->checkAccess('read', $ref_id)) {
216 $permission_ok = true;
217 break;
218 }
219 }
220
221 if (!$permission_ok && !$write_permission_ok) {
222 return $this->raiseError(
223 'No permission to edit the object with id: ' . $requested_ref_id,
224 'Server'
225 );
226 }
227
230
231 if (!is_object($exercise) || $exercise->getType() !== "exc") {
232 return $this->raiseError(
233 'Wrong obj id or type for exercise with id ' . $requested_ref_id,
234 'Server'
235 );
236 }
237
238 include_once './Modules/Exercise/classes/class.ilExerciseXMLWriter.php';
239
240 $xmlWriter = new ilExerciseXMLWriter();
241 $xmlWriter->setExercise($exercise);
242 $xmlWriter->setAttachMembers($write_permission_ok);
243 $xmlWriter->setAttachFileContents($attachFileContentsMode);
244 $xmlWriter->start();
245
246 return $xmlWriter->getXML();
247 }
248}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjExercise.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjectId(int $ref_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _isInTrash(int $ref_id)
soap server Base class for all SOAP registered methods.
raiseError(string $a_message, $a_code)
Soap exercise administration methods.
addExercise(string $sid, int $target_id, string $exercise_xml)
$requested_ref_id
Definition: feed.php:40
global $DIC
Definition: feed.php:28
$target_id
Definition: goto.php:52
$ref_id
Definition: ltiauth.php:67