ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilExerciseXMLParser Class Reference

Exercise XML Parser which completes/updates a given exercise by an xml string. More...

+ Inheritance diagram for ilExerciseXMLParser:
+ Collaboration diagram for ilExerciseXMLParser:

Public Member Functions

 ilExerciseXMLParser (& $exercise, $a_xml_data, $obj_id=-1)
 Constructor. More...
 
 setHandlers ($a_xml_parser)
 set event handlers More...
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
 start ()
 starts parsing an changes object by side effect. More...
 
 getAssignment ()
 
- Public Member Functions inherited from ilSaxParser
 ilSaxParser ($a_xml_file='', $throwException=false)
 Constructor setup ILIAS global object @access public. More...
 
 setXMLContent ($a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 create parser More...
 
 setOptions ($a_xml_parser)
 set parser options More...
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class @access private More...
 
 openXMLFile ()
 open xml file More...
 
 parse ($a_xml_parser, $a_fp=null)
 parse xml file More...
 
 freeParser ($a_xml_parser)
 free xml parser handle More...
 
 setThrowException ($throwException)
 set error handling More...
 
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Data Fields

 $exercise
 
 $obj_id
 
 $result
 
 $mode
 
 $assignment
 
 $storage
 
- Data Fields inherited from ilSaxParser
 $input_type = null
 
 $xml_content = ''
 
 $ilias
 
 $lng
 
 $xml_file
 
 $throwException = false
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

Static Public Attributes

static $CONTENT_NOT_COMPRESSED = 0
 
static $CONTENT_GZ_COMPRESSED = 1
 
static $CONTENT_ZLIB_COMPRESSED = 2
 

Private Member Functions

 updateMember ($user_id, $action)
 update member object according to given action More...
 
 updateFile ($filename, $b64encodedContent, $action)
 update file according to filename More...
 
 updateMarking ($usr_id)
 update marking of member More...
 

Additional Inherited Members

- Protected Member Functions inherited from ilSaxParser
 handleError ($message, $code)
 use given error handler to handle error message or internal ilias error message handle More...
 

Detailed Description

Exercise XML Parser which completes/updates a given exercise by an xml string.

Author
Roland Küstermann rolan.nosp@m.d@ku.nosp@m.ester.nosp@m.mann.nosp@m..com
Version
Id
class.ilObjectXMLParser.php 12811 2006-12-08 18:37:44Z akill

Definition at line 19 of file class.ilExerciseXMLParser.php.

Member Function Documentation

◆ getAssignment()

ilExerciseXMLParser::getAssignment ( )

Definition at line 352 of file class.ilExerciseXMLParser.php.

References $assignment.

◆ handlerBeginTag()

ilExerciseXMLParser::handlerBeginTag (   $a_xml_parser,
  $a_name,
  $a_attribs 
)

handler for begin of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name
array$a_attribselement attributes array
Exceptions
ilExerciseExceptionwhen obj id != - 1 and if it it does not match the id in the xml

Definition at line 124 of file class.ilExerciseXMLParser.php.

125 {
126 global $ilErr;
127
128 switch($a_name)
129 {
130 case 'Exercise':
131 if (isset($a_attribs["obj_id"]))
132 {
133 $read_obj_id = ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID);
134 if ($this->obj_id != -1 && (int) $read_obj_id != -1 && (int) $this->obj_id != (int) $read_obj_id)
135 {
136 throw new ilExerciseException ("Object IDs (xml $read_obj_id and argument ".$this->obj_id.") do not match!", ilExerciseException::$ID_MISMATCH);
137 }
138 }
139 break;
140 case 'Member':
141 $this->usr_action = $a_attribs["action"];
142 $this->usr_id = ilUtil::__extractId($a_attribs["usr_id"], IL_INST_ID);
143 break;
144
145 case 'File':
146 $this->file_action = $a_attribs["action"];
147 break;
148 case 'Content':
150 if ($a_attribs["mode"] == "GZIP")
151 {
152 if (!function_exists("gzdecode"))
153 throw new ilExerciseException ("Deflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
154
156 } elseif ($a_attribs["mode"] == "ZLIB")
157 {
158 if (!function_exists("gzuncompress"))
159 throw new ilExerciseException ("Deflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
160
162 }
163 break;
164 case 'Marking':
165 $this->status = $a_attribs["status"];
166 if ($this->status == ilExerciseXMLWriter::$STATUS_NOT_GRADED)
167 $this->status = "notgraded";
168 elseif ($this->status == ilExerciseXMLWriter::$STATUS_PASSED)
169 $this->status = "passed";
170 else
171 $this->status = "failed";
172 break;
173
174 }
175 }
Class to report exception.
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.

References $CONTENT_GZ_COMPRESSED, $CONTENT_NOT_COMPRESSED, $CONTENT_ZLIB_COMPRESSED, ilExerciseException\$ID_DEFLATE_METHOD_MISMATCH, ilExerciseException\$ID_MISMATCH, $ilErr, ilExerciseXMLWriter\$STATUS_NOT_GRADED, ilExerciseXMLWriter\$STATUS_PASSED, and ilUtil\__extractId().

+ Here is the call graph for this function:

◆ handlerCharacterData()

ilExerciseXMLParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

Definition at line 244 of file class.ilExerciseXMLParser.php.

245 {
246 if($a_data != "\n")
247 {
248 $this->cdata .= $a_data;
249 }
250 }

◆ handlerEndTag()

ilExerciseXMLParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

handler for end of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name

Definition at line 185 of file class.ilExerciseXMLParser.php.

186 {
187 switch($a_name)
188 {
189 case 'Exercise':
190 $this->result = true;
191 break;
192 case 'Title':
193 $this->exercise->setTitle(trim($this->cdata));
194 $this->assignment->setTitle(trim($this->cdata));
195 break;
196 case 'Description':
197 $this->exercise->setDescription(trim($this->cdata));
198 break;
199 case 'Instruction':
200 $this->assignment->setInstruction(trim($this->cdata));
201 break;
202 case 'DueDate':
203 $this->assignment->setDeadLine(trim($this->cdata));
204 break;
205 case 'Member':
206 $this->updateMember($this->usr_id, $this->usr_action);
207 // update marking after update member.
208 $this->updateMarking($this->usr_id);
209 break;
210 case 'Filename':
211 $this->file_name = trim($this->cdata);
212 break;
213 case 'Content':
214 $this->file_content = trim($this->cdata);
215 break;
216 case 'File':
217 $this->updateFile($this->file_name, $this->file_content, $this->file_action);
218 break;
219 case 'Comment':
220 $this->comment = trim($this->cdata);
221 break;
222 case 'Notice':
223 $this->notice = trim($this->cdata);
224 break;
225 case 'Mark':
226 $this->mark = trim($this->cdata);
227 break;
228 case 'Marking':
229 // see Member end tag
230 break;
231 }
232
233 $this->cdata = '';
234
235 return;
236 }
updateMember($user_id, $action)
update member object according to given action
updateMarking($usr_id)
update marking of member
updateFile($filename, $b64encodedContent, $action)
update file according to filename

References updateFile(), updateMarking(), and updateMember().

+ Here is the call graph for this function:

◆ ilExerciseXMLParser()

ilExerciseXMLParser::ilExerciseXMLParser ( $exercise,
  $a_xml_data,
  $obj_id = -1 
)

Constructor.

Parameters
ilExercise$exerciseexisting exercise object
string$a_xml_filexml data
int$obj_idobj id of exercise which is to be updated @access public

Definition at line 76 of file class.ilExerciseXMLParser.php.

77 {
78// @todo: needs to be revised for multiple assignments per exercise
79
80 parent::ilSaxParser();
81 $this->exercise = $exercise;
82 // get all assignments and choose first one if exists, otherwise create
84 if (count ($assignments) > 0) {
85 $this->assignment = new ilExAssignment($assignments [0]["id"]);
86 } else {
87 $this->assignment = new ilExAssignment();
88 $this->assignment->setExerciseId($exercise->getId());
89 $this->assignment->save();
90 }
91
92 include_once ("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
93 $this->storage = new ilFSStorageExercise ( $this->exercise->getId(), $this->assignment->getId());
94 $this->storage->create();
95 $this->storage->init();
96
97 $this->setXMLContent($a_xml_data);
98 $this->obj_id = $obj_id;
99 $this->result = false;
100 }
Exercise assignment.
static getAssignmentDataOfExercise($a_exc_id)
Get assignments data of an exercise in an array.
setXMLContent($a_xml_content)

References $exercise, $obj_id, ilExAssignment\getAssignmentDataOfExercise(), and ilSaxParser\setXMLContent().

+ Here is the call graph for this function:

◆ setHandlers()

ilExerciseXMLParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser @access private

Reimplemented from ilSaxParser.

Definition at line 109 of file class.ilExerciseXMLParser.php.

110 {
111 xml_set_object($a_xml_parser,$this);
112 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
113 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
114 }

◆ start()

ilExerciseXMLParser::start ( )

starts parsing an changes object by side effect.

Exceptions
ilExerciseExceptionwhen obj id != - 1 and if it it does not match the id in the xml
Returns
boolean true, if no errors happend.

Definition at line 316 of file class.ilExerciseXMLParser.php.

316 {
317 $this->startParsing();
318 return $this->result > 0;
319 }
startParsing()
stores xml data in array

References ilSaxParser\startParsing().

+ Here is the call graph for this function:

◆ updateFile()

ilExerciseXMLParser::updateFile (   $filename,
  $b64encodedContent,
  $action 
)
private

update file according to filename

Parameters
string$filename
string$contentbase 64 encoded string
string$actioncan be Attach or Detach

Definition at line 283 of file class.ilExerciseXMLParser.php.

284 {
285 if (strlen($filename) == 0) {
286 return;
287 }
288 $filename= $this->storage->getAbsolutePath()."/".$filename;
289
290 if ($action == "Attach")
291 {
292 $content = base64_decode((string) $b64encodedContent);
294 $content = gzdecode($content);
295 }elseif ($this->mode ==ilExerciseXMLParser::$CONTENT_ZLIB_COMPRESSED) {
296 $content = gzuncompress($content);
297 }
298
299 //echo $filename;
300 $this->storage->writeToFile($content, $filename);
301
302 }
303 if ($action == "Detach")
304 {
305 $this->storage->deleteFile($filename);
306 }
307 }
$filename
Definition: buildRTE.php:89

References $CONTENT_GZ_COMPRESSED, $CONTENT_ZLIB_COMPRESSED, and $filename.

Referenced by handlerEndTag().

+ Here is the caller graph for this function:

◆ updateMarking()

ilExerciseXMLParser::updateMarking (   $usr_id)
private

update marking of member

Parameters
int$usr_id

Definition at line 326 of file class.ilExerciseXMLParser.php.

326 {
327 if (isset($this->mark))
328 {
329 ilExAssignment::updateMarkOfUser($this->assignment->getId(), $usr_id, ilUtil::stripSlashes($this->mark));
330 }
331 if (isset($this->comment))
332 {
333
334 ilExAssignment::updateCommentForUser($this->assignment->getId(), $usr_id, ilUtil::stripSlashes($this->comment));
335 }
336
337 //$memberObject = $this->exercise->members_obj;
338 if (isset ( $this->status )){
339
340 ilExAssignment::updateStatusOfUser ( $this->assignment->getId (), $usr_id, ilUtil::stripSlashes ( $this->status ) );
341 }
342 if (isset($this->notice)){
343 ilExAssignment::updateNoticeForUser($this->assignment->getId(), $usr_id, ilUtil::stripSlashes($this->notice));
344 }
345 // reset variables
346 $this->mark = null;
347 $this->status = null;
348 $this->notice = null;
349 $this->comment = null;
350 }
updateNoticeForUser($a_ass_id, $a_user_id, $a_notice)
was: setNoticeForMember($a_member_id,$a_notice)
updateStatusOfUser($a_ass_id, $a_user_id, $a_status)
was: setStatusForMember($a_member_id,$a_status)
updateMarkOfUser($a_ass_id, $a_user_id, $a_value)
Update mark.
updateCommentForUser($a_ass_id, $a_user_id, $a_value)
Update comment.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled

References ilUtil\stripSlashes(), ilExAssignment\updateCommentForUser(), ilExAssignment\updateMarkOfUser(), ilExAssignment\updateNoticeForUser(), and ilExAssignment\updateStatusOfUser().

Referenced by handlerEndTag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateMember()

ilExerciseXMLParser::updateMember (   $user_id,
  $action 
)
private

update member object according to given action

Parameters
int$user_id
string$actioncan be Attach or Detach

Definition at line 259 of file class.ilExerciseXMLParser.php.

259 {
260 if (!is_int($user_id) || $user_id <= 0) {
261 return;
262 }
263 $memberObject = new ilExerciseMembers($this->exercise);
264
265 if ($action == "Attach" && !$memberObject->isAssigned($user_id))
266 {
267 $memberObject->assignMember ($user_id);
268 }
269
270 if ($action == "Detach" && $memberObject->isAssigned($user_id))
271 {
272 $memberObject->deassignMember ($user_id);
273 }
274 }
Class ilExerciseMembers.

Referenced by handlerEndTag().

+ Here is the caller graph for this function:

Field Documentation

◆ $assignment

ilExerciseXMLParser::$assignment

Definition at line 60 of file class.ilExerciseXMLParser.php.

Referenced by getAssignment().

◆ $CONTENT_GZ_COMPRESSED

ilExerciseXMLParser::$CONTENT_GZ_COMPRESSED = 1
static

Definition at line 23 of file class.ilExerciseXMLParser.php.

Referenced by handlerBeginTag(), and updateFile().

◆ $CONTENT_NOT_COMPRESSED

ilExerciseXMLParser::$CONTENT_NOT_COMPRESSED = 0
static

Definition at line 22 of file class.ilExerciseXMLParser.php.

Referenced by handlerBeginTag().

◆ $CONTENT_ZLIB_COMPRESSED

ilExerciseXMLParser::$CONTENT_ZLIB_COMPRESSED = 2
static

Definition at line 24 of file class.ilExerciseXMLParser.php.

Referenced by handlerBeginTag(), and updateFile().

◆ $exercise

ilExerciseXMLParser::$exercise

Definition at line 31 of file class.ilExerciseXMLParser.php.

Referenced by ilExerciseXMLParser().

◆ $mode

ilExerciseXMLParser::$mode

Definition at line 54 of file class.ilExerciseXMLParser.php.

◆ $obj_id

ilExerciseXMLParser::$obj_id

Definition at line 39 of file class.ilExerciseXMLParser.php.

Referenced by ilExerciseXMLParser().

◆ $result

ilExerciseXMLParser::$result

Definition at line 47 of file class.ilExerciseXMLParser.php.

◆ $storage

ilExerciseXMLParser::$storage

Definition at line 66 of file class.ilExerciseXMLParser.php.


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