ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.assQuestionExport.php
Go to the documentation of this file.
1<?php
2
20
31{
35 public $object;
36
43 public function __construct($a_object)
44 {
45 $this->object = $a_object;
46 }
47
51 protected function addAnswerSpecificFeedback(ilXmlWriter $a_xml_writer, $answers): void
52 {
53 foreach ($answers as $index => $answer) {
54 $linkrefid = "response_$index";
55 $attrs = [
56 "ident" => $linkrefid,
57 "view" => "All"
58 ];
59 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
60 // qti flow_mat
61 $a_xml_writer->xmlStartTag("flow_mat");
62 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
63 $this->object->getId(),
64 0,
65 $index
66 );
67 $this->addQTIMaterial($a_xml_writer, $fb);
68 $a_xml_writer->xmlEndTag("flow_mat");
69 $a_xml_writer->xmlEndTag("itemfeedback");
70 }
71 }
72
76 protected function addGenericFeedback(ilXmlWriter $a_xml_writer): void
77 {
78 $this->exportFeedbackOnly($a_xml_writer);
79 }
80
81 public function exportFeedbackOnly($a_xml_writer): void
82 {
83 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
84 $this->object->getId(),
85 true
86 );
87 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
88 $this->object->getId(),
89 false
90 );
91 if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
92 $a_xml_writer->xmlStartTag("resprocessing");
93 $a_xml_writer->xmlStartTag("outcomes");
94 $a_xml_writer->xmlStartTag("decvar");
95 $a_xml_writer->xmlEndTag("decvar");
96 $a_xml_writer->xmlEndTag("outcomes");
97
98 if (strlen($feedback_allcorrect)) {
99 $attrs = [
100 "continue" => "Yes"
101 ];
102 $a_xml_writer->xmlStartTag("respcondition", $attrs);
103 // qti conditionvar
104 $a_xml_writer->xmlStartTag("conditionvar");
105 $attrs = [
106 "respident" => "points"
107 ];
108 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
109 $a_xml_writer->xmlEndTag("conditionvar");
110 // qti displayfeedback
111 $attrs = [
112 "feedbacktype" => "Response",
113 "linkrefid" => "response_allcorrect"
114 ];
115 $a_xml_writer->xmlElement("displayfeedback", $attrs);
116 $a_xml_writer->xmlEndTag("respcondition");
117 }
118
119 if (strlen($feedback_onenotcorrect)) {
120 $attrs = [
121 "continue" => "Yes"
122 ];
123 $a_xml_writer->xmlStartTag("respcondition", $attrs);
124 // qti conditionvar
125 $a_xml_writer->xmlStartTag("conditionvar");
126 $a_xml_writer->xmlStartTag("not");
127 $attrs = [
128 "respident" => "points"
129 ];
130 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
131 $a_xml_writer->xmlEndTag("not");
132 $a_xml_writer->xmlEndTag("conditionvar");
133 // qti displayfeedback
134 $attrs = [
135 "feedbacktype" => "Response",
136 "linkrefid" => "response_onenotcorrect"
137 ];
138 $a_xml_writer->xmlElement("displayfeedback", $attrs);
139 $a_xml_writer->xmlEndTag("respcondition");
140 }
141 $a_xml_writer->xmlEndTag("resprocessing");
142 }
143
144 if (strlen($feedback_allcorrect)) {
145 $attrs = [
146 "ident" => "response_allcorrect",
147 "view" => "All"
148 ];
149 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
150 // qti flow_mat
151 $a_xml_writer->xmlStartTag("flow_mat");
152 $this->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
153 $a_xml_writer->xmlEndTag("flow_mat");
154 $a_xml_writer->xmlEndTag("itemfeedback");
155 }
156 if (strlen($feedback_onenotcorrect)) {
157 $attrs = [
158 "ident" => "response_onenotcorrect",
159 "view" => "All"
160 ];
161 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
162 // qti flow_mat
163 $a_xml_writer->xmlStartTag("flow_mat");
164 $this->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
165 $a_xml_writer->xmlEndTag("flow_mat");
166 $a_xml_writer->xmlEndTag("itemfeedback");
167 }
168 }
169
175 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
176 {
177 return '';
178 }
179
190 final protected function addQtiMetaDataField(ilXmlWriter $a_xml_writer, $fieldLabel, $fieldValue): void
191 {
192 $a_xml_writer->xmlStartTag("qtimetadatafield");
193 $a_xml_writer->xmlElement("fieldlabel", null, $fieldLabel);
194 $a_xml_writer->xmlElement("fieldentry", null, $fieldValue);
195 $a_xml_writer->xmlEndTag("qtimetadatafield");
196 }
197
206 final protected function addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer): void
207 {
208 $this->addQtiMetaDataField(
209 $a_xml_writer,
210 'additional_cont_edit_mode',
211 $this->object->getAdditionalContentEditingMode()
212 );
213 }
214
218 protected function addGeneralMetadata(ilXmlWriter $xmlwriter): void
219 {
220 $this->addQtiMetaDataField($xmlwriter, 'externalId', $this->object->getExternalId());
221
222 $this->addQtiMetaDataField(
223 $xmlwriter,
224 'ilias_lifecycle',
225 $this->object->getLifecycle()->getIdentifier()
226 );
227
228 $this->addQtiMetaDataField(
229 $xmlwriter,
230 'lifecycle',
231 $this->object->getLifecycle()->getMappedLomLifecycle()
232 );
233 }
234
235 protected function addSuggestedSolution(ilXmlWriter $writer): ilXmlWriter
236 {
237 $solution = $this->object->getSuggestedSolution();
238 if ($solution === null) {
239 return $writer;
240 }
241
242 $mattext = ['type' => $solution->getType()];
243 $attrs = [
244 'label' => 'suggested_solution',
245 'texttype' => 'application/json'
246 ];
247
248 if ($solution instanceof SuggestedSolutionFile) {
249 $mattext['title'] = $solution->getTitle();
250 $mattext['filename'] = $solution->getFilename();
251 $mattext['value'] = base64_encode(file_get_contents(
252 $this->object->getSuggestedSolutionPath() . $solution->getFilename()
253 ));
254 } else {
255 if (!preg_match('/il_(\d*?)_(\w+)_(\d+)/', $solution->getInternalLink(), $matches)) {
256 return $writer;
257 }
258 $mattext['value'] = 'il_' . IL_INST_ID . '_' . $matches[2] . '_' . $matches[3];
259 if ($matches[1] !== '') {
260 $mattext['value'] = $solution->getInternalLink();
261 }
262
263 }
264
265 $writer->xmlStartTag('material');
266 $writer->xmlElement('mattext', $attrs, json_encode($mattext));
267 $writer->xmlEndTag('material');
268 return $writer;
269 }
270
271 public function addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag = true, bool $add_mobs = true): void
272 {
273 $a_xml_writer->xmlStartTag("material");
274 $attrs = [
275 "texttype" => "text/plain"
276 ];
277 if (ilUtil::isHTML($a_material)) {
278 $attrs["texttype"] = "text/xhtml";
279 }
280 $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
281 if ($add_mobs) {
282 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->object->getId());
283 foreach ($mobs as $mob) {
284 $moblabel = "il_" . IL_INST_ID . "_mob_" . $mob;
285 if (str_contains($a_material, "mm_$mob")) {
286 if (ilObjMediaObject::_exists($mob)) {
287 $mob_obj = new ilObjMediaObject($mob);
288 $imgattrs = [
289 "label" => $moblabel,
290 "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
291 ];
292 }
293 $a_xml_writer->xmlElement("matimage", $imgattrs, null);
294 }
295 }
296 }
297 if ($close_material_tag) {
298 $a_xml_writer->xmlEndTag("material");
299 }
300 }
301}
Class for question exports.
addGeneralMetadata(ilXmlWriter $xmlwriter)
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
addSuggestedSolution(ilXmlWriter $writer)
addQtiMetaDataField(ilXmlWriter $a_xml_writer, $fieldLabel, $fieldValue)
adds a qti meta data field with given name and value to the passed xml writer (xml writer must be in ...
__construct($a_object)
assQuestionExport constructor
addAnswerSpecificFeedback(ilXmlWriter $a_xml_writer, $answers)
addGenericFeedback(ilXmlWriter $a_xml_writer)
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
exportFeedbackOnly($a_xml_writer)
toXML($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false)
Returns a QTI xml representation of the question Returns a QTI xml representation of the question and...
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static isHTML(string $a_text)
Checks if a given string contains HTML or not.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
const IL_INST_ID
Definition: constants.php:40