ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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.

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

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  }
static _isInTrash($a_ref_id)
checks wether object is in trash
$target_id
Definition: goto.php:49
Class ilObjExercise.
__raiseError($a_message, $a_code)
Create styles array
The data for the language used.
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
Exercise exceptions class.
+ 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 191 of file class.ilSoapExerciseAdministration.php.

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

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  }
static _isInTrash($a_ref_id)
checks wether object is in trash
static _getAllReferences($a_id)
get all reference ids of object
static _lookupObjectId($a_ref_id)
lookup object id
__raiseError($a_message, $a_code)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
initAuth($sid)
Init authentication.
+ 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 115 of file class.ilSoapExerciseAdministration.php.

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

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  }
static _isInTrash($a_ref_id)
checks wether object is in trash
static _getAllReferences($a_id)
get all reference ids of object
static _lookupObjectId($a_ref_id)
lookup object id
__raiseError($a_message, $a_code)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
initAuth($sid)
Init authentication.
Exercise XML Parser which completes/updates a given exercise by an xml string.
Exercise exceptions class.
+ Here is the call graph for this function:

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