ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 @access 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 @access 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 @access 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 @access public

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

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

References $CONTENT_ATTACH_NO.

Member Function Documentation

◆ __buildFooter()

ilExerciseXMLWriter::__buildFooter ( )

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

154 {
155 }

Referenced by start().

+ Here is the caller graph for this function:

◆ __buildHeader()

ilExerciseXMLWriter::__buildHeader ( )

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

145 {
146 $this->xmlSetDtdDef("<!DOCTYPE Exercise PUBLIC \"-//ILIAS//DTD ExerciseAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_exercise_4_4.dtd\">");
147 $this->xmlSetGenCmt("Exercise Object");
148 $this->xmlHeader();
149
150 return true;
151 }
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlHeader()
Writes xml header @access public.
xmlSetDtdDef($dtdDef)
Sets dtd definition.

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

Referenced by start().

+ 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 173 of file class.ilExerciseXMLWriter.php.

174 {
175 $ass = new ilExAssignment($assignment_id);
176
177 $amark = $ass->getMemberStatus($user_id)->getMark();
178 $astatus = $ass->getMemberStatus($user_id)->getStatus();
179 $acomment = $ass->getMemberStatus($user_id)->getComment();
180 $anotice = $ass->getMemberStatus($user_id)->getNotice();
181
182
183 if ($astatus == "notgraded") {
185 } elseif ($astatus == "failed") {
187 } else {
189 }
190
191 $this->xmlStartTag("Marking", array("status" => $status ));
192 $this->xmlElement("Mark", null, $amark);
193 $this->xmlElement("Notice", null, $anotice);
194 $this->xmlElement("Comment", null, $acomment);
195 $this->xmlEndTag("Marking");
196 }
Exercise assignment.
xmlEndTag($tag)
Writes an endtag.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.

References $STATUS_FAILED, $STATUS_NOT_GRADED, $STATUS_PASSED, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by handleAssignmentMembers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getXML()

ilExerciseXMLWriter::getXML ( )

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

140 {
141 return $this->xmlDumpMem(false);
142 }
xmlDumpMem($format=true)
Returns xml document from memory.

References ilXmlWriter\xmlDumpMem().

+ Here is the call graph for this function:

◆ handleAssignmentFiles()

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

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

199 {
200 $this->xmlStartTag("Files");
201 include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
202 $storage = new ilFSStorageExercise($ex_id, $as_id);
203 $files = $storage->getFiles();
204
205 if (count($files)) {
206 foreach ($files as $file) {
207 $this->xmlStartTag("File", array("size" => $file ["size"] ));
208 $this->xmlElement("Filename", null, $file ["name"]);
209 if ($this->attachFileContents) {
210 $filename = $file ["fullpath"];
211 if (@is_file($filename)) {
212 $content = @file_get_contents($filename);
213 $attribs = array("mode" => "PLAIN" );
214 if ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
215 $attribs = array("mode" => "ZLIB" );
216 $content = gzcompress($content, 9);
217 } elseif ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
218 $attribs = array("mode" => "GZIP" );
219 $content = gzencode($content, 9);
220 }
221 $content = base64_encode($content);
222 $this->xmlElement("Content", $attribs, $content);
223 }
224 }
225 $this->xmlEndTag("File");
226 }
227 }
228 $this->xmlEndTag("Files");
229 }
$filename
Definition: buildRTE.php:89
$files
Definition: metarefresh.php:49

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

Referenced by start().

+ 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 237 of file class.ilExerciseXMLWriter.php.

238 {
239 $this->xmlStartTag("Members");
240 include_once("./Modules/Exercise/classes/class.ilExerciseMembers.php");
241 $members = ilExerciseMembers::_getMembers($ex_id);
242 if (count($members)) {
243 foreach ($members as $member_id) {
244 $this->xmlStartTag("Member", array("usr_id" => "il_" . IL_INST_ID . "_usr_" . $member_id ));
245
246 $name = ilObjUser::_lookupName($member_id);
247
248 $this->xmlElement("Firstname", array(), $name['firstname']);
249 $this->xmlElement("Lastname", array(), $name['lastname']);
250 $this->xmlElement("Login", array(), $name['login']);
251 $this->attachMarking($member_id, $assignment_id);
252 $this->xmlEndTag("Member");
253 }
254 }
255 $this->xmlEndTag("Members");
256 }
static _getMembers($a_obj_id)
attachMarking($user_id, $assignment_id)
attach marking tag to member for given assignment
static _lookupName($a_user_id)
lookup user name

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

Referenced by start().

+ 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 84 of file class.ilExerciseXMLWriter.php.

85 {
86 if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode")) {
87 throw new ilExerciseException("Inflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
88 }
89 if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress")) {
90 throw new ilExerciseException("Inflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
91 }
92
93 $this->attachFileContents = $attachFileContents;
94 }
Exercise exceptions class.

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

◆ setAttachMembers()

ilExerciseXMLWriter::setAttachMembers (   $value)

write access to property attchMarkings

Parameters
boolean$value

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

163 {
164 $this->attachMembers = $value ? true : false;
165 }

◆ setExercise()

ilExerciseXMLWriter::setExercise (   $exercise)

set exercise object

Parameters
ilObjExercise$exercise

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

74 {
75 $this->exercise = $exercise;
76 }

References $exercise.

◆ start()

ilExerciseXMLWriter::start ( )

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

97 {
98 $this->__buildHeader();
99
100 $attribs = array("obj_id" => "il_" . IL_INST_ID . "_exc_" . $this->exercise->getId() );
101
102 if ($this->exercise->getOwner()) {
103 $attribs ["owner"] = "il_" . IL_INST_ID . "_usr_" . $this->exercise->getOwner();
104 }
105
106 $this->xmlStartTag("Exercise", $attribs);
107
108 //todo: create new dtd for new assignment structure
109 $this->xmlElement("Title", null, $this->exercise->getTitle());
110 $this->xmlElement("Description", null, $this->exercise->getDescription());
111 //$this->xmlElement("Instruction", null,$this->exercise->getInstruction());
112 //$this->xmlElement("DueDate", null,$this->exercise->getTimestamp());
113
114
115 //todo: as a workaround use first assignment for compatibility with old exercise dtd
116 $assignments = ilExAssignment::getAssignmentDataOfExercise($this->exercise->getId());
117
118 if (count($assignments) > 0) {
119 foreach ($assignments as $assignment) {
120 $this->xmlStartTag("Assignment");
121 $this->xmlElement("Instruction", null, $assignment ["instruction"]);
122 $this->xmlElement("DueDate", null, $assignment ["deadline"]);
123
124 $this->handleAssignmentFiles($this->exercise->getId(), $assignment ["id"]);
125 if ($this->attachMembers) {
126 $this->handleAssignmentMembers($this->exercise->getId(), $assignment ["id"]);
127 }
128 $this->xmlEndTag("Assignment");
129 }
130 }
131
132
133 $this->xmlEndTag("Exercise");
134 $this->__buildFooter();
135
136 return true;
137 }
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

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

+ 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: