ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.assLongMenuExport.php
Go to the documentation of this file.
1<?php
2require_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 $ilias;
13
14 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
15 $xml = new ilXmlWriter;
16 // set xml header
17 $xml->xmlHeader();
18 $attrs = array(
19 'xmlns' => "http://www.imsglobal.org/xsd/imsqti_v2p1",
20 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
21 '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',
22 "identifier" => "il_".IL_INST_ID."_qst_".$this->object->getId(),
23 "title" => $this->object->getTitle(),
24 //"maxattempts" => $this->object->getNrOfTries(),
25 'adaptive' => 'false',
26 'timeDependent' => 'false'
27 );
28 $xml->xmlStartTag("assessmentItem", $attrs, false, true, false);
29 // add question description
30 $correct_answers = $this->object->getCorrectAnswers();
31 $answers = $this->object->getAnswers();
32 $a = 0;
33 $inlineChoice = array();
34 foreach($answers as $key => $values)
35 {
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 {
56
57 $points = 0;
58 if(in_array($value, $correct_answers[$key][0]))
59 {
60 $points = $correct_answers[$key][1];
61 }
62 $attrs = array(
63 "mapKey" => $value,
64 "mappedValue" => $points
65 );
66 $inlineChoiceString .= '<inlineChoice identifier="'.$value.'" fixed="false" showHide="show">'.$value.'</inlineChoice>';
67 $xml->xmlElement("mapEntry", $attrs);
68 }
69 $xml->xmlEndTag("mapping");
70 $xml->xmlEndTag("responseDeclaration");
71 $inlineChoiceString .= '</inlineChoiceInteraction>';
72 $inlineChoice[$real_id] = $inlineChoiceString;
73 }
74 $attrs = array(
75 "identifier" => "SCORE",
76 "cardinality" => "single",
77 "baseType" => "float"
78 );
79 $xml->xmlStartTag("outcomeDeclaration", $attrs);
80 $xml->xmlStartTag("defaultValue");
81 $xml->xmlElement("value", NULL, 0);
82 $xml->xmlEndTag("defaultValue");
83 $xml->xmlEndTag("outcomeDeclaration");
84
85 $attrs = array(
86 "identifier" => "MAXSCORE",
87 "cardinality" => "single",
88 "baseType" => "float"
89 );
90 $xml->xmlStartTag("outcomeDeclaration", $attrs);
91 $xml->xmlStartTag("defaultValue");
92 $xml->xmlElement("value", NULL, $this->object->getMaximumPoints());
93 $xml->xmlEndTag("defaultValue");
94 $xml->xmlEndTag("outcomeDeclaration");
95
96 $attrs = array(
97 "identifier" => "FEEDBACKBASIC",
98 "cardinality" => "single",
99 "baseType" => "identifier",
100 "view" => "testConstructor"
101 );
102
103 $xml->xmlStartTag("outcomeDeclaration", $attrs);
104 $xml->xmlStartTag("defaultValue");
105 $xml->xmlElement("value", NULL, "TODO IMPLEMENT FEEDBACK");
106 $xml->xmlEndTag("defaultValue");
107 $xml->xmlEndTag("outcomeDeclaration");
108
109 $longmenu_text = $this->object->getLongMenuTextValue();
110
111 for($i = 1; $i <= sizeof($answers); $i++ )
112 {
113 $longmenu_text = preg_replace("/\\[".assLongMenu::GAP_PLACEHOLDER." ".$i."]/", $inlineChoice[$i], $longmenu_text);
114 }
115 $longmenu_text = $this->object->getQuestion() . $longmenu_text;
116 $xml->xmlStartTag("itemBody", $attrs);
117 $xml->xmlElement("div", NULL, $longmenu_text, true, false);
118 $xml->xmlEndTag("itemBody");
119
120 $xml->xmlStartTag("responseProcessing");
121 foreach($answers as $key => $values)
122 {
123 $xml->xmlStartTag("responseCondition");
124 $xml->xmlStartTag("responseIf");
125 $xml->xmlStartTag("not");
126 $xml->xmlStartTag("isNull");
127 $xml->xmlElement("variable", array("identifier" => 'LONGMENU_'. ($key + 1) ));
128 $xml->xmlEndTag("isNull");
129 $xml->xmlEndTag("not");
130 $xml->xmlStartTag("setOutcomeValue", array("identifier" => 'SCORE'));
131 $xml->xmlStartTag("sum");
132 $xml->xmlElement("variable", array("identifier" => 'SCORE'));
133 $xml->xmlElement("mapResponse", array("identifier" => 'LONGMENU_'. ($key + 1) ));
134 $xml->xmlEndTag("sum");
135 $xml->xmlEndTag("setOutcomeValue");
136 $xml->xmlStartTag("setOutcomeValue", array("identifier" => 'FEEDBACKBASIC'));
137 $xml->xmlElement("value", array('baseType' => 'identifier'), "incorrect");
138 $xml->xmlEndTag("setOutcomeValue");
139 $xml->xmlEndTag("responseIf");
140 $xml->xmlEndTag("responseCondition");
141 }
142 $xml->xmlEndTag("responseProcessing");
143 $xml->xmlEndTag("assessmentItem");
144 $xml = $xml->xmlDumpMem(FALSE);
145 if (!$a_include_header)
146 {
147 $pos = strpos($xml, "?>");
148 $xml = substr($xml, $pos + 2);
149 }
150 return $xml;
151 }
152}
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.
Class for question exports.
XML writer class.
xmlHeader()
Writes xml header @access public.