ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilExerciseXMLWriter.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
18{
19 public static $CONTENT_ATTACH_NO = 0;
20 public static $CONTENT_ATTACH_ENCODED = 1;
23
24 public static $STATUS_NOT_GRADED = "NOT_GRADED";
25 public static $STATUS_PASSED = "PASSED";
26 public static $STATUS_FAILED = "FAILED";
33
40
46 public $exercise;
47
55 public function __construct()
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 }
62
69 public function setExercise($exercise)
70 {
71 $this->exercise = $exercise;
72 }
73
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 }
91
92 public function start()
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 }
134
135 public function getXML()
136 {
137 return $this->xmlDumpMem(false);
138 }
139
140 public function __buildHeader()
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 }
148
149 public function __buildFooter()
150 {
151 }
152
158 public function setAttachMembers($value)
159 {
160 $this->attachMembers = $value ? true : false;
161 }
162
169 private function attachMarking($user_id, $assignment_id)
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 }
193
194 private function handleAssignmentFiles($ex_id, $as_id)
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 }
225
232 private function handleAssignmentMembers($ex_id, $assignment_id)
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 }
251}
$filename
Definition: buildRTE.php:89
An exception for terminatinating execution or to throw for unit testing.
Exercise assignment.
static getAssignmentDataOfExercise($a_exc_id)
Get assignments data of an exercise in an array.
Exercise exceptions class.
static _getMembers($a_obj_id)
setExercise($exercise)
set exercise object
attachMarking($user_id, $assignment_id)
attach marking tag to member for given assignment
setAttachFileContents($attachFileContents)
set attachment content mode
setAttachMembers($value)
write access to property attchMarkings
handleAssignmentMembers($ex_id, $assignment_id)
create xml for files per assignment
static _lookupName($a_user_id)
lookup user name
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlDumpMem($format=true)
Returns xml document from memory.
xmlHeader()
Writes xml header @access public.
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.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc