ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExerciseXMLWriter.php
Go to the documentation of this file.
1<?php
28{
29 public static int $CONTENT_ATTACH_NO = 0;
30 public static int $CONTENT_ATTACH_ENCODED = 1;
31 public static int $CONTENT_ATTACH_ZLIB_ENCODED = 2;
32 public static int $CONTENT_ATTACH_GZIP_ENCODED = 3;
33
34 public static string $STATUS_NOT_GRADED = "NOT_GRADED";
35 public static string $STATUS_PASSED = "PASSED";
36 public static string $STATUS_FAILED = "FAILED";
37
38 public bool $attachFileContents; // if true, file contents will be attached as base64
39 public bool $attachMembers; // if true, members will be attach to xml
41
42 public function __construct()
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 }
49
50 public function setExercise(ilObjExercise $exercise): void
51 {
52 $this->exercise = $exercise;
53 }
54
59 public function setAttachFileContents(int $attachFileContents): 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 }
70
71 public function start(): 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 }
113
114 public function getXML(): string
115 {
116 return $this->xmlDumpMem(false);
117 }
118
119 public function __buildHeader(): bool
120 {
121 $this->xmlSetGenCmt("Exercise Object");
122 $this->xmlHeader();
123
124 return true;
125 }
126
127 public function __buildFooter(): void
128 {
129 }
130
134 public function setAttachMembers(bool $value): void
135 {
136 $this->attachMembers = $value;
137 }
138
142 private function attachMarking(
143 int $user_id,
144 int $assignment_id
145 ): void {
146 $ass = new ilExAssignment($assignment_id);
147
148 $amark = $ass->getMemberStatus($user_id)->getMark();
149 $astatus = $ass->getMemberStatus($user_id)->getStatus();
150 $acomment = $ass->getMemberStatus($user_id)->getComment();
151 $anotice = $ass->getMemberStatus($user_id)->getNotice();
152
153
154 if ($astatus == "notgraded") {
156 } elseif ($astatus == "failed") {
158 } else {
160 }
161
162 $this->xmlStartTag("Marking", array("status" => $status ));
163 $this->xmlElement("Mark", null, $amark);
164 $this->xmlElement("Notice", null, $anotice);
165 $this->xmlElement("Comment", null, $acomment);
166 $this->xmlEndTag("Marking");
167 }
168
169 private function handleAssignmentFiles(
170 int $ex_id,
171 int $as_id
172 ): void {
173 }
174
178 private function handleAssignmentMembers(
179 int $ex_id,
180 int $assignment_id
181 ): void {
182 $this->xmlStartTag("Members");
183 $members = ilExerciseMembers::_getMembers($ex_id);
184 if (count($members)) {
185 foreach ($members as $member_id) {
186 $this->xmlStartTag("Member", array("usr_id" => "il_" . IL_INST_ID . "_usr_" . $member_id ));
187
188 $name = ilObjUser::_lookupName($member_id);
189
190 $this->xmlElement("Firstname", array(), $name['firstname']);
191 $this->xmlElement("Lastname", array(), $name['lastname']);
192 $this->xmlElement("Login", array(), $name['login']);
193 $this->attachMarking($member_id, $assignment_id);
194 $this->xmlEndTag("Member");
195 }
196 }
197 $this->xmlEndTag("Members");
198 }
199}
Exercise assignment.
static getAssignmentDataOfExercise(int $a_exc_id)
getMemberStatus(?int $a_user_id=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getMembers(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
attachMarking(int $user_id, int $assignment_id)
attach marking tag to member for given assignment
setAttachFileContents(int $attachFileContents)
set attachment content mode
handleAssignmentMembers(int $ex_id, int $assignment_id)
create xml for files per assignment
handleAssignmentFiles(int $ex_id, int $as_id)
setAttachMembers(bool $value)
write access to property attchMarkings
setExercise(ilObjExercise $exercise)
Class ilObjExercise.
static _lookupName(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlHeader()
Writes xml header.
xmlEndTag(string $tag)
Writes an endtag.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
const IL_INST_ID
Definition: constants.php:40
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc