ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.assLongMenuExportQti21.php
Go to the documentation of this file.
1<?php
2
20{
24 public $object;
25
26 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
27 {
28 global $DIC;
29 $ilias = $DIC['ilias'];
30
31 $xml = new ilXmlWriter();
32 // set xml header
33 $xml->xmlHeader();
34 $attrs = [
35 'xmlns' => "http://www.imsglobal.org/xsd/imsqti_v2p1",
36 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
37 'xsi:schemaLocation' => 'http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1p1.xsd http://www.w3.org/1998/Math/MathML http://www.w3.org/Math/XMLSchema/mathml2/mathml2.xsd',
38 "identifier" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
39 "title" => $this->object->getTitle(),
40 //"maxattempts" => $this->object->getNrOfTries(),
41 'adaptive' => 'false',
42 'timeDependent' => 'false'
43 ];
44 $xml->xmlStartTag("assessmentItem", $attrs, false, true, false);
45 // add question description
46 $correct_answers = $this->object->getCorrectAnswers();
47 $answers = $this->object->getAnswers();
48 $a = 0;
49 $inlineChoice = [];
50 foreach ($answers as $key => $values) {
51 $real_id = $key + 1;
52 $inlineChoiceString = '<inlineChoiceInteraction responseIdentifier="LONGMENU_' . $real_id . '" shuffle="false" required="false">';
53 $attrs = [
54 "identifier" => "LONGMENU_" . $real_id,
55 "cardinality" => "single",
56 "baseType" => "identifier"
57 ];
58 $xml->xmlStartTag("responseDeclaration", $attrs);
59 $xml->xmlStartTag("correctResponse");
60 $xml->xmlElement("value", null, $correct_answers[$key][0][0]);
61 $xml->xmlEndTag("correctResponse");
62 $attrs = [
63 "defaultValue" => "0",
64 "lowerBound" => "0",
65 "upperBound" => $correct_answers[$key][1]
66 ];
67 $xml->xmlStartTag("mapping", $attrs);
68
69 foreach ($values as $index => $value) {
70 $points = 0;
71 if (in_array($value, $correct_answers[$key][0])) {
72 $points = $correct_answers[$key][1];
73 }
74 $attrs = [
75 "mapKey" => $value,
76 "mappedValue" => $points
77 ];
78 $inlineChoiceString .= '<inlineChoice identifier="' . $value . '" fixed="false" showHide="show">' . $value . '</inlineChoice>';
79 $xml->xmlElement("mapEntry", $attrs);
80 }
81 $xml->xmlEndTag("mapping");
82 $xml->xmlEndTag("responseDeclaration");
83 $inlineChoiceString .= '</inlineChoiceInteraction>';
84 $inlineChoice[$real_id] = $inlineChoiceString;
85 }
86 $attrs = [
87 "identifier" => "SCORE",
88 "cardinality" => "single",
89 "baseType" => "float"
90 ];
91 $xml->xmlStartTag("outcomeDeclaration", $attrs);
92 $xml->xmlStartTag("defaultValue");
93 $xml->xmlElement("value", null, 0);
94 $xml->xmlEndTag("defaultValue");
95 $xml->xmlEndTag("outcomeDeclaration");
96
97 $attrs = [
98 "identifier" => "MAXSCORE",
99 "cardinality" => "single",
100 "baseType" => "float"
101 ];
102 $xml->xmlStartTag("outcomeDeclaration", $attrs);
103 $xml->xmlStartTag("defaultValue");
104 $xml->xmlElement("value", null, $this->object->getMaximumPoints());
105 $xml->xmlEndTag("defaultValue");
106 $xml->xmlEndTag("outcomeDeclaration");
107
108 $attrs = [
109 "identifier" => "FEEDBACKBASIC",
110 "cardinality" => "single",
111 "baseType" => "identifier",
112 "view" => "testConstructor"
113 ];
114
115 $xml->xmlStartTag("outcomeDeclaration", $attrs);
116 $xml->xmlStartTag("defaultValue");
117 $xml->xmlElement("value", null, "TODO IMPLEMENT FEEDBACK");
118 $xml->xmlEndTag("defaultValue");
119 $xml->xmlEndTag("outcomeDeclaration");
120
121 $longmenu_text = $this->object->getLongMenuTextValue();
122
123 for ($i = 1; $i <= sizeof($answers); $i++) {
124 $longmenu_text = preg_replace("/\\[" . assLongMenu::GAP_PLACEHOLDER . " " . $i . "]/", $inlineChoice[$i], $longmenu_text);
125 }
126 $longmenu_text = $this->object->getQuestion() . $longmenu_text;
127 $xml->xmlStartTag("itemBody", $attrs);
128 $xml->xmlElement("div", null, $longmenu_text, true, false);
129 $xml->xmlEndTag("itemBody");
130
131 $xml->xmlStartTag("responseProcessing");
132 foreach ($answers as $key => $values) {
133 $xml->xmlStartTag("responseCondition");
134 $xml->xmlStartTag("responseIf");
135 $xml->xmlStartTag("not");
136 $xml->xmlStartTag("isNull");
137 $xml->xmlElement("variable", ["identifier" => 'LONGMENU_' . ($key + 1) ]);
138 $xml->xmlEndTag("isNull");
139 $xml->xmlEndTag("not");
140 $xml->xmlStartTag("setOutcomeValue", ["identifier" => 'SCORE']);
141 $xml->xmlStartTag("sum");
142 $xml->xmlElement("variable", ["identifier" => 'SCORE']);
143 $xml->xmlElement("mapResponse", ["identifier" => 'LONGMENU_' . ($key + 1) ]);
144 $xml->xmlEndTag("sum");
145 $xml->xmlEndTag("setOutcomeValue");
146 $xml->xmlStartTag("setOutcomeValue", ["identifier" => 'FEEDBACKBASIC']);
147 $xml->xmlElement("value", ['baseType' => 'identifier'], "incorrect");
148 $xml->xmlEndTag("setOutcomeValue");
149 $xml->xmlEndTag("responseIf");
150 $xml->xmlEndTag("responseCondition");
151 }
152 $xml->xmlEndTag("responseProcessing");
153 $xml->xmlEndTag("assessmentItem");
154 $xml = $xml->xmlDumpMem(false);
155 if (!$a_include_header) {
156 $pos = strpos($xml, "?>");
157 $xml = substr($xml, $pos + 2);
158 }
159 return $xml;
160 }
161}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
Class for question exports.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_INST_ID
Definition: constants.php:40
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26