ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilExerciseXMLWriter Class Reference

XML writer class. More...

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

Public Member Functions

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

Additional Inherited Members

- Static Public Member Functions inherited from ilXmlWriter
static _xmlEscapeData ($data)
 Escapes reserved characters. 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.

Constructor & Destructor Documentation

◆ __construct()

ilExerciseXMLWriter::__construct ( )

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::__construct();
63  $this->attachFileContents = ilExerciseXMLWriter::$CONTENT_ATTACH_NO;
64  }

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, array, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by handleAssignmentMembers().

166  {
167 
168  $ass = new ilExAssignment($assignment_id);
169 
170  $amark = $ass->getMemberStatus($user_id)->getMark();
171  $astatus = $ass->getMemberStatus($user_id)->getStatus();
172  $acomment = $ass->getMemberStatus($user_id)->getComment();
173  $anotice = $ass->getMemberStatus($user_id)->getNotice();
174 
175 
176  if ($astatus == "notgraded") {
178  } elseif ($astatus == "failed") {
180  } else {
182  }
183 
184  $this->xmlStartTag ( "Marking", array ("status" => $status ) );
185  $this->xmlElement ( "Mark", null, $amark);
186  $this->xmlElement ( "Notice", null, $anotice );
187  $this->xmlElement ( "Comment", null, $acomment );
188  $this->xmlEndTag ( "Marking" );
189  }
Exercise 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.
Create styles array
The data for the language used.
+ 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 191 of file class.ilExerciseXMLWriter.php.

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

Referenced by start().

191  {
192  $this->xmlStartTag ( "Files" );
193  include_once ("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
194  $storage = new ilFSStorageExercise ( $ex_id, $as_id );
195  $files = $storage->getFiles ();
196 
197  if (count ( $files )) {
198  foreach ( $files as $file ) {
199  $this->xmlStartTag ( "File", array ("size" => $file ["size"] ) );
200  $this->xmlElement ( "Filename", null, $file ["name"] );
201  if ($this->attachFileContents) {
202  $filename = $file ["fullpath"];
203  if (@is_file ( $filename )) {
204  $content = @file_get_contents ( $filename );
205  $attribs = array ("mode" => "PLAIN" );
206  if ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
207  $attribs = array ("mode" => "ZLIB" );
208  $content = gzcompress ( $content, 9 );
209  } elseif ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
210  $attribs = array ("mode" => "GZIP" );
211  $content = gzencode ( $content, 9 );
212  }
213  $content = base64_encode ( $content );
214  $this->xmlElement ( "Content", $attribs, $content );
215  }
216  }
217  $this->xmlEndTag ( "File" );
218  }
219  }
220  $this->xmlEndTag ( "Files" );
221  }
$files
Definition: add-vimline.php:18
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.
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ 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 229 of file class.ilExerciseXMLWriter.php.

References ilExerciseMembers\_getMembers(), ilObjUser\_lookupName(), array, attachMarking(), ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by start().

229  {
230  $this->xmlStartTag ( "Members" );
231  include_once ("./Modules/Exercise/classes/class.ilExerciseMembers.php");
232  $members = ilExerciseMembers::_getMembers($ex_id);
233  if (count ( $members )) {
234  foreach ( $members as $member_id ) {
235  $this->xmlStartTag ( "Member", array ("usr_id" => "il_" . IL_INST_ID . "_usr_" . $member_id ) );
236 
237  $name = ilObjUser::_lookupName($member_id);
238 
239  $this->xmlElement("Firstname", array(), $name['firstname']);
240  $this->xmlElement("Lastname", array(), $name['lastname']);
241  $this->xmlElement("Login", array(), $name['login']);
242  $this->attachMarking ( $member_id, $assignment_id);
243  $this->xmlEndTag ( "Member" );
244  }
245  }
246  $this->xmlEndTag ( "Members" );
247  }
static _lookupName($a_user_id)
lookup user name
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.
attachMarking($user_id, $assignment_id)
attach marking tag to member for given assignment
Create styles array
The data for the language used.
static _getMembers($a_obj_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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(), array, 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.
Create styles array
The data for the language used.
+ 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 __construct().

◆ $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: