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