ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSoapExerciseAdministration Class Reference
+ Inheritance diagram for ilSoapExerciseAdministration:
+ Collaboration diagram for ilSoapExerciseAdministration:

Public Member Functions

 ilSoapExerciseAdministration ()
 
 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
 ilSoapAdministration ($use_nusoap=true)
 
 initErrorWriter ()
 Overwrite error handler. More...
 
 __explodeSid ($sid)
 
 __setMessage ($a_str)
 
 __getMessage ()
 
 __appendMessage ($a_str)
 
 __setMessageCode ($a_code)
 
 __getMessageCode ()
 
 initAuth ($sid)
 
 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 51 of file class.ilSoapExerciseAdministration.php.

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

52  {
53  $this->initAuth($sid);
54  $this->initIlias();
55 
56  if(!$this->__checkSession($sid))
57  {
58  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
59  }
60  global $rbacsystem, $tree, $ilLog;
61 
62  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
63  {
64  return $this->__raiseError('No valid target given.', 'Client');
65  }
66 
68  {
69  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
70  }
71 
72  // Check access
73  $allowed_types = array('cat','grp','crs','fold','root');
74  if(!in_array($target_obj->getType(), $allowed_types))
75  {
76  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
77  }
78 
79  if(!$rbacsystem->checkAccess('create',$target_id,"exc"))
80  {
81  return $this->__raiseError('No permission to create exercises in target '.$target_id.'!', 'Client');
82  }
83 
84  // create object, put it into the tree and use the parser to update the settings
85  include_once './Modules/Exercise/classes/class.ilObjExercise.php';
86  include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
87  include_once './Modules/Exercise/classes/class.ilExerciseException.php';
88 
89 
90  $exercise = new ilObjExercise();
91  $exercise->create();
92  $exercise->createReference();
93  $exercise->putInTree($target_id);
94  $exercise->setPermissions($target_id);
95  $exercise->saveData();
96 
97  // we need this as workaround because file and member objects need to be initialised
98  $exercise->read();
99 
100  $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml);
101  try
102  {
103  if ($exerciseXMLParser->start()) {
104  $exerciseXMLParser->getAssignment()->update();
105  return $exercise->update() ? $exercise->getRefId() : -1;
106  }
107  throw new ilExerciseException ("Could not parse XML");
108  } catch(ilExerciseException $exception) {
109  return $this->__raiseError($exception->getMessage(),
110  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
111  }
112  }
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
$target_id
Definition: goto.php:88
Class ilObjExercise.
__raiseError($a_message, $a_code)
_isInTrash($a_ref_id)
checks wether object is in trash
Exercise XML Parser which completes/updates a given exercise by an xml string.
Class to report exception.
+ 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 200 of file class.ilSoapExerciseAdministration.php.

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

200  {
201 
202  $this->initAuth($sid);
203  $this->initIlias();
204 
205  if(!$this->__checkSession($sid))
206  {
207  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
208  }
209  if(!strlen($ref_id))
210  {
211  return $this->__raiseError('No ref id given. Aborting!',
212  'Client');
213  }
214  global $rbacsystem, $tree, $ilLog;
215 
216  // get obj_id
217  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
218  {
219  return $this->__raiseError('No exercise found for id: '.$ref_id,
220  'Client');
221  }
222 
224  {
225  return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'Client');
226  }
227 
228 
229 
230  // Check access
231  $permission_ok = false;
232  $write_permission_ok = false;
233  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
234  {
235  if($rbacsystem->checkAccess('write',$ref_id)) // #14299
236  {
237  $write_permission_ok = true;
238  break;
239  }
240  if($rbacsystem->checkAccess('read',$ref_id))
241  {
242  $permission_ok = true;
243  break;
244  }
245 
246  }
247 
248  if(!$permission_ok && !$write_permission_ok)
249  {
250  return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
251  'Server');
252  }
253 
254  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
255 
256  if (!is_object($exercise) || $exercise->getType()!= "exc")
257  {
258  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
259  'Server');
260  }
261  // store into xml result set
262  include_once './Modules/Exercise/classes/class.ilExerciseXMLWriter.php';
263 
264  // create writer
265  $xmlWriter = new ilExerciseXMLWriter();
266  $xmlWriter->setExercise($exercise);
267  $xmlWriter->setAttachMembers($write_permission_ok);
268  $xmlWriter->setAttachFileContents($attachFileContentsMode);
269  $xmlWriter->start();
270 
271  return $xmlWriter->getXML();
272  }
static _getAllReferences($a_id)
get all reference ids of object
static _lookupObjectId($a_ref_id)
lookup object id
__raiseError($a_message, $a_code)
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
_isInTrash($a_ref_id)
checks wether object is in trash
$ref_id
Definition: sahs_server.php:39
+ Here is the call graph for this function:

◆ ilSoapExerciseAdministration()

ilSoapExerciseAdministration::ilSoapExerciseAdministration ( )

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

38  {
39  parent::ilSoapAdministration();
40  }

◆ 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 124 of file class.ilSoapExerciseAdministration.php.

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

125  {
126  $this->initAuth($sid);
127  $this->initIlias();
128 
129  if(!$this->__checkSession($sid))
130  {
131  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
132  }
133  global $rbacsystem, $tree, $ilLog;
134 
136  {
137  return $this->__raiseError('Cannot perform update since exercise has been deleted.', 'CLIENT_OBJECT_DELETED');
138  }
139  // get obj_id
140  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
141  {
142  return $this->__raiseError('No exercise found for id: '.$ref_id,
143  'CLIENT_OBJECT_NOT_FOUND');
144  }
145 
146  // Check access
147  $permission_ok = false;
148  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
149  {
150  if($rbacsystem->checkAccess('edit',$ref_id))
151  {
152  $permission_ok = true;
153  break;
154  }
155  }
156 
157  if(!$permission_ok)
158  {
159  return $this->__raiseError('No permission to edit the exercise with id: '.$ref_id,
160  'Server');
161  }
162 
163 
164  $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
165 
166  if (!is_object($exercise) || $exercise->getType()!= "exc")
167  {
168  return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
169  'CLIENT_OBJECT_NOI_FOUND');
170  }
171 
172  include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
173  include_once './Modules/Exercise/classes/class.ilExerciseException.php';
174  $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml, $obj_id);
175 
176  try
177  {
178  if ($exerciseXMLParser->start()) {
179  $exerciseXMLParser->getAssignment()->update();
180  return $exercise->update();
181  }
182  throw new ilExerciseException ("Could not parse XML");
183  } catch(ilExerciseException $exception) {
184  return $this->__raiseError($exception->getMessage(),
185  $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
186  }
187  return false;
188  }
static _getAllReferences($a_id)
get all reference ids of object
static _lookupObjectId($a_ref_id)
lookup object id
__raiseError($a_message, $a_code)
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
_isInTrash($a_ref_id)
checks wether object is in trash
$ref_id
Definition: sahs_server.php:39
Exercise XML Parser which completes/updates a given exercise by an xml string.
Class to report exception.
+ Here is the call graph for this function:

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