ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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
72 $unit_repository = $object->getUnitRepository();
73
74 $question_id = $this->object->getId();
75 $unit_categories = array_filter(
76 $unit_repository->getAllUnitCategories(),
77 static fn(object $object): bool => $object->getQuestionFi() === $question_id,
78 );
79
80 $a_xml_writer->xmlStartTag("qtimetadatafield");
81 $a_xml_writer->xmlElement("fieldlabel", null, "unit_categories");
83 foreach ($unit_categories as $unit_category) {
84 $a_xml_writer->xmlElement(
85 "fieldentry",
86 ["id" => $unit_category->getId(), "question_fi" => $unit_category->getQuestionFi()],
87 $unit_category->getCategory()
88 );
89 }
90 $a_xml_writer->xmlEndTag("qtimetadatafield");
91
92 $categorized_units = array_filter(
93 $unit_repository->getCategorizedUnits(),
94 static fn(object $object): bool => $object instanceof assFormulaQuestionUnit,
95 );
96
97 $a_xml_writer->xmlStartTag("qtimetadatafield");
98 $a_xml_writer->xmlElement("fieldlabel", null, "units");
100 foreach ($categorized_units as $categorized_unit) {
101 $a_xml_writer->xmlElement(
102 "fieldentry",
103 [
104 "id" => $categorized_unit->getId(),
105 "sequence" => $categorized_unit->getSequence(),
106 "factor" => $categorized_unit->getFactor(),
107 "base_unit" => $categorized_unit->getBaseUnit(),
108 "base_unit_title" => $categorized_unit->getBaseunitTitle(),
109 "category" => $categorized_unit->getCategory()
110 ],
111 $categorized_unit->getUnit()
112 );
113 }
114 $a_xml_writer->xmlEndTag("qtimetadatafield");
115
116 foreach ($this->object->getVariables() as $variable) {
117 $var = [
118 "precision" => $variable->getPrecision(),
119 "intprecision" => $variable->getIntprecision(),
120 "rangemin" => $variable->getRangeMin(),
121 "rangemax" => $variable->getRangeMax(),
122 "unit" => (is_object($variable->getUnit())) ? $variable->getUnit()->getUnit() : "",
123 "unitvalue" => (is_object($variable->getUnit())) ? $variable->getUnit()->getId() : ""
124 ];
125 $a_xml_writer->xmlStartTag("qtimetadatafield");
126 $a_xml_writer->xmlElement("fieldlabel", null, $variable->getVariable());
127 $a_xml_writer->xmlElement("fieldentry", null, serialize($var));
128 $a_xml_writer->xmlEndTag("qtimetadatafield");
129 }
130 foreach ($this->object->getResults() as $result) {
131 $resultunits = $this->object->getResultUnits($result);
132 $ru = [];
133 foreach ($resultunits as $unit) {
134 array_push($ru, ["unit" => $unit->getUnit(), "unitvalue" => $unit->getId()]);
135 }
136 $res = [
137 "precision" => $result->getPrecision(),
138 "tolerance" => $result->getTolerance(),
139 "rangemin" => $result->getRangeMin(),
140 "rangemax" => $result->getRangeMax(),
141 "points" => $result->getPoints(),
142 "formula" => $result->getFormula(),
143 "rating" => ($result->getRatingSimple()) ? "" : ["sign" => $result->getRatingSign(), "value" => $result->getRatingValue(), "unit" => $result->getRatingUnit()],
144 "unit" => (is_object($result->getUnit())) ? $result->getUnit()->getUnit() : "",
145 "unitvalue" => (is_object($result->getUnit())) ? $result->getUnit()->getId() : "",
146 "resultunits" => $ru,
147 "resulttype" => $result->getResultType()
148 ];
149 $a_xml_writer->xmlStartTag("qtimetadatafield");
150 $a_xml_writer->xmlElement("fieldlabel", null, $result->getResult());
151 $a_xml_writer->xmlElement("fieldentry", null, serialize($res));
152 $a_xml_writer->xmlEndTag("qtimetadatafield");
153 }
154
155 // additional content editing information
156 $this->addAdditionalContentEditingModeInformation($a_xml_writer);
157 $this->addGeneralMetadata($a_xml_writer);
158
159 $a_xml_writer->xmlEndTag("qtimetadata");
160 $a_xml_writer->xmlEndTag("itemmetadata");
161
162 // PART I: qti presentation
163 $attrs = [
164 "label" => $this->object->getTitle()
165 ];
166 $a_xml_writer->xmlStartTag("presentation", $attrs);
167 // add flow to presentation
168 $a_xml_writer->xmlStartTag("flow");
169 // add material with question text to presentation
170 $this->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
171 // add answers to presentation
172 $a_xml_writer->xmlEndTag("flow");
173 $a_xml_writer = $this->addSuggestedSolution($a_xml_writer);
174 $a_xml_writer->xmlEndTag("presentation");
175
176 $this->addGenericFeedback($a_xml_writer);
177
178 $a_xml_writer->xmlEndTag("item");
179 $a_xml_writer->xmlEndTag("questestinterop");
180
181 $xml = $a_xml_writer->xmlDumpMem(false);
182 if (!$a_include_header) {
183 $pos = strpos($xml, "?>");
184 $xml = substr($xml, $pos + 2);
185 }
186 return $xml;
187 }
188}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
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...
const IL_INST_ID
Definition: constants.php:40
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26