ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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

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

Constructor & Destructor Documentation

◆ __construct()

ilExerciseXMLWriter::__construct ( )

constructor

Parameters
stringxml version
stringoutput encoding
stringinput encoding @access public

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

56 {
57 // @todo: needs to be revised for multiple assignments per exercise
58 //die ("Needs revision for ILIAS 4.1");
60 $this->attachFileContents = ilExerciseXMLWriter::$CONTENT_ATTACH_NO;
61 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $CONTENT_ATTACH_NO, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ __buildFooter()

ilExerciseXMLWriter::__buildFooter ( )

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

150 {
151 }

Referenced by start().

+ Here is the caller graph for this function:

◆ __buildHeader()

ilExerciseXMLWriter::__buildHeader ( )

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

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

References ILIAS_HTTP_PATH, 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 169 of file class.ilExerciseXMLWriter.php.

170 {
171 $ass = new ilExAssignment($assignment_id);
172
173 $amark = $ass->getMemberStatus($user_id)->getMark();
174 $astatus = $ass->getMemberStatus($user_id)->getStatus();
175 $acomment = $ass->getMemberStatus($user_id)->getComment();
176 $anotice = $ass->getMemberStatus($user_id)->getNotice();
177
178
179 if ($astatus == "notgraded") {
181 } elseif ($astatus == "failed") {
183 } else {
185 }
186
187 $this->xmlStartTag("Marking", array("status" => $status ));
188 $this->xmlElement("Mark", null, $amark);
189 $this->xmlElement("Notice", null, $anotice);
190 $this->xmlElement("Comment", null, $acomment);
191 $this->xmlEndTag("Marking");
192 }
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 135 of file class.ilExerciseXMLWriter.php.

136 {
137 return $this->xmlDumpMem(false);
138 }
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 194 of file class.ilExerciseXMLWriter.php.

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

References $CONTENT_ATTACH_GZIP_ENCODED, $CONTENT_ATTACH_ZLIB_ENCODED, $filename, 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 232 of file class.ilExerciseXMLWriter.php.

233 {
234 $this->xmlStartTag("Members");
235 $members = ilExerciseMembers::_getMembers($ex_id);
236 if (count($members)) {
237 foreach ($members as $member_id) {
238 $this->xmlStartTag("Member", array("usr_id" => "il_" . IL_INST_ID . "_usr_" . $member_id ));
239
240 $name = ilObjUser::_lookupName($member_id);
241
242 $this->xmlElement("Firstname", array(), $name['firstname']);
243 $this->xmlElement("Lastname", array(), $name['lastname']);
244 $this->xmlElement("Login", array(), $name['login']);
245 $this->attachMarking($member_id, $assignment_id);
246 $this->xmlEndTag("Member");
247 }
248 }
249 $this->xmlEndTag("Members");
250 }
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
if($format !==null) $name
Definition: metadata.php:230

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

81 {
82 if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode")) {
83 throw new ilExerciseException("Inflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
84 }
85 if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress")) {
86 throw new ilExerciseException("Inflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
87 }
88
89 $this->attachFileContents = $attachFileContents;
90 }
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 158 of file class.ilExerciseXMLWriter.php.

159 {
160 $this->attachMembers = $value ? true : false;
161 }

◆ setExercise()

ilExerciseXMLWriter::setExercise (   $exercise)

set exercise object

Parameters
ilObjExercise$exercise

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

70 {
71 $this->exercise = $exercise;
72 }

References $exercise.

◆ start()

ilExerciseXMLWriter::start ( )

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

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
102 $this->xmlStartTag("Exercise", $attribs);
103
104 //todo: create new dtd for new assignment structure
105 $this->xmlElement("Title", null, $this->exercise->getTitle());
106 $this->xmlElement("Description", null, $this->exercise->getDescription());
107 //$this->xmlElement("Instruction", null,$this->exercise->getInstruction());
108 //$this->xmlElement("DueDate", null,$this->exercise->getTimestamp());
109
110
111 //todo: as a workaround use first assignment for compatibility with old exercise dtd
112 $assignments = ilExAssignment::getAssignmentDataOfExercise($this->exercise->getId());
113
114 if (count($assignments) > 0) {
115 foreach ($assignments as $assignment) {
116 $this->xmlStartTag("Assignment");
117 $this->xmlElement("Instruction", null, $assignment ["instruction"]);
118 $this->xmlElement("DueDate", null, $assignment ["deadline"]);
119
120 $this->handleAssignmentFiles($this->exercise->getId(), $assignment ["id"]);
121 if ($this->attachMembers) {
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

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

Referenced by setAttachFileContents().

◆ $attachMembers

ilExerciseXMLWriter::$attachMembers

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

◆ $CONTENT_ATTACH_ENCODED

ilExerciseXMLWriter::$CONTENT_ATTACH_ENCODED = 1
static

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

◆ $CONTENT_ATTACH_GZIP_ENCODED

ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED = 3
static

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

Referenced by handleAssignmentFiles(), and setAttachFileContents().

◆ $CONTENT_ATTACH_NO

ilExerciseXMLWriter::$CONTENT_ATTACH_NO = 0
static

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

Referenced by __construct().

◆ $CONTENT_ATTACH_ZLIB_ENCODED

ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED = 2
static

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

Referenced by handleAssignmentFiles(), and setAttachFileContents().

◆ $exercise

ilExerciseXMLWriter::$exercise

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

Referenced by setExercise().

◆ $STATUS_FAILED

ilExerciseXMLWriter::$STATUS_FAILED = "FAILED"
static

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