Public Member Functions | Data Fields | Static Public Attributes | Private Member Functions

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.

Data Fields

 $exercise
 $obj_id
 $result
 $mode

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

Detailed Description

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

Author:
Roland Küstermann <roland@kuestermann.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_parser xml parser
string $a_name element name
array $a_attribs element attributes array
Exceptions:
ilExerciseException when 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, 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':
                $this->mode = ilExerciseXMLParser::$CONTENT_NOT_COMPRESSED;
                            if ($a_attribs["mode"] == "GZIP")
                            {
                    if (!function_exists("gzdecode"))
                        throw new  ilExerciseException ("Deflating with gzip is not supported",  ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);

                                $this->mode = ilExerciseXMLParser::$CONTENT_GZ_COMPRESSED;
                            } 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);

                                $this->mode = ilExerciseXMLParser::$CONTENT_ZLIB_COMPRESSED;
                            }
                            break;

                }
        }

Here is the call graph for this function:

ilExerciseXMLParser::handlerCharacterData ( a_xml_parser,
a_data 
)

handler for character data

Parameters:
resource $a_xml_parser xml parser
string $a_data character data

Definition at line 214 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_parser xml parser
string $a_name element name

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

References updateFile(), 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);
                            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;

                }

                $this->cdata = '';

                return;
        }

Here is the call graph for this function:

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

Constructor.

Parameters:
ilExercise $exercise existing exercise object
string $a_xml_file xml data
int $obj_id obj 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().

        {
                parent::ilSaxParser();
                $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:
resource reference 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:
ilExerciseException when 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 283 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 $content base 64 encoded string
string $action can be Attach or Detach

Definition at line 253 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);
           if ($this->mode == ilExerciseXMLParser::$CONTENT_GZ_COMPRESSED) {
                $content = gzdecode($content);
               }elseif ($this->mode ==ilExerciseXMLParser::$CONTENT_ZLIB_COMPRESSED) {
                $content = gzuncompress($content);
               }
           $fileObject->storeContentAsFile ($filename, $content);
        }
        if ($action == "Detach")
        {
            $fileObject->unlinkFile ($filename);
        }
        }

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 $action can be Attach or Detach

Definition at line 229 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: