ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
 setHandlers ($a_xml_parser)
 set event handlers
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data
 start ()
 starts parsing an changes object by side effect.
- Public Member Functions inherited from ilSaxParser
 ilSaxParser ($a_xml_file= '', $throwException=false)
 Constructor setup ILIAS global object public.
 setXMLContent ($a_xml_content)
 getXMLContent ()
 getInputType ()
 startParsing ()
 stores xml data in array
 createParser ()
 create parser
 setOptions ($a_xml_parser)
 set parser options
 openXMLFile ()
 open xml file
 parse ($a_xml_parser, $a_fp=null)
 parse xml file
 freeParser ($a_xml_parser)
 free xml parser handle
 setThrowException ($throwException)
 set error handling

Data Fields

 $exercise
 $obj_id
 $result
 $mode
- Data Fields inherited from ilSaxParser
 $input_type = null
 $xml_content = ''
 $ilias
 $lng
 $xml_file
 $throwException = false

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
 updateFile ($filename, $b64encodedContent, $action)
 update file according to filename
 updateMarking ($usr_id)
 update marking of member

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

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 41 of file class.ilExerciseXMLParser.php.

Member Function Documentation

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 117 of file class.ilExerciseXMLParser.php.

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().

{
global $ilErr;
switch($a_name)
{
case 'Exercise':
if (isset($a_attribs["obj_id"]))
{
$read_obj_id = ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID);
if ($this->obj_id != -1 && (int) $read_obj_id != -1 && (int) $this->obj_id != (int) $read_obj_id)
{
throw new ilExerciseException ("Object IDs (xml $read_obj_id and argument ".$this->obj_id.") do not match!", ilExerciseException::$ID_MISMATCH);
}
}
break;
case 'Member':
$this->usr_action = $a_attribs["action"];
$this->usr_id = ilUtil::__extractId($a_attribs["usr_id"], IL_INST_ID);
break;
case 'File':
$this->file_action = $a_attribs["action"];
break;
case 'Content':
if ($a_attribs["mode"] == "GZIP")
{
if (!function_exists("gzdecode"))
throw new ilExerciseException ("Deflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
} elseif ($a_attribs["mode"] == "ZLIB")
{
if (!function_exists("gzuncompress"))
throw new ilExerciseException ("Deflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
}
break;
case 'Marking':
$this->status = $a_attribs["status"];
$this->status = "notgraded";
elseif ($this->status == ilExerciseXMLWriter::$STATUS_PASSED)
$this->status = "passed";
else
$this->status = "failed";
break;
}
}

+ Here is the call graph for this function:

ilExerciseXMLParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

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

{
if($a_data != "\n")
{
$this->cdata .= $a_data;
}
}
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 178 of file class.ilExerciseXMLParser.php.

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

{
switch($a_name)
{
case 'Exercise':
$this->result = true;
break;
case 'Title':
$this->exercise->setTitle(trim($this->cdata));
break;
case 'Description':
$this->exercise->setDescription(trim($this->cdata));
break;
case 'Instruction':
$this->exercise->setInstruction(trim($this->cdata));
break;
case 'DueDate':
$this->exercise->setTimestamp(trim($this->cdata));
break;
case 'Member':
$this->updateMember($this->usr_id, $this->usr_action);
// update marking after update member.
$this->updateMarking($this->usr_id);
break;
case 'Filename':
$this->file_name = trim($this->cdata);
break;
case 'Content':
$this->file_content = trim($this->cdata);
break;
case 'File':
$this->updateFile($this->file_name, $this->file_content, $this->file_action);
break;
case 'Comment':
$this->comment = trim($this->cdata);
break;
case 'Notice':
$this->notice = trim($this->cdata);
break;
case 'Mark':
$this->mark = trim($this->cdata);
break;
case 'Marking':
// see Member end tag
break;
}
$this->cdata = '';
return;
}

+ Here is the call graph for this function:

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 public

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

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

{
$this->exercise = $exercise;
$this->setXMLContent($a_xml_data);
$this->obj_id = $obj_id;
$this->result = false;
}

+ Here is the call graph for this function:

ilExerciseXMLParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser private

Reimplemented from ilSaxParser.

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

{
xml_set_object($a_xml_parser,$this);
xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
}
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 305 of file class.ilExerciseXMLParser.php.

References ilSaxParser\startParsing().

{
$this->startParsing();
return $this->result > 0;
}

+ Here is the call graph for this function:

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 275 of file class.ilExerciseXMLParser.php.

References $CONTENT_GZ_COMPRESSED, $CONTENT_ZLIB_COMPRESSED, and $filename.

Referenced by handlerEndTag().

{
if (strlen($filename) == 0) {
return;
}
$fileObject = $this->exercise->file_obj;
if ($action == "Attach")
{
$content = base64_decode((string) $b64encodedContent);
$content = gzdecode($content);
$content = gzuncompress($content);
}
$fileObject->storeContentAsFile ($filename, $content);
}
if ($action == "Detach")
{
$fileObject->unlinkFile ($filename);
}
}

+ Here is the caller graph for this function:

ilExerciseXMLParser::updateMarking (   $usr_id)
private

update marking of member

Parameters
int$usr_id

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

References ilLPMarks\setComment(), ilLPMarks\setMark(), and ilUtil\stripSlashes().

Referenced by handlerEndTag().

{
include_once 'Services/Tracking/classes/class.ilLPMarks.php';
$marks_obj = new ilLPMarks($this->exercise->getId(), $usr_id);
$update = false;
if (isset($this->mark))
{
$update = true;
$marks_obj->setMark(ilUtil::stripSlashes($this->mark));
}
if (isset($this->mark))
{
$update = true;
$marks_obj->setComment(ilUtil::stripSlashes($this->comment));
}
if ($update)
{
$marks_obj->update();
}
$memberObject = $this->exercise->members_obj;
if (isset($this->status))
$memberObject ->setStatusForMember($usr_id, $this->status);
if (isset($this->notice))
$memberObject->setNoticeForMember($usr_id, ilUtil::stripSlashes($this->notice));
// reset variables
$this->mark = null;
$this->status = null;
$this->notice = null;
$this->comment = null;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 251 of file class.ilExerciseXMLParser.php.

Referenced by handlerEndTag().

{
if (!is_int($user_id) || $user_id <= 0) {
return;
}
$memberObject = $this->exercise->members_obj;
if ($action == "Attach" && !$memberObject->isAssigned($user_id))
{
$memberObject->assignMember ($user_id);
}
if ($action == "Detach" && $memberObject->isAssigned($user_id))
{
$memberObject->deassignMember ($user_id);
}
}

+ Here is the caller graph for this function:

Field Documentation

ilExerciseXMLParser::$CONTENT_GZ_COMPRESSED = 1
static

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

Referenced by handlerBeginTag(), and updateFile().

ilExerciseXMLParser::$CONTENT_NOT_COMPRESSED = 0
static

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

Referenced by handlerBeginTag().

ilExerciseXMLParser::$CONTENT_ZLIB_COMPRESSED = 2
static

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

Referenced by handlerBeginTag(), and updateFile().

ilExerciseXMLParser::$exercise

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

Referenced by ilExerciseXMLParser().

ilExerciseXMLParser::$mode

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

ilExerciseXMLParser::$obj_id

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

Referenced by ilExerciseXMLParser().

ilExerciseXMLParser::$result

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


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