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