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

XML writer class. More...

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

Public Member Functions

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

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 More...
 
 handleAssignmentFiles ($ex_id, $as_id)
 
 handleAssignmentMembers ($ex_id, $assignment_id)
 create xml for files per assignment More...
 

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

◆ __buildFooter()

ilExerciseXMLWriter::__buildFooter ( )

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

Referenced by start().

147  {
148 
149  }
+ Here is the caller graph for this function:

◆ __buildHeader()

ilExerciseXMLWriter::__buildHeader ( )

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

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

Referenced by start().

139  {
140  $this->xmlSetDtdDef ( "<!DOCTYPE Exercise PUBLIC \"-//ILIAS//DTD ExerciseAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_exercise_4_4.dtd\">" );
141  $this->xmlSetGenCmt ( "Exercise Object" );
142  $this->xmlHeader ();
143 
144  return true;
145  }
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
xmlHeader()
Writes xml header public.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attachMarking()

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

166  {
167 
168  $amark = ilExAssignment::lookupMarkOfUser($assignment_id, $user_id);
169  $astatus = ilExAssignment::lookupStatusOfUser($assignment_id, $user_id);
170  $acomment = ilExAssignment::lookupCommentForUser($assignment_id, $user_id);
171  $anotice = ilExAssignment::lookupNoticeOfUser($assignment_id, $user_id);
172 
173 
174  if ($astatus == "notgraded") {
176  } elseif ($astatus == "failed") {
178  } else {
180  }
181 
182  $this->xmlStartTag ( "Marking", array ("status" => $status ) );
183  $this->xmlElement ( "Mark", null, $amark);
184  $this->xmlElement ( "Notice", null, $anotice );
185  $this->xmlElement ( "Comment", null, $acomment );
186  $this->xmlEndTag ( "Marking" );
187  }
lookupCommentForUser($a_ass_id, $a_user_id)
Lookup comment for the user.
lookupStatusOfUser($a_ass_id, $a_user_id)
was: getStatusByMember
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
lookupMarkOfUser($a_ass_id, $a_user_id)
Lookup user mark.
xmlEndTag($tag)
Writes an endtag.
lookupNoticeOfUser($a_ass_id, $a_user_id)
was: getNoticeByMember($a_member_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getXML()

ilExerciseXMLWriter::getXML ( )

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

References ilXmlWriter\xmlDumpMem().

135  {
136  return $this->xmlDumpMem ( FALSE );
137  }
xmlDumpMem($format=TRUE)
Returns xml document from memory.
+ Here is the call graph for this function:

◆ handleAssignmentFiles()

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

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

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

Referenced by start().

189  {
190  $this->xmlStartTag ( "Files" );
191  include_once ("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
192  $storage = new ilFSStorageExercise ( $ex_id, $as_id );
193  $files = $storage->getFiles ();
194 
195  if (count ( $files )) {
196  foreach ( $files as $file ) {
197  $this->xmlStartTag ( "File", array ("size" => $file ["size"] ) );
198  $this->xmlElement ( "Filename", null, $file ["name"] );
199  if ($this->attachFileContents) {
200  $filename = $file ["fullpath"];
201  if (@is_file ( $filename )) {
202  $content = @file_get_contents ( $filename );
203  $attribs = array ("mode" => "PLAIN" );
204  if ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
205  $attribs = array ("mode" => "ZLIB" );
206  $content = gzcompress ( $content, 9 );
207  } elseif ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
208  $attribs = array ("mode" => "GZIP" );
209  $content = gzencode ( $content, 9 );
210  }
211  $content = base64_encode ( $content );
212  $this->xmlElement ( "Content", $attribs, $content );
213  }
214  }
215  $this->xmlEndTag ( "File" );
216  }
217  }
218  $this->xmlEndTag ( "Files" );
219  }
print $file
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
xmlEndTag($tag)
Writes an endtag.
$filename
Definition: buildRTE.php:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleAssignmentMembers()

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

create xml for files per assignment

Parameters
integer$ex_idexercise id
array$assignmentsassignment id

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

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

Referenced by start().

227  {
228  $this->xmlStartTag ( "Members" );
229  include_once ("./Modules/Exercise/classes/class.ilExerciseMembers.php");
230  $members = ilExerciseMembers::_getMembers($ex_id);
231  if (count ( $members )) {
232  foreach ( $members as $member_id ) {
233  $this->xmlStartTag ( "Member", array ("usr_id" => "il_" . IL_INST_ID . "_usr_" . $member_id ) );
234  $this->attachMarking ( $member_id, $assignment_id);
235  $this->xmlEndTag ( "Member" );
236  }
237  }
238  $this->xmlEndTag ( "Members" );
239  }
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlEndTag($tag)
Writes an endtag.
attachMarking($user_id, $assignment_id)
attach marking tag to member for given assignment
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ilExerciseXMLWriter()

ilExerciseXMLWriter::ilExerciseXMLWriter ( )

constructor

Parameters
stringxml version
stringoutput encoding
stringinput encoding public

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

References $CONTENT_ATTACH_NO.

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

◆ setAttachFileContents()

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.

82  {
83  if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && ! function_exists ( "gzencode" )) {
84  throw new ilExerciseException ( "Inflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH );
85  }
86  if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && ! function_exists ( "gzcompress" )) {
87  throw new ilExerciseException ( "Inflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH );
88  }
89 
90  $this->attachFileContents = $attachFileContents;
91  }
Class to report exception.

◆ setAttachMembers()

ilExerciseXMLWriter::setAttachMembers (   $value)

write access to property attchMarkings

Parameters
boolean$value

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

156  {
157  $this->attachMembers = $value ? true : false;
158  }

◆ setExercise()

ilExerciseXMLWriter::setExercise ( $exercise)

set exercise object

Parameters
ilObjExercise$exercise

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

References $exercise.

72  {
73  $this->exercise = & $exercise;
74  }

◆ start()

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

93  {
94  $this->__buildHeader ();
95 
96  $attribs = array ("obj_id" => "il_" . IL_INST_ID . "_exc_" . $this->exercise->getId () );
97 
98  if ($this->exercise->getOwner ())
99  $attribs ["owner"] = "il_" . IL_INST_ID . "_usr_" . $this->exercise->getOwner ();
100 
101  $this->xmlStartTag ( "Exercise", $attribs );
102 
103  //todo: create new dtd for new assignment structure
104  $this->xmlElement("Title", null,$this->exercise->getTitle());
105  $this->xmlElement("Description", null,$this->exercise->getDescription());
106  //$this->xmlElement("Instruction", null,$this->exercise->getInstruction());
107  //$this->xmlElement("DueDate", null,$this->exercise->getTimestamp());
108 
109 
110  //todo: as a workaround use first assignment for compatibility with old exercise dtd
111  $assignments = ilExAssignment::getAssignmentDataOfExercise ( $this->exercise->getId () );
112 
113  if (count ( $assignments ) > 0) {
114  foreach ( $assignments as $assignment ) {
115  $this->xmlStartTag ("Assignment");
116  $this->xmlElement ( "Instruction", null, $assignment ["instruction"] );
117  $this->xmlElement ( "DueDate", null, $assignment ["deadline"] );
118 
119  $this->handleAssignmentFiles ( $this->exercise->getId (), $assignment ["id"] );
120  if ($this->attachMembers)
121  {
122  $this->handleAssignmentMembers ($this->exercise->getId (), $assignment ["id"]);
123  }
124  $this->xmlEndTag ( "Assignment" );
125  }
126  }
127 
128 
129  $this->xmlEndTag ( "Exercise" );
130  $this->__buildFooter ();
131 
132  return true;
133  }
static getAssignmentDataOfExercise($a_exc_id)
Get assignments data of an exercise in an array.
handleAssignmentMembers($ex_id, $assignment_id)
create xml for files per assignment
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
xmlEndTag($tag)
Writes an endtag.
+ Here is the call graph for this function:

Field Documentation

◆ $attachFileContents

ilExerciseXMLWriter::$attachFileContents

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

Referenced by setAttachFileContents().

◆ $attachMembers

ilExerciseXMLWriter::$attachMembers

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

◆ $CONTENT_ATTACH_ENCODED

ilExerciseXMLWriter::$CONTENT_ATTACH_ENCODED = 1
static

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

◆ $CONTENT_ATTACH_GZIP_ENCODED

ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED = 3
static

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

Referenced by handleAssignmentFiles(), and setAttachFileContents().

◆ $CONTENT_ATTACH_NO

ilExerciseXMLWriter::$CONTENT_ATTACH_NO = 0
static

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

Referenced by ilExerciseXMLWriter().

◆ $CONTENT_ATTACH_ZLIB_ENCODED

ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED = 2
static

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

Referenced by handleAssignmentFiles(), and setAttachFileContents().

◆ $exercise

ilExerciseXMLWriter::$exercise

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

Referenced by setExercise().

◆ $STATUS_FAILED

ilExerciseXMLWriter::$STATUS_FAILED = "FAILED"
static

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

Referenced by attachMarking().

◆ $STATUS_NOT_GRADED

ilExerciseXMLWriter::$STATUS_NOT_GRADED = "NOT_GRADED"
static

◆ $STATUS_PASSED

ilExerciseXMLWriter::$STATUS_PASSED = "PASSED"
static

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