ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilExerciseXMLWriter Class Reference

XML writer class. More...

+ Inheritance diagram for ilExerciseXMLWriter:
+ Collaboration diagram for ilExerciseXMLWriter:

Public Member Functions

 ilExerciseXMLWriter ()
 constructor
 setExercise (&$exercise)
 set exercise object
 setAttachFileContents ($attachFileContents)
 set attachment content mode
 start ()
 getXML ()
 __buildHeader ()
 __buildFooter ()
 setAttachMembers ($value)
 write access to property attchMarkings
- Public Member Functions inherited from ilXmlWriter
 ilXmlWriter ($version="1.0", $outEnc="utf-8", $inEnc="utf-8")
 constructor
 _ilXmlWriter ()
 destructor public
 xmlSetDtdDef ($dtdDef)
 Sets dtd definition.
 xmlSetStSheet ($stSheet)
 Sets stylesheet.
 xmlSetGenCmt ($genCmt)
 Sets generated comment.
 _xmlEscapeData ($data)
 Escapes reserved characters.
 xmlEncodeData ($data)
 Encodes text from input encoding into output encoding.
 xmlFormatData ($data)
 Indents text for better reading.
 xmlFormatElement ($array)
 Callback function for xmlFormatData; do not invoke directly.
 xmlHeader ()
 Writes xml header public.
 xmlStartTag ($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
 Writes a starttag.
 xmlEndTag ($tag)
 Writes an endtag.
 xmlComment ($comment)
 Writes a comment.
 xmlData ($data, $encode=TRUE, $escape=TRUE)
 Writes data.
 xmlElement ($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
 Writes a basic element (no children, just textual content)
 xmlDumpFile ($file, $format=TRUE)
 Dumps xml document from memory into a file.
 xmlDumpMem ($format=TRUE)
 Returns xml document from memory.
 appendXML ($a_str)
 append xml string to document
 xmlClear ()
 clears xmlStr public

Data Fields

 $attachFileContents
 $attachMembers
 $exercise
- Data Fields inherited from ilXmlWriter
 $xmlStr
 $version
 $outEnc
 $inEnc
 $dtdDef = ""
 $stSheet = ""
 $genCmt = "Generated by ILIAS XmlWriter"

Static Public Attributes

static $CONTENT_ATTACH_NO = 0
static $CONTENT_ATTACH_ENCODED = 1
static $CONTENT_ATTACH_ZLIB_ENCODED = 2
static $CONTENT_ATTACH_GZIP_ENCODED = 3
static $STATUS_NOT_GRADED = "NOT_GRADED"
static $STATUS_PASSED = "PASSED"
static $STATUS_FAILED = "FAILED"

Private Member Functions

 attachMarking ($user_id, $assignment_id)
 attach marking tag to member for given assignment
 handleAssignmentFiles ($ex_id, $as_id)
 handleAssignmentMembers ($ex_id, $assignments)
 create xml for files per assignment

Detailed Description

XML writer class.

Class to simplify manual writing of xml documents. It only supports writing xml sequentially, because the xml document is saved in a string with no additional structure information. The author is responsible for well-formedness and validity of the xml document.

Author
Roland Küstermann Rolan.nosp@m.d@ku.nosp@m.ester.nosp@m.mann.nosp@m..com
Version
Id:
class.ilExerciseXMLWriter.php,v 1.3 2005/11/04 12:50:24 smeyer Exp

Definition at line 21 of file class.ilExerciseXMLWriter.php.

Member Function Documentation

ilExerciseXMLWriter::__buildFooter ( )

Definition at line 151 of file class.ilExerciseXMLWriter.php.

Referenced by start().

{
}

+ Here is the caller graph for this function:

ilExerciseXMLWriter::__buildHeader ( )

Definition at line 143 of file class.ilExerciseXMLWriter.php.

References ilXmlWriter\xmlHeader(), ilXmlWriter\xmlSetDtdDef(), and ilXmlWriter\xmlSetGenCmt().

Referenced by start().

{
$this->xmlSetDtdDef ( "<!DOCTYPE Exercise PUBLIC \"-//ILIAS//DTD ExerciseAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_exercise_3_10.dtd\">" );
$this->xmlSetGenCmt ( "Exercise Object" );
$this->xmlHeader ();
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilExerciseXMLWriter::attachMarking (   $user_id,
  $assignment_id 
)
private

attach marking tag to member for given assignment

Parameters
int$user_id
int$assignment_id

Definition at line 170 of file class.ilExerciseXMLWriter.php.

References $STATUS_FAILED, $STATUS_NOT_GRADED, $STATUS_PASSED, ilExAssignment\lookupCommentForUser(), ilExAssignment\lookupMarkOfUser(), ilExAssignment\lookupNoticeOfUser(), ilExAssignment\lookupStatusOfUser(), ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by handleAssignmentMembers().

{
$amark = ilExAssignment::lookupMarkOfUser($assignment_id, $user_id);
$astatus = ilExAssignment::lookupStatusOfUser($assignment_id, $user_id);
$acomment = ilExAssignment::lookupCommentForUser($assignment_id, $user_id);
$anotice = ilExAssignment::lookupNoticeOfUser($assignment_id, $user_id);
if ($astatus == "notgraded") {
} elseif ($astatus == "failed") {
} else {
}
$this->xmlStartTag ( "Marking", array ("status" => $status ) );
$this->xmlElement ( "Mark", null, $amark);
$this->xmlElement ( "Notice", null, $anotice );
$this->xmlElement ( "Comment", null, $acomment );
$this->xmlEndTag ( "Marking" );
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilExerciseXMLWriter::getXML ( )

Definition at line 139 of file class.ilExerciseXMLWriter.php.

References ilXmlWriter\xmlDumpMem().

{
return $this->xmlDumpMem ( FALSE );
}

+ Here is the call graph for this function:

ilExerciseXMLWriter::handleAssignmentFiles (   $ex_id,
  $as_id 
)
private

Definition at line 193 of file class.ilExerciseXMLWriter.php.

References $CONTENT_ATTACH_GZIP_ENCODED, $CONTENT_ATTACH_ZLIB_ENCODED, $file, $filename, $files, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by start().

{
$this->xmlStartTag ( "Files" );
include_once ("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
$storage = new ilFSStorageExercise ( $ex_id, $as_id );
$files = $storage->getFiles ();
if (count ( $files )) {
foreach ( $files as $file ) {
$this->xmlStartTag ( "File", array ("size" => $file ["size"] ) );
$this->xmlElement ( "Filename", null, $file ["name"] );
if ($this->attachFileContents) {
$filename = $file ["fullpath"];
if (@is_file ( $filename )) {
$content = @file_get_contents ( $filename );
$attribs = array ("mode" => "PLAIN" );
if ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
$attribs = array ("mode" => "ZLIB" );
$content = gzcompress ( $content, 9 );
} elseif ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
$attribs = array ("mode" => "GZIP" );
$content = gzencode ( $content, 9 );
}
$content = base64_encode ( $content );
$this->xmlElement ( "Content", $attribs, $content );
}
}
$this->xmlEndTag ( "File" );
}
}
$this->xmlEndTag ( "Files" );
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilExerciseXMLWriter::handleAssignmentMembers (   $ex_id,
  $assignments 
)
private

create xml for files per assignment

Parameters
integer$ex_idexercise id
array$assignmentsassignment id

Definition at line 231 of file class.ilExerciseXMLWriter.php.

References ilExerciseMembers\_getMembers(), attachMarking(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by start().

{
$this->xmlStartTag ( "Members" );
include_once ("./Modules/Exercise/classes/class.ilExerciseMembers.php");
$members = ilExerciseMembers::_getMembers($ex_id);
if (count ( $members )) {
foreach ( $members as $member_id ) {
$this->xmlStartTag ( "Member", array ("usr_id" => "il_" . IL_INST_ID . "_usr_" . $member_id ) );
if (count ($assignments) > 0) {
foreach($assignments as $assignment) {
$this->attachMarking ( $member_id, $assignment["id"] );
//todo: handle only first assignment, must be fixed when for dtd
break;
}
}
$this->xmlEndTag ( "Member" );
}
}
$this->xmlEndTag ( "Members" );
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilExerciseXMLWriter::ilExerciseXMLWriter ( )

constructor

Parameters
stringxml version
stringoutput encoding
stringinput encoding public

Definition at line 59 of file class.ilExerciseXMLWriter.php.

References $CONTENT_ATTACH_NO, and ilXmlWriter\ilXmlWriter().

{
// @todo: needs to be revised for multiple assignments per exercise
//die ("Needs revision for ILIAS 4.1");
$this->attachFileContents = ilExerciseXMLWriter::$CONTENT_ATTACH_NO;
}

+ Here is the call graph for this function:

ilExerciseXMLWriter::setAttachFileContents (   $attachFileContents)

set attachment content mode

Parameters
int$attachFileContents
Exceptions
ilExerciseExceptionif mode is not supported

Definition at line 82 of file class.ilExerciseXMLWriter.php.

References $attachFileContents, $CONTENT_ATTACH_GZIP_ENCODED, $CONTENT_ATTACH_ZLIB_ENCODED, and ilExerciseException\$ID_DEFLATE_METHOD_MISMATCH.

{
if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && ! function_exists ( "gzencode" )) {
throw new ilExerciseException ( "Inflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH );
}
if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && ! function_exists ( "gzcompress" )) {
throw new ilExerciseException ( "Inflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH );
}
$this->attachFileContents = $attachFileContents;
}
ilExerciseXMLWriter::setAttachMembers (   $value)

write access to property attchMarkings

Parameters
boolean$value

Definition at line 160 of file class.ilExerciseXMLWriter.php.

{
$this->attachMembers = $value ? true : false;
}
ilExerciseXMLWriter::setExercise ( $exercise)

set exercise object

Parameters
ilObjExercise$exercise

Definition at line 72 of file class.ilExerciseXMLWriter.php.

References $exercise.

{
$this->exercise = & $exercise;
}
ilExerciseXMLWriter::start ( )

Definition at line 93 of file class.ilExerciseXMLWriter.php.

References __buildFooter(), __buildHeader(), ilExAssignment\getAssignmentDataOfExercise(), handleAssignmentFiles(), handleAssignmentMembers(), ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

{
$this->__buildHeader ();
$attribs = array ("obj_id" => "il_" . IL_INST_ID . "_exc_" . $this->exercise->getId () );
if ($this->exercise->getOwner ())
$attribs ["owner"] = "il_" . IL_INST_ID . "_usr_" . $this->exercise->getOwner ();
$this->xmlStartTag ( "Exercise", $attribs );
//todo: create new dtd for new assignment structure
//$this->xmlElement("Title", null,$this->exercise->getTitle());
//$this->xmlElement("Description", null,$this->exercise->getDescription());
//$this->xmlElement("Instruction", null,$this->exercise->getInstruction());
//$this->xmlElement("DueDate", null,$this->exercise->getTimestamp());
//todo: as a workaround use first assignment for compatibility with old exercise dtd
$assignments = ilExAssignment::getAssignmentDataOfExercise ( $this->exercise->getId () );
if (count ( $assignments ) > 0) {
foreach ( $assignments as $assignment ) {
$this->xmlElement ( "Title", null, $this->exercise->getTitle ());
$this->xmlElement ( "Description", null, $this->exercise->getDescription () );
$this->xmlElement ( "Instruction", null, $assignment ["instruction"] );
$this->xmlElement ( "DueDate", null, $assignment ["deadline"] );
$this->handleAssignmentFiles ( $this->exercise->getId (), $assignment ["id"] );
//todo: we handle only the first one for workaround, remove later for new dtd
break;
}
} else {
$this->xmlElement ( "Title", null, $this->exercise->getTitle () );
$this->xmlElement ( "Description", null, $this->exercise->getDescription () );
}
if ($this->attachMembers) {
$this->handleAssignmentMembers ($this->exercise->getId (), $assignments);
}
$this->xmlEndTag ( "Exercise" );
$this->__buildFooter ();
return true;
}

+ Here is the call graph for this function:

Field Documentation

ilExerciseXMLWriter::$attachFileContents

Definition at line 36 of file class.ilExerciseXMLWriter.php.

Referenced by setAttachFileContents().

ilExerciseXMLWriter::$attachMembers

Definition at line 43 of file class.ilExerciseXMLWriter.php.

ilExerciseXMLWriter::$CONTENT_ATTACH_ENCODED = 1
static

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

ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED = 3
static

Definition at line 26 of file class.ilExerciseXMLWriter.php.

Referenced by handleAssignmentFiles(), and setAttachFileContents().

ilExerciseXMLWriter::$CONTENT_ATTACH_NO = 0
static

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

Referenced by ilExerciseXMLWriter().

ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED = 2
static

Definition at line 25 of file class.ilExerciseXMLWriter.php.

Referenced by handleAssignmentFiles(), and setAttachFileContents().

ilExerciseXMLWriter::$exercise

Definition at line 50 of file class.ilExerciseXMLWriter.php.

Referenced by setExercise().

ilExerciseXMLWriter::$STATUS_FAILED = "FAILED"
static

Definition at line 30 of file class.ilExerciseXMLWriter.php.

Referenced by attachMarking().

ilExerciseXMLWriter::$STATUS_NOT_GRADED = "NOT_GRADED"
static
ilExerciseXMLWriter::$STATUS_PASSED = "PASSED"
static

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