ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilExerciseXMLWriter.php
Go to the documentation of this file.
1<?php
2
29{
30 public static int $CONTENT_ATTACH_NO = 0;
31 public static int $CONTENT_ATTACH_ENCODED = 1;
32 public static int $CONTENT_ATTACH_ZLIB_ENCODED = 2;
33 public static int $CONTENT_ATTACH_GZIP_ENCODED = 3;
34
35 public static string $STATUS_NOT_GRADED = "NOT_GRADED";
36 public static string $STATUS_PASSED = "PASSED";
37 public static string $STATUS_FAILED = "FAILED";
38
39 public bool $attachFileContents; // if true, file contents will be attached as base64
40 public bool $attachMembers; // if true, members will be attach to xml
42
43 public function __construct()
44 {
45 // @todo: needs to be revised for multiple assignments per exercise
46 //die ("Needs revision for ILIAS 4.1");
48 $this->attachFileContents = ilExerciseXMLWriter::$CONTENT_ATTACH_NO;
49 }
50
51 public function setExercise(ilObjExercise $exercise): void
52 {
53 $this->exercise = $exercise;
54 }
55
60 public function setAttachFileContents(int $attachFileContents): void
61 {
62 if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode")) {
63 throw new ilExerciseException("Inflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
64 }
65 if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress")) {
66 throw new ilExerciseException("Inflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
67 }
68
69 $this->attachFileContents = $attachFileContents;
70 }
71
72 public function start(): bool
73 {
74 $this->__buildHeader();
75
76 $attribs = array("obj_id" => "il_" . IL_INST_ID . "_exc_" . $this->exercise->getId() );
77
78 if ($this->exercise->getOwner() !== 0) {
79 $attribs ["owner"] = "il_" . IL_INST_ID . "_usr_" . $this->exercise->getOwner();
80 }
81
82 $this->xmlStartTag("Exercise", $attribs);
83
84 //todo: create new dtd for new assignment structure
85 $this->xmlElement("Title", null, $this->exercise->getTitle());
86 $this->xmlElement("Description", null, $this->exercise->getDescription());
87 //$this->xmlElement("Instruction", null,$this->exercise->getInstruction());
88 //$this->xmlElement("DueDate", null,$this->exercise->getTimestamp());
89
90
91 //todo: as a workaround use first assignment for compatibility with old exercise dtd
92 $assignments = ilExAssignment::getAssignmentDataOfExercise($this->exercise->getId());
93
94 if (count($assignments) > 0) {
95 foreach ($assignments as $assignment) {
96 $this->xmlStartTag("Assignment");
97 $this->xmlElement("Instruction", null, $assignment ["instruction"]);
98 $this->xmlElement("DueDate", null, $assignment ["deadline"]);
99
100 $this->handleAssignmentFiles($this->exercise->getId(), $assignment ["id"]);
101 if ($this->attachMembers) {
102 $this->handleAssignmentMembers($this->exercise->getId(), $assignment ["id"]);
103 }
104 $this->xmlEndTag("Assignment");
105 }
106 }
107
108
109 $this->xmlEndTag("Exercise");
110 $this->__buildFooter();
111
112 return true;
113 }
114
115 public function getXML(): string
116 {
117 return $this->xmlDumpMem(false);
118 }
119
120 public function __buildHeader(): bool
121 {
122 $this->xmlSetGenCmt("Exercise Object");
123 $this->xmlHeader();
124
125 return true;
126 }
127
128 public function __buildFooter(): void
129 {
130 }
131
135 public function setAttachMembers(bool $value): void
136 {
137 $this->attachMembers = $value;
138 }
139
143 private function attachMarking(
144 int $user_id,
145 int $assignment_id
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 }
169
170 private function handleAssignmentFiles(
171 int $ex_id,
172 int $as_id
173 ): void {
174 }
175
179 private function handleAssignmentMembers(
180 int $ex_id,
181 int $assignment_id
182 ): void {
183 $this->xmlStartTag("Members");
184 $members = ilExerciseMembers::_getMembers($ex_id);
185 if (count($members)) {
186 foreach ($members as $member_id) {
187 $this->xmlStartTag("Member", array("usr_id" => "il_" . IL_INST_ID . "_usr_" . $member_id ));
188
189 $name = ilObjUser::_lookupName($member_id);
190
191 $this->xmlElement("Firstname", array(), $name['firstname']);
192 $this->xmlElement("Lastname", array(), $name['lastname']);
193 $this->xmlElement("Login", array(), $name['login']);
194 $this->attachMarking($member_id, $assignment_id);
195 $this->xmlEndTag("Member");
196 }
197 }
198 $this->xmlEndTag("Members");
199 }
200}
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