ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilSoapExerciseAdministration Class Reference
+ Inheritance diagram for ilSoapExerciseAdministration:
+ Collaboration diagram for ilSoapExerciseAdministration:

Public Member Functions

 addExercise ($sid, $target_id, $exercise_xml)
 add an exercise with id. More...
 
 updateExercise ($sid, $ref_id, $exercise_xml)
 update a exercise with id. More...
 
 getExerciseXML ($sid, $ref_id, $attachFileContentsMode)
 get exercise xml More...
 
- Public Member Functions inherited from ilSoapAdministration
 __construct ($use_nusoap=true)
 Constructor. More...
 
 initErrorWriter ()
 Overwrite error handler. More...
 
 __explodeSid ($sid)
 
 __setMessage ($a_str)
 
 __getMessage ()
 
 __appendMessage ($a_str)
 
 __setMessageCode ($a_code)
 
 __getMessageCode ()
 
 initAuth ($sid)
 Init authentication. More...
 
 initIlias ()
 
 __initAuthenticationObject ($a_auth_mode=AUTH_LOCAL)
 
 __raiseError ($a_message, $a_code)
 
 getNIC ($sid)
 get client information from current as xml result set More...
 
 isFault ($object)
 
 checkObjectAccess ($ref_id, $expected_type, $permission, $returnObject=false)
 check access for ref id: expected type, permission, return object instance if returnobject is true More...
 
 getInstallationInfoXML ()
 
 getClientInfoXML ($clientid)
 

Additional Inherited Members

- Static Public Member Functions inherited from ilSoapAdministration
static return_bytes ($val)
 calculate bytes from K,M,G modifiers e.g: 8M = 8 * 1024 * 1024 bytes More...
 
- Data Fields inherited from ilSoapAdministration
 $sauth = null
 
 $error_method = null
 
- Protected Attributes inherited from ilSoapAdministration
 $soap_check = true
 

Detailed Description

Definition at line 35 of file class.ilSoapExerciseAdministration.php.

Member Function Documentation

◆ addExercise()

ilSoapExerciseAdministration::addExercise (   $sid,
  $target_id,
  $exercise_xml 
)

add an exercise with id.

Parameters
string$session_idcurrent session
int$target_idrefid of parent in repository
string$exercise_xmlqti xml description of test
Returns
int reference id in the tree, 0 if not successful

Definition at line 46 of file class.ilSoapExerciseAdministration.php.

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
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 }
Exercise exceptions class.
Exercise XML Parser which completes/updates a given exercise by an xml string.
Class ilObjExercise.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _isInTrash($a_ref_id)
checks wether object is in trash
initAuth($sid)
Init authentication.
__raiseError($a_message, $a_code)
$target_id
Definition: goto.php:49
$DIC
Definition: xapitoken.php:46

References $DIC, $exercise, ilExerciseException\$ID_MISMATCH, $ilLog, $target_id, ilSoapAdministration\__getMessage(), ilSoapAdministration\__getMessageCode(), ilSoapAdministration\__raiseError(), ilObject\_isInTrash(), ilObjectFactory\getInstanceByRefId(), ilSoapAdministration\initAuth(), and ilSoapAdministration\initIlias().

+ Here is the call graph for this function:

◆ getExerciseXML()

ilSoapExerciseAdministration::getExerciseXML (   $sid,
  $ref_id,
  $attachFileContentsMode 
)

get exercise xml

Parameters
string$sid
int$ref_id
int$attachFileContentsModesee constants
Returns
xml following ilias_exercise_x.dtd

Definition at line 199 of file class.ilSoapExerciseAdministration.php.

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 }
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjectId($a_ref_id)
lookup object id
static _getAllReferences($a_id)
get all reference ids of object

References $DIC, $exercise, $ilLog, ilSoapAdministration\__getMessage(), ilSoapAdministration\__getMessageCode(), ilSoapAdministration\__raiseError(), ilObject\_getAllReferences(), ilObject\_isInTrash(), ilObject\_lookupObjectId(), ilObjectFactory\getInstanceByObjId(), ilSoapAdministration\initAuth(), and ilSoapAdministration\initIlias().

+ Here is the call graph for this function:

◆ updateExercise()

ilSoapExerciseAdministration::updateExercise (   $sid,
  $ref_id,
  $exercise_xml 
)

update a exercise with id.

Parameters
string$session_idcurrent session
int$ref_idrefid id of exercise in repository
string$exercise_xmlqti xml description of test
Returns
boolean true, if update successful, false otherwise

Definition at line 119 of file class.ilSoapExerciseAdministration.php.

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 }

References $DIC, $exercise, ilExerciseException\$ID_MISMATCH, $ilLog, ilSoapAdministration\__getMessage(), ilSoapAdministration\__getMessageCode(), ilSoapAdministration\__raiseError(), ilObject\_getAllReferences(), ilObject\_isInTrash(), ilObject\_lookupObjectId(), ilObjectFactory\getInstanceByObjId(), ilSoapAdministration\initAuth(), and ilSoapAdministration\initIlias().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: