ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSoapExerciseAdministration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
25{
29 public function addExercise(string $sid, int $target_id, string $exercise_xml)
30 {
31 $this->initAuth($sid);
32 $this->initIlias();
33
34 if (!$this->checkSession($sid)) {
35 return $this->raiseError($this->getMessage(), $this->getMessageCode());
36 }
37 global $DIC;
38
39 $rbacsystem = $DIC['rbacsystem'];
40 $tree = $DIC['tree'];
41 $ilLog = $DIC['ilLog'];
42
43 if (!$target_obj = ilObjectFactory::getInstanceByRefId($target_id, false)) {
44 return $this->raiseError('No valid target given.', 'Client');
45 }
46
47 if (ilObject::_isInTrash($target_id)) {
48 return $this->raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
49 }
50
51 $allowed_types = array('cat', 'grp', 'crs', 'fold', 'root');
52 if (!in_array($target_obj->getType(), $allowed_types)) {
53 return $this->raiseError(
54 'No valid target type. Target must be reference id of "course, group, category or folder"',
55 'Client'
56 );
57 }
58
59 if (!$rbacsystem->checkAccess('create', $target_id, "exc")) {
60 return $this->raiseError('No permission to create exercises in target ' . $target_id . '!', 'Client');
61 }
62
63 // create object, put it into the tree and use the parser to update the settings
64
66 $exercise->create();
67 $exercise->createReference();
68 $exercise->putInTree($target_id);
69 $exercise->setPermissions($target_id);
70 $exercise->saveData();
71
72 // we need this as workaround because file and member objects need to be initialised
73 $exercise->read();
74
75 $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml);
76 try {
77 if ($exerciseXMLParser->start()) {
78 $exerciseXMLParser->getAssignment()->update();
79 return $exercise->update() ? $exercise->getRefId() : -1;
80 }
81 throw new ilExerciseException("Could not parse XML");
82 } catch (ilExerciseException $exception) {
83 return $this->raiseError(
84 $exception->getMessage(),
85 $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server"
86 );
87 }
88 }
89
93 public function updateExercise(string $sid, int $requested_ref_id, string $exercise_xml)
94 {
95 $this->initAuth($sid);
96 $this->initIlias();
97
98 if (!$this->checkSession($sid)) {
99 return $this->raiseError($this->getMessage(), $this->getMessageCode());
100 }
101 global $DIC;
102
103 $rbacsystem = $DIC['rbacsystem'];
104 $tree = $DIC['tree'];
105 $ilLog = $DIC['ilLog'];
106
108 return $this->raiseError(
109 'Cannot perform update since exercise has been deleted.',
110 'CLIENT_OBJECT_DELETED'
111 );
112 }
113
115 return $this->raiseError(
116 'No exercise found for id: ' . $requested_ref_id,
117 'CLIENT_OBJECT_NOT_FOUND'
118 );
119 }
120
121 $permission_ok = false;
122 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
123 if ($rbacsystem->checkAccess('edit', $ref_id)) {
124 $permission_ok = true;
125 break;
126 }
127 }
128
129 if (!$permission_ok) {
130 return $this->raiseError(
131 'No permission to edit the exercise with id: ' . $requested_ref_id,
132 'Server'
133 );
134 }
135
138
139 if (!is_object($exercise) || $exercise->getType() !== "exc") {
140 return $this->raiseError(
141 'Wrong obj id or type for exercise with id ' . $requested_ref_id,
142 'CLIENT_OBJECT_NOI_FOUND'
143 );
144 }
145
146 $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml, $obj_id);
147
148 try {
149 if ($exerciseXMLParser->start()) {
150 $exerciseXMLParser->getAssignment()->update();
151 return $exercise->update();
152 }
153 throw new ilExerciseException("Could not parse XML");
154 } catch (ilExerciseException $exception) {
155 return $this->raiseError(
156 $exception->getMessage(),
157 $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server"
158 );
159 }
160 }
161
165 public function getExerciseXML(string $sid, int $requested_ref_id, int $attachFileContentsMode)
166 {
167 $this->initAuth($sid);
168 $this->initIlias();
169
170 if (!$this->checkSession($sid)) {
171 return $this->raiseError($this->getMessage(), $this->getMessageCode());
172 }
173 if (!$requested_ref_id) {
174 return $this->raiseError(
175 'No ref id given. Aborting!',
176 'Client'
177 );
178 }
179 global $DIC;
180
181 $rbacsystem = $DIC['rbacsystem'];
182 $tree = $DIC['tree'];
183 $ilLog = $DIC['ilLog'];
184
185 // get obj_id
187 return $this->raiseError(
188 'No exercise found for id: ' . $requested_ref_id,
189 'Client'
190 );
191 }
192
194 return $this->raiseError("Parent with ID $requested_ref_id has been deleted.", 'Client');
195 }
196
197 $permission_ok = false;
198 $write_permission_ok = false;
199 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
200 if ($rbacsystem->checkAccess('write', $ref_id)) { // #14299
201 $write_permission_ok = true;
202 break;
203 }
204 if ($rbacsystem->checkAccess('read', $ref_id)) {
205 $permission_ok = true;
206 break;
207 }
208 }
209
210 if (!$permission_ok && !$write_permission_ok) {
211 return $this->raiseError(
212 'No permission to edit the object with id: ' . $requested_ref_id,
213 'Server'
214 );
215 }
216
219
220 if (!is_object($exercise) || $exercise->getType() !== "exc") {
221 return $this->raiseError(
222 'Wrong obj id or type for exercise with id ' . $requested_ref_id,
223 'Server'
224 );
225 }
226
227 $xmlWriter = new ilExerciseXMLWriter();
228 $xmlWriter->setExercise($exercise);
229 $xmlWriter->setAttachMembers($write_permission_ok);
230 $xmlWriter->setAttachFileContents($attachFileContentsMode);
231 $xmlWriter->start();
232
233 return $xmlWriter->getXML();
234 }
235}
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)
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
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26