ILIAS  release_8 Revision v8.24
ilExerciseXMLWriter Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 __construct ()
 
 setExercise (ilObjExercise $exercise)
 
 setAttachFileContents (int $attachFileContents)
 set attachment content mode More...
 
 start ()
 
 getXML ()
 
 __buildHeader ()
 
 __buildFooter ()
 
 setAttachMembers (bool $value)
 write access to property attchMarkings More...
 
- Public Member Functions inherited from ilXmlWriter
 __construct (string $version="1.0", string $outEnc="utf-8", string $inEnc="utf-8")
 
 xmlSetDtdDef (string $dtdDef)
 Sets dtd definition. More...
 
 xmlSetGenCmt (string $genCmt)
 Sets generated comment. More...
 
 xmlFormatData (string $data)
 Indents text for better reading. More...
 
 xmlHeader ()
 Writes xml header. More...
 
 xmlStartTag (string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
 Writes a starttag. More...
 
 xmlEndTag (string $tag)
 Writes an endtag. More...
 
 xmlData (string $data, bool $encode=true, bool $escape=true)
 Writes data. More...
 
 xmlElement (string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
 Writes a basic element (no children, just textual content) More...
 
 xmlDumpFile (string $file, bool $format=true)
 Dumps xml document from memory into a file. More...
 
 xmlDumpMem (bool $format=true)
 Returns xml document from memory. More...
 
 appendXML (string $a_str)
 append xml string to document More...
 
 xmlClear ()
 clears xmlStr More...
 

Data Fields

bool $attachFileContents
 
bool $attachMembers
 
ilObjExercise $exercise
 

Static Public Attributes

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

Private Member Functions

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

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 27 of file class.ilExerciseXMLWriter.php.

Constructor & Destructor Documentation

◆ __construct()

ilExerciseXMLWriter::__construct ( )

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

43 {
44 // @todo: needs to be revised for multiple assignments per exercise
45 //die ("Needs revision for ILIAS 4.1");
47 $this->attachFileContents = ilExerciseXMLWriter::$CONTENT_ATTACH_NO;
48 }
__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 128 of file class.ilExerciseXMLWriter.php.

128 : void
129 {
130 }

Referenced by start().

+ Here is the caller graph for this function:

◆ __buildHeader()

ilExerciseXMLWriter::__buildHeader ( )

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

119 : bool
120 {
121 $this->xmlSetDtdDef("<!DOCTYPE Exercise PUBLIC \"-//ILIAS//DTD ExerciseAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_exercise_4_4.dtd\">");
122 $this->xmlSetGenCmt("Exercise Object");
123 $this->xmlHeader();
124
125 return true;
126 }
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlHeader()
Writes xml header.
xmlSetDtdDef(string $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 ( int  $user_id,
int  $assignment_id 
)
private

attach marking tag to member for given assignment

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

146 : void {
147 $ass = new ilExAssignment($assignment_id);
148
149 $amark = $ass->getMemberStatus($user_id)->getMark();
150 $astatus = $ass->getMemberStatus($user_id)->getStatus();
151 $acomment = $ass->getMemberStatus($user_id)->getComment();
152 $anotice = $ass->getMemberStatus($user_id)->getNotice();
153
154
155 if ($astatus == "notgraded") {
157 } elseif ($astatus == "failed") {
159 } else {
161 }
162
163 $this->xmlStartTag("Marking", array("status" => $status ));
164 $this->xmlElement("Mark", null, $amark);
165 $this->xmlElement("Notice", null, $anotice);
166 $this->xmlElement("Comment", null, $acomment);
167 $this->xmlEndTag("Marking");
168 }
Exercise assignment.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.

References $STATUS_NOT_GRADED.

◆ getXML()

ilExerciseXMLWriter::getXML ( )

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

114 : string
115 {
116 return $this->xmlDumpMem(false);
117 }
xmlDumpMem(bool $format=true)
Returns xml document from memory.

References ilXmlWriter\xmlDumpMem().

+ Here is the call graph for this function:

◆ handleAssignmentFiles()

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

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

173 : void {
174 $this->xmlStartTag("Files");
175 $storage = new ilFSStorageExercise($ex_id, $as_id);
176 $files = $storage->getFiles();
177
178 if (count($files)) {
179 foreach ($files as $file) {
180 $this->xmlStartTag("File", array("size" => $file ["size"] ));
181 $this->xmlElement("Filename", null, $file ["name"]);
182 if ($this->attachFileContents) {
183 $filename = $file ["fullpath"];
184 if (is_file($filename)) {
185 $content = file_get_contents($filename);
186 $attribs = array("mode" => "PLAIN" );
187 if ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
188 $attribs = array("mode" => "ZLIB" );
189 $content = gzcompress($content, 9);
190 } elseif ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
191 $attribs = array("mode" => "GZIP" );
192 $content = gzencode($content, 9);
193 }
194 $content = base64_encode($content);
195 $this->xmlElement("Content", $attribs, $content);
196 }
197 }
198 $this->xmlEndTag("File");
199 }
200 }
201 $this->xmlEndTag("Files");
202 }
$filename
Definition: buildRTE.php:78
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Referenced by start().

+ Here is the caller graph for this function:

◆ handleAssignmentMembers()

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

create xml for files per assignment

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

210 : void {
211 $this->xmlStartTag("Members");
212 $members = ilExerciseMembers::_getMembers($ex_id);
213 if (count($members)) {
214 foreach ($members as $member_id) {
215 $this->xmlStartTag("Member", array("usr_id" => "il_" . IL_INST_ID . "_usr_" . $member_id ));
216
217 $name = ilObjUser::_lookupName($member_id);
218
219 $this->xmlElement("Firstname", array(), $name['firstname']);
220 $this->xmlElement("Lastname", array(), $name['lastname']);
221 $this->xmlElement("Login", array(), $name['login']);
222 $this->attachMarking($member_id, $assignment_id);
223 $this->xmlEndTag("Member");
224 }
225 }
226 $this->xmlEndTag("Members");
227 }
static _getMembers(int $a_obj_id)
attachMarking(int $user_id, int $assignment_id)
attach marking tag to member for given assignment
static _lookupName(int $a_user_id)
lookup user name
const IL_INST_ID
Definition: constants.php:40
if($format !==null) $name
Definition: metadata.php:247

Referenced by start().

+ Here is the caller graph for this function:

◆ setAttachFileContents()

ilExerciseXMLWriter::setAttachFileContents ( int  $attachFileContents)

set attachment content mode

Exceptions
ilExerciseExceptionif mode is not supported

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

59 : void
60 {
61 if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode")) {
62 throw new ilExerciseException("Inflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
63 }
64 if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress")) {
65 throw new ilExerciseException("Inflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
66 }
67
68 $this->attachFileContents = $attachFileContents;
69 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

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

◆ setAttachMembers()

ilExerciseXMLWriter::setAttachMembers ( bool  $value)

write access to property attchMarkings

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

135 : void
136 {
137 $this->attachMembers = $value;
138 }

◆ setExercise()

ilExerciseXMLWriter::setExercise ( ilObjExercise  $exercise)

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

50 : void
51 {
52 $this->exercise = $exercise;
53 }

References $exercise.

◆ start()

ilExerciseXMLWriter::start ( )

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

71 : bool
72 {
73 $this->__buildHeader();
74
75 $attribs = array("obj_id" => "il_" . IL_INST_ID . "_exc_" . $this->exercise->getId() );
76
77 if ($this->exercise->getOwner() !== 0) {
78 $attribs ["owner"] = "il_" . IL_INST_ID . "_usr_" . $this->exercise->getOwner();
79 }
80
81 $this->xmlStartTag("Exercise", $attribs);
82
83 //todo: create new dtd for new assignment structure
84 $this->xmlElement("Title", null, $this->exercise->getTitle());
85 $this->xmlElement("Description", null, $this->exercise->getDescription());
86 //$this->xmlElement("Instruction", null,$this->exercise->getInstruction());
87 //$this->xmlElement("DueDate", null,$this->exercise->getTimestamp());
88
89
90 //todo: as a workaround use first assignment for compatibility with old exercise dtd
91 $assignments = ilExAssignment::getAssignmentDataOfExercise($this->exercise->getId());
92
93 if (count($assignments) > 0) {
94 foreach ($assignments as $assignment) {
95 $this->xmlStartTag("Assignment");
96 $this->xmlElement("Instruction", null, $assignment ["instruction"]);
97 $this->xmlElement("DueDate", null, $assignment ["deadline"]);
98
99 $this->handleAssignmentFiles($this->exercise->getId(), $assignment ["id"]);
100 if ($this->attachMembers) {
101 $this->handleAssignmentMembers($this->exercise->getId(), $assignment ["id"]);
102 }
103 $this->xmlEndTag("Assignment");
104 }
105 }
106
107
108 $this->xmlEndTag("Exercise");
109 $this->__buildFooter();
110
111 return true;
112 }
static getAssignmentDataOfExercise(int $a_exc_id)
handleAssignmentMembers(int $ex_id, int $assignment_id)
create xml for files per assignment
handleAssignmentFiles(int $ex_id, int $as_id)

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

+ Here is the call graph for this function:

Field Documentation

◆ $attachFileContents

bool ilExerciseXMLWriter::$attachFileContents

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

Referenced by setAttachFileContents().

◆ $attachMembers

bool ilExerciseXMLWriter::$attachMembers

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

◆ $CONTENT_ATTACH_ENCODED

int ilExerciseXMLWriter::$CONTENT_ATTACH_ENCODED = 1
static

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

◆ $CONTENT_ATTACH_GZIP_ENCODED

int ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED = 3
static

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

Referenced by setAttachFileContents().

◆ $CONTENT_ATTACH_NO

int ilExerciseXMLWriter::$CONTENT_ATTACH_NO = 0
static

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

Referenced by __construct().

◆ $CONTENT_ATTACH_ZLIB_ENCODED

int ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED = 2
static

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

Referenced by setAttachFileContents().

◆ $exercise

ilObjExercise ilExerciseXMLWriter::$exercise

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

Referenced by setExercise().

◆ $STATUS_FAILED

string ilExerciseXMLWriter::$STATUS_FAILED = "FAILED"
static

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

◆ $STATUS_NOT_GRADED

string ilExerciseXMLWriter::$STATUS_NOT_GRADED = "NOT_GRADED"
static

◆ $STATUS_PASSED

string ilExerciseXMLWriter::$STATUS_PASSED = "PASSED"
static

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

Referenced by ilExerciseXMLParser\handlerBeginTag().


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