ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.assFormulaQuestionExport.php
Go to the documentation of this file.
1<?php
18include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
19
30{
36 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
37 {
38 global $DIC;
39 $ilias = $DIC['ilias'];
40
41 include_once 'Services/Xml/classes/class.ilXmlWriter.php';
42 $a_xml_writer = new ilXmlWriter();
43 // set xml header
44 $a_xml_writer->xmlHeader();
45 $a_xml_writer->xmlStartTag("questestinterop");
46 $attrs = array(
47 "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
48 "title" => $this->object->getTitle()
49 );
50 $a_xml_writer->xmlStartTag("item", $attrs);
51 // add question description
52 $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
53 $a_xml_writer->xmlStartTag("itemmetadata");
54 $a_xml_writer->xmlStartTag("qtimetadata");
55 $a_xml_writer->xmlStartTag("qtimetadatafield");
56 $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
57 $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
58 $a_xml_writer->xmlEndTag("qtimetadatafield");
59 $a_xml_writer->xmlStartTag("qtimetadatafield");
60 $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
61 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getQuestionType());
62 $a_xml_writer->xmlEndTag("qtimetadatafield");
63 $a_xml_writer->xmlStartTag("qtimetadatafield");
64 $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
65 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
66 $a_xml_writer->xmlEndTag("qtimetadatafield");
67 $a_xml_writer->xmlStartTag("qtimetadatafield");
68 $a_xml_writer->xmlElement("fieldlabel", null, "points");
69 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getPoints());
70 $a_xml_writer->xmlEndTag("qtimetadatafield");
71 foreach ($this->object->getVariables() as $variable) {
72 $var = array(
73 "precision" => $variable->getPrecision(),
74 "intprecision" => $variable->getIntprecision(),
75 "rangemin" => $variable->getRangeMin(),
76 "rangemax" => $variable->getRangeMax(),
77 "unit" => (is_object($variable->getUnit())) ? $variable->getUnit()->getUnit() : "",
78 "unitvalue" => (is_object($variable->getUnit())) ? $variable->getUnit()->getId() : ""
79 );
80 $a_xml_writer->xmlStartTag("qtimetadatafield");
81 $a_xml_writer->xmlElement("fieldlabel", null, $variable->getVariable());
82 $a_xml_writer->xmlElement("fieldentry", null, serialize($var));
83 $a_xml_writer->xmlEndTag("qtimetadatafield");
84 }
85 foreach ($this->object->getResults() as $result) {
86 $resultunits = $this->object->getResultUnits($result);
87 $ru = array();
88 foreach ($resultunits as $unit) {
89 array_push($ru, array("unit" => $unit->getUnit(), "unitvalue" => $unit->getId()));
90 }
91 $res = array(
92 "precision" => $result->getPrecision(),
93 "tolerance" => $result->getTolerance(),
94 "rangemin" => $result->getRangeMin(),
95 "rangemax" => $result->getRangeMax(),
96 "points" => $result->getPoints(),
97 "formula" => $result->getFormula(),
98 "rating" => ($result->getRatingSimple()) ? "" : array("sign" => $result->getRatingSign(), "value" => $result->getRatingValue(), "unit" => $result->getRatingUnit()),
99 "unit" => (is_object($result->getUnit())) ? $result->getUnit()->getUnit() : "",
100 "unitvalue" => (is_object($result->getUnit())) ? $result->getUnit()->getId() : "",
101 "resultunits" => $ru,
102 "resulttype" => $result->getResultType()
103 );
104 $a_xml_writer->xmlStartTag("qtimetadatafield");
105 $a_xml_writer->xmlElement("fieldlabel", null, $result->getResult());
106 $a_xml_writer->xmlElement("fieldentry", null, serialize($res));
107 $a_xml_writer->xmlEndTag("qtimetadatafield");
108 }
109
110 // additional content editing information
111 $this->addAdditionalContentEditingModeInformation($a_xml_writer);
112 $this->addGeneralMetadata($a_xml_writer);
113
114 $a_xml_writer->xmlEndTag("qtimetadata");
115 $a_xml_writer->xmlEndTag("itemmetadata");
116
117 // PART I: qti presentation
118 $attrs = array(
119 "label" => $this->object->getTitle()
120 );
121 $a_xml_writer->xmlStartTag("presentation", $attrs);
122 // add flow to presentation
123 $a_xml_writer->xmlStartTag("flow");
124 // add material with question text to presentation
125 $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
126 // add answers to presentation
127 $a_xml_writer->xmlEndTag("flow");
128 $a_xml_writer->xmlEndTag("presentation");
129
130 $this->addGenericFeedback($a_xml_writer);
131
132 $a_xml_writer = $this->addSolutionHints($a_xml_writer);
133
134 $a_xml_writer->xmlEndTag("item");
135 $a_xml_writer->xmlEndTag("questestinterop");
136
137 $xml = $a_xml_writer->xmlDumpMem(false);
138 if (!$a_include_header) {
139 $pos = strpos($xml, "?>");
140 $xml = substr($xml, $pos + 2);
141 }
142 return $xml;
143 }
144}
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...
addGeneralMetadata(ilXmlWriter $xmlwriter)
addGenericFeedback(ilXmlWriter $a_xml_writer)
addSolutionHints(ilXmlWriter $writer)
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
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
$res
Definition: ltiservices.php:69
$xml
Definition: metadata.php:351