ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assErrorTextExport.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
25 
34 {
42  function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
43  {
44  global $ilias;
45 
46  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
47  $a_xml_writer = new ilXmlWriter;
48  // set xml header
49  $a_xml_writer->xmlHeader();
50  $a_xml_writer->xmlStartTag("questestinterop");
51  $attrs = array(
52  "ident" => "il_".IL_INST_ID."_qst_".$this->object->getId(),
53  "title" => $this->object->getTitle(),
54  "maxattempts" => $this->object->getNrOfTries()
55  );
56  $a_xml_writer->xmlStartTag("item", $attrs);
57  // add question description
58  $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
59  // add estimated working time
60  $workingtime = $this->object->getEstimatedWorkingTime();
61  $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
62  $a_xml_writer->xmlElement("duration", NULL, $duration);
63  // add ILIAS specific metadata
64  $a_xml_writer->xmlStartTag("itemmetadata");
65  $a_xml_writer->xmlStartTag("qtimetadata");
66  $a_xml_writer->xmlStartTag("qtimetadatafield");
67  $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
68  $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
69  $a_xml_writer->xmlEndTag("qtimetadatafield");
70  $a_xml_writer->xmlStartTag("qtimetadatafield");
71  $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
72  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getQuestionType());
73  $a_xml_writer->xmlEndTag("qtimetadatafield");
74  $a_xml_writer->xmlStartTag("qtimetadatafield");
75  $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
76  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
77  $a_xml_writer->xmlEndTag("qtimetadatafield");
78  $a_xml_writer->xmlStartTag("qtimetadatafield");
79  $a_xml_writer->xmlElement("fieldlabel", NULL, "points_wrong");
80  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPointsWrong());
81  $a_xml_writer->xmlEndTag("qtimetadatafield");
82  $a_xml_writer->xmlStartTag("qtimetadatafield");
83  $a_xml_writer->xmlElement("fieldlabel", NULL, "errortext");
84  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getErrorText());
85  $a_xml_writer->xmlEndTag("qtimetadatafield");
86  $a_xml_writer->xmlStartTag("qtimetadatafield");
87  $a_xml_writer->xmlElement("fieldlabel", NULL, "textsize");
88  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextSize());
89  $a_xml_writer->xmlEndTag("qtimetadatafield");
90  $a_xml_writer->xmlStartTag("qtimetadatafield");
91  $a_xml_writer->xmlElement("fieldlabel", NULL, "errordata");
92  $serialized = array();
93  foreach ($this->object->getErrorData() as $data)
94  {
95  array_push($serialized, array($data->text_correct, $data->text_wrong, $data->points));
96  }
97  $a_xml_writer->xmlElement("fieldentry", NULL, serialize($serialized));
98  $a_xml_writer->xmlEndTag("qtimetadatafield");
99  $a_xml_writer->xmlEndTag("qtimetadata");
100  $a_xml_writer->xmlEndTag("itemmetadata");
101 
102  // PART I: qti presentation
103  $attrs = array(
104  "label" => $this->object->getTitle()
105  );
106  $a_xml_writer->xmlStartTag("presentation", $attrs);
107  // add flow to presentation
108  $a_xml_writer->xmlStartTag("flow");
109  // add material with question text to presentation
110  $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
111  // add answers to presentation
112  $a_xml_writer->xmlEndTag("flow");
113  $a_xml_writer->xmlEndTag("presentation");
114 
115  $a_xml_writer->xmlEndTag("item");
116  $a_xml_writer->xmlEndTag("questestinterop");
117 
118  $xml = $a_xml_writer->xmlDumpMem(FALSE);
119  if (!$a_include_header)
120  {
121  $pos = strpos($xml, "?>");
122  $xml = substr($xml, $pos + 2);
123  }
124  return $xml;
125  }
126 
127 }
128 
129 ?>