ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.assFormulaQuestionExport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
5
16{
26 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
27 {
28 global $ilias;
29
30 include_once 'Services/Xml/classes/class.ilXmlWriter.php';
31 $a_xml_writer = new ilXmlWriter;
32 // set xml header
33 $a_xml_writer->xmlHeader();
34 $a_xml_writer->xmlStartTag("questestinterop");
35 $attrs = array(
36 "ident" => "il_".IL_INST_ID."_qst_".$this->object->getId(),
37 "title" => $this->object->getTitle()
38 );
39 $a_xml_writer->xmlStartTag("item", $attrs);
40 // add question description
41 $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
42 // add estimated working time
43 $workingtime = $this->object->getEstimatedWorkingTime();
44 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
45 $a_xml_writer->xmlElement("duration", NULL, $duration);
46 // add ILIAS specific metadata
47 $a_xml_writer->xmlStartTag("itemmetadata");
48 $a_xml_writer->xmlStartTag("qtimetadata");
49 $a_xml_writer->xmlStartTag("qtimetadatafield");
50 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
51 $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
52 $a_xml_writer->xmlEndTag("qtimetadatafield");
53 $a_xml_writer->xmlStartTag("qtimetadatafield");
54 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
55 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getQuestionType());
56 $a_xml_writer->xmlEndTag("qtimetadatafield");
57 $a_xml_writer->xmlStartTag("qtimetadatafield");
58 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
59 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
60 $a_xml_writer->xmlEndTag("qtimetadatafield");
61 $a_xml_writer->xmlStartTag("qtimetadatafield");
62 $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
63 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
64 $a_xml_writer->xmlEndTag("qtimetadatafield");
65 foreach ($this->object->getVariables() as $variable)
66 {
67 $var = array(
68 "precision" => $variable->getPrecision(),
69 "intprecision" => $variable->getIntprecision(),
70 "rangemin" => $variable->getRangeMin(),
71 "rangemax" => $variable->getRangeMax(),
72 "unit" => (is_object($variable->getUnit())) ? $variable->getUnit()->getUnit() : "",
73 "unitvalue" => (is_object($variable->getUnit())) ? $variable->getUnit()->getId() : ""
74 );
75 $a_xml_writer->xmlStartTag("qtimetadatafield");
76 $a_xml_writer->xmlElement("fieldlabel", NULL, $variable->getVariable());
77 $a_xml_writer->xmlElement("fieldentry", NULL, serialize($var));
78 $a_xml_writer->xmlEndTag("qtimetadatafield");
79 }
80 foreach ($this->object->getResults() as $result)
81 {
82 $resultunits = $this->object->getResultUnits($result);
83 $ru = array();
84 foreach ($resultunits as $unit)
85 {
86 array_push($ru, array("unit" => $unit->getUnit(), "unitvalue" => $unit->getId()));
87 }
88 $res = array(
89 "precision" => $result->getPrecision(),
90 "tolerance" => $result->getTolerance(),
91 "rangemin" => $result->getRangeMin(),
92 "rangemax" => $result->getRangeMax(),
93 "points" => $result->getPoints(),
94 "formula" => $result->getFormula(),
95 "rating" => ($result->getRatingSimple()) ? "" : array("sign" => $result->getRatingSign(), "value" => $result->getRatingValue(), "unit" => $result->getRatingUnit()),
96 "unit" => (is_object($result->getUnit())) ? $result->getUnit()->getUnit() : "",
97 "unitvalue" => (is_object($result->getUnit())) ? $result->getUnit()->getId() : "",
98 "resultunits" => $ru
99 );
100 $a_xml_writer->xmlStartTag("qtimetadatafield");
101 $a_xml_writer->xmlElement("fieldlabel", NULL, $result->getResult());
102 $a_xml_writer->xmlElement("fieldentry", NULL, serialize($res));
103 $a_xml_writer->xmlEndTag("qtimetadatafield");
104 }
105
106 // additional content editing information
107 $this->addAdditionalContentEditingModeInformation($a_xml_writer);
108 $this->addGeneralMetadata($a_xml_writer);
109
110 $a_xml_writer->xmlEndTag("qtimetadata");
111 $a_xml_writer->xmlEndTag("itemmetadata");
112
113 // PART I: qti presentation
114 $attrs = array(
115 "label" => $this->object->getTitle()
116 );
117 $a_xml_writer->xmlStartTag("presentation", $attrs);
118 // add flow to presentation
119 $a_xml_writer->xmlStartTag("flow");
120 // add material with question text to presentation
121 $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
122 // add answers to presentation
123 $a_xml_writer->xmlEndTag("flow");
124 $a_xml_writer->xmlEndTag("presentation");
125
126 $a_xml_writer->xmlEndTag("item");
127 $a_xml_writer->xmlEndTag("questestinterop");
128
129 $xml = $a_xml_writer->xmlDumpMem(FALSE);
130 if (!$a_include_header)
131 {
132 $pos = strpos($xml, "?>");
133 $xml = substr($xml, $pos + 2);
134 }
135 return $xml;
136 }
137
138}
139
140?>
$result
Class for formula question question exports.
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.
addGeneralMetadata(ilXmlWriter $xmlwriter)
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
XML writer class.
xmlHeader()
Writes xml header @access public.