ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.assFormulaQuestionExport.php
Go to the documentation of this file.
1 <?php
28 {
34  public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
35  {
36  global $DIC;
37  $ilias = $DIC['ilias'];
38 
39  $a_xml_writer = new ilXmlWriter();
40  // set xml header
41  $a_xml_writer->xmlHeader();
42  $a_xml_writer->xmlStartTag("questestinterop");
43  $attrs = [
44  "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
45  "title" => $this->object->getTitle()
46  ];
47  $a_xml_writer->xmlStartTag("item", $attrs);
48  // add question description
49  $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
50  $a_xml_writer->xmlStartTag("itemmetadata");
51  $a_xml_writer->xmlStartTag("qtimetadata");
52  $a_xml_writer->xmlStartTag("qtimetadatafield");
53  $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
54  $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
55  $a_xml_writer->xmlEndTag("qtimetadatafield");
56  $a_xml_writer->xmlStartTag("qtimetadatafield");
57  $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
58  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getQuestionType());
59  $a_xml_writer->xmlEndTag("qtimetadatafield");
60  $a_xml_writer->xmlStartTag("qtimetadatafield");
61  $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
62  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
63  $a_xml_writer->xmlEndTag("qtimetadatafield");
64  $a_xml_writer->xmlStartTag("qtimetadatafield");
65  $a_xml_writer->xmlElement("fieldlabel", null, "points");
66  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getPoints());
67  $a_xml_writer->xmlEndTag("qtimetadatafield");
68  foreach ($this->object->getVariables() as $variable) {
69  $var = [
70  "precision" => $variable->getPrecision(),
71  "intprecision" => $variable->getIntprecision(),
72  "rangemin" => $variable->getRangeMin(),
73  "rangemax" => $variable->getRangeMax(),
74  "unit" => (is_object($variable->getUnit())) ? $variable->getUnit()->getUnit() : "",
75  "unitvalue" => (is_object($variable->getUnit())) ? $variable->getUnit()->getId() : ""
76  ];
77  $a_xml_writer->xmlStartTag("qtimetadatafield");
78  $a_xml_writer->xmlElement("fieldlabel", null, $variable->getVariable());
79  $a_xml_writer->xmlElement("fieldentry", null, serialize($var));
80  $a_xml_writer->xmlEndTag("qtimetadatafield");
81  }
82  foreach ($this->object->getResults() as $result) {
83  $resultunits = $this->object->getResultUnits($result);
84  $ru = [];
85  foreach ($resultunits as $unit) {
86  array_push($ru, ["unit" => $unit->getUnit(), "unitvalue" => $unit->getId()]);
87  }
88  $res = [
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()) ? "" : ["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  "resulttype" => $result->getResultType()
100  ];
101  $a_xml_writer->xmlStartTag("qtimetadatafield");
102  $a_xml_writer->xmlElement("fieldlabel", null, $result->getResult());
103  $a_xml_writer->xmlElement("fieldentry", null, serialize($res));
104  $a_xml_writer->xmlEndTag("qtimetadatafield");
105  }
106 
107  // additional content editing information
108  $this->addAdditionalContentEditingModeInformation($a_xml_writer);
109  $this->addGeneralMetadata($a_xml_writer);
110 
111  $a_xml_writer->xmlEndTag("qtimetadata");
112  $a_xml_writer->xmlEndTag("itemmetadata");
113 
114  // PART I: qti presentation
115  $attrs = [
116  "label" => $this->object->getTitle()
117  ];
118  $a_xml_writer->xmlStartTag("presentation", $attrs);
119  // add flow to presentation
120  $a_xml_writer->xmlStartTag("flow");
121  // add material with question text to presentation
122  $this->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
123  // add answers to presentation
124  $a_xml_writer->xmlEndTag("flow");
125  $a_xml_writer = $this->addSuggestedSolution($a_xml_writer);
126  $a_xml_writer->xmlEndTag("presentation");
127 
128  $this->addGenericFeedback($a_xml_writer);
129 
130  $a_xml_writer = $this->addSolutionHints($a_xml_writer);
131 
132  $a_xml_writer->xmlEndTag("item");
133  $a_xml_writer->xmlEndTag("questestinterop");
134 
135  $xml = $a_xml_writer->xmlDumpMem(false);
136  if (!$a_include_header) {
137  $pos = strpos($xml, "?>");
138  $xml = substr($xml, $pos + 2);
139  }
140  return $xml;
141  }
142 }
$res
Definition: ltiservices.php:69
const IL_INST_ID
Definition: constants.php:40
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
global $DIC
Definition: feed.php:28
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...
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
addSuggestedSolution(ilXmlWriter $writer)
addSolutionHints(ilXmlWriter $writer)
addGenericFeedback(ilXmlWriter $a_xml_writer)