ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assLongMenuExportQti21.php
Go to the documentation of this file.
1 <?php
2 require_once 'Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php';
4 {
8  public $object;
9 
10  public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
11  {
12  global $DIC;
13  $ilias = $DIC['ilias'];
14 
15  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
16  $xml = new ilXmlWriter;
17  // set xml header
18  $xml->xmlHeader();
19  $attrs = array(
20  'xmlns' => "http://www.imsglobal.org/xsd/imsqti_v2p1",
21  'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
22  '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',
23  "identifier" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
24  "title" => $this->object->getTitle(),
25  //"maxattempts" => $this->object->getNrOfTries(),
26  'adaptive' => 'false',
27  'timeDependent' => 'false'
28  );
29  $xml->xmlStartTag("assessmentItem", $attrs, false, true, false);
30  // add question description
31  $correct_answers = $this->object->getCorrectAnswers();
32  $answers = $this->object->getAnswers();
33  $a = 0;
34  $inlineChoice = array();
35  foreach ($answers as $key => $values) {
36  $real_id = $key + 1;
37  $inlineChoiceString = '<inlineChoiceInteraction responseIdentifier="LONGMENU_' . $real_id . '" shuffle="false" required="false">';
38  $attrs = array(
39  "identifier" => "LONGMENU_" . $real_id,
40  "cardinality" => "single",
41  "baseType" => "identifier"
42  );
43  $xml->xmlStartTag("responseDeclaration", $attrs);
44  $xml->xmlStartTag("correctResponse");
45  $xml->xmlElement("value", null, $correct_answers[$key][0][0]);
46  $xml->xmlEndTag("correctResponse");
47  $attrs = array(
48  "defaultValue" => "0",
49  "lowerBound" => "0",
50  "upperBound" => $correct_answers[$key][1]
51  );
52  $xml->xmlStartTag("mapping", $attrs);
53 
54  foreach ($values as $index => $value) {
55  $points = 0;
56  if (in_array($value, $correct_answers[$key][0])) {
57  $points = $correct_answers[$key][1];
58  }
59  $attrs = array(
60  "mapKey" => $value,
61  "mappedValue" => $points
62  );
63  $inlineChoiceString .= '<inlineChoice identifier="' . $value . '" fixed="false" showHide="show">' . $value . '</inlineChoice>';
64  $xml->xmlElement("mapEntry", $attrs);
65  }
66  $xml->xmlEndTag("mapping");
67  $xml->xmlEndTag("responseDeclaration");
68  $inlineChoiceString .= '</inlineChoiceInteraction>';
69  $inlineChoice[$real_id] = $inlineChoiceString;
70  }
71  $attrs = array(
72  "identifier" => "SCORE",
73  "cardinality" => "single",
74  "baseType" => "float"
75  );
76  $xml->xmlStartTag("outcomeDeclaration", $attrs);
77  $xml->xmlStartTag("defaultValue");
78  $xml->xmlElement("value", null, 0);
79  $xml->xmlEndTag("defaultValue");
80  $xml->xmlEndTag("outcomeDeclaration");
81 
82  $attrs = array(
83  "identifier" => "MAXSCORE",
84  "cardinality" => "single",
85  "baseType" => "float"
86  );
87  $xml->xmlStartTag("outcomeDeclaration", $attrs);
88  $xml->xmlStartTag("defaultValue");
89  $xml->xmlElement("value", null, $this->object->getMaximumPoints());
90  $xml->xmlEndTag("defaultValue");
91  $xml->xmlEndTag("outcomeDeclaration");
92 
93  $attrs = array(
94  "identifier" => "FEEDBACKBASIC",
95  "cardinality" => "single",
96  "baseType" => "identifier",
97  "view" => "testConstructor"
98  );
99 
100  $xml->xmlStartTag("outcomeDeclaration", $attrs);
101  $xml->xmlStartTag("defaultValue");
102  $xml->xmlElement("value", null, "TODO IMPLEMENT FEEDBACK");
103  $xml->xmlEndTag("defaultValue");
104  $xml->xmlEndTag("outcomeDeclaration");
105 
106  $longmenu_text = $this->object->getLongMenuTextValue();
107 
108  for ($i = 1; $i <= sizeof($answers); $i++) {
109  $longmenu_text = preg_replace("/\\[" . assLongMenu::GAP_PLACEHOLDER . " " . $i . "]/", $inlineChoice[$i], $longmenu_text);
110  }
111  $longmenu_text = $this->object->getQuestion() . $longmenu_text;
112  $xml->xmlStartTag("itemBody", $attrs);
113  $xml->xmlElement("div", null, $longmenu_text, true, false);
114  $xml->xmlEndTag("itemBody");
115 
116  $xml->xmlStartTag("responseProcessing");
117  foreach ($answers as $key => $values) {
118  $xml->xmlStartTag("responseCondition");
119  $xml->xmlStartTag("responseIf");
120  $xml->xmlStartTag("not");
121  $xml->xmlStartTag("isNull");
122  $xml->xmlElement("variable", array("identifier" => 'LONGMENU_' . ($key + 1) ));
123  $xml->xmlEndTag("isNull");
124  $xml->xmlEndTag("not");
125  $xml->xmlStartTag("setOutcomeValue", array("identifier" => 'SCORE'));
126  $xml->xmlStartTag("sum");
127  $xml->xmlElement("variable", array("identifier" => 'SCORE'));
128  $xml->xmlElement("mapResponse", array("identifier" => 'LONGMENU_' . ($key + 1) ));
129  $xml->xmlEndTag("sum");
130  $xml->xmlEndTag("setOutcomeValue");
131  $xml->xmlStartTag("setOutcomeValue", array("identifier" => 'FEEDBACKBASIC'));
132  $xml->xmlElement("value", array('baseType' => 'identifier'), "incorrect");
133  $xml->xmlEndTag("setOutcomeValue");
134  $xml->xmlEndTag("responseIf");
135  $xml->xmlEndTag("responseCondition");
136  }
137  $xml->xmlEndTag("responseProcessing");
138  $xml->xmlEndTag("assessmentItem");
139  $xml = $xml->xmlDumpMem(false);
140  if (!$a_include_header) {
141  $pos = strpos($xml, "?>");
142  $xml = substr($xml, $pos + 2);
143  }
144  return $xml;
145  }
146 }
global $DIC
Definition: saml.php:7
XML writer class.
Class for question exports.
$index
Definition: metadata.php:60
toXML($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false)
$values
$i
Definition: disco.tpl.php:19
$key
Definition: croninfo.php:18