ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 public 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 $var = array(
67 "precision" => $variable->getPrecision(),
68 "intprecision" => $variable->getIntprecision(),
69 "rangemin" => $variable->getRangeMin(),
70 "rangemax" => $variable->getRangeMax(),
71 "unit" => (is_object($variable->getUnit())) ? $variable->getUnit()->getUnit() : "",
72 "unitvalue" => (is_object($variable->getUnit())) ? $variable->getUnit()->getId() : ""
73 );
74 $a_xml_writer->xmlStartTag("qtimetadatafield");
75 $a_xml_writer->xmlElement("fieldlabel", null, $variable->getVariable());
76 $a_xml_writer->xmlElement("fieldentry", null, serialize($var));
77 $a_xml_writer->xmlEndTag("qtimetadatafield");
78 }
79 foreach ($this->object->getResults() as $result) {
80 $resultunits = $this->object->getResultUnits($result);
81 $ru = array();
82 foreach ($resultunits as $unit) {
83 array_push($ru, array("unit" => $unit->getUnit(), "unitvalue" => $unit->getId()));
84 }
85 $res = array(
86 "precision" => $result->getPrecision(),
87 "tolerance" => $result->getTolerance(),
88 "rangemin" => $result->getRangeMin(),
89 "rangemax" => $result->getRangeMax(),
90 "points" => $result->getPoints(),
91 "formula" => $result->getFormula(),
92 "rating" => ($result->getRatingSimple()) ? "" : array("sign" => $result->getRatingSign(), "value" => $result->getRatingValue(), "unit" => $result->getRatingUnit()),
93 "unit" => (is_object($result->getUnit())) ? $result->getUnit()->getUnit() : "",
94 "unitvalue" => (is_object($result->getUnit())) ? $result->getUnit()->getId() : "",
95 "resultunits" => $ru
96 );
97 $a_xml_writer->xmlStartTag("qtimetadatafield");
98 $a_xml_writer->xmlElement("fieldlabel", null, $result->getResult());
99 $a_xml_writer->xmlElement("fieldentry", null, serialize($res));
100 $a_xml_writer->xmlEndTag("qtimetadatafield");
101 }
102
103 // additional content editing information
104 $this->addAdditionalContentEditingModeInformation($a_xml_writer);
105 $this->addGeneralMetadata($a_xml_writer);
106
107 $a_xml_writer->xmlEndTag("qtimetadata");
108 $a_xml_writer->xmlEndTag("itemmetadata");
109
110 // PART I: qti presentation
111 $attrs = array(
112 "label" => $this->object->getTitle()
113 );
114 $a_xml_writer->xmlStartTag("presentation", $attrs);
115 // add flow to presentation
116 $a_xml_writer->xmlStartTag("flow");
117 // add material with question text to presentation
118 $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
119 // add answers to presentation
120 $a_xml_writer->xmlEndTag("flow");
121 $a_xml_writer->xmlEndTag("presentation");
122
123 $this->addGenericFeedback($a_xml_writer);
124
125 $a_xml_writer->xmlEndTag("item");
126 $a_xml_writer->xmlEndTag("questestinterop");
127
128 $xml = $a_xml_writer->xmlDumpMem(false);
129 if (!$a_include_header) {
130 $pos = strpos($xml, "?>");
131 $xml = substr($xml, $pos + 2);
132 }
133 return $xml;
134 }
135}
sprintf('%.4f', $callTime)
$result
An exception for terminatinating execution or to throw for unit testing.
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)
addGenericFeedback(ilXmlWriter $a_xml_writer)
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.
$xml
Definition: metadata.php:240
foreach($_POST as $key=> $value) $res