1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
5
6/**
7* Class for flash question exports
8*
9* @author		Helmut Schottmüller <helmut.schottmueller@mac.com>
10* @version	$Id$
11* @ingroup ModulesTestQuestionPool
12*/
13class assFlashQuestionExport extends assQuestionExport
14{
15    /**
16    * Returns a QTI xml representation of the question
17    *
18    * Returns a QTI xml representation of the question and sets the internal
19    * domxml variable with the DOM XML representation of the QTI xml representation
20    *
21    * @return string The QTI xml representation of the question
22    * @access public
23    */
24    public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
25    {
26        global $DIC;
27        $ilias = $DIC['ilias'];
28
29        include_once("./Services/Xml/classes/class.ilXmlWriter.php");
30        $a_xml_writer = new ilXmlWriter;
31        // set xml header
32        $a_xml_writer->xmlHeader();
33        $a_xml_writer->xmlStartTag("questestinterop");
34        $attrs = array(
35            "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
36            "title" => $this->object->getTitle(),
37            "maxattempts" => $this->object->getNrOfTries()
38        );
39        $a_xml_writer->xmlStartTag("item", $attrs);
40        // add question description
41        $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
42        // add estimated working time
43        $workingtime = $this->object->getEstimatedWorkingTime();
44        $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
45        $a_xml_writer->xmlElement("duration", null, $duration);
46        // add ILIAS specific metadata
47        $a_xml_writer->xmlStartTag("itemmetadata");
48        $a_xml_writer->xmlStartTag("qtimetadata");
49        $a_xml_writer->xmlStartTag("qtimetadatafield");
50        $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
51        $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
52        $a_xml_writer->xmlEndTag("qtimetadatafield");
53        $a_xml_writer->xmlStartTag("qtimetadatafield");
54        $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
55        $a_xml_writer->xmlElement("fieldentry", null, $this->object->getQuestionType());
56        $a_xml_writer->xmlEndTag("qtimetadatafield");
57        $a_xml_writer->xmlStartTag("qtimetadatafield");
58        $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
59        $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
60        $a_xml_writer->xmlEndTag("qtimetadatafield");
61
62        // additional content editing information
63        $this->addAdditionalContentEditingModeInformation($a_xml_writer);
64        $this->addGeneralMetadata($a_xml_writer);
65
66        $a_xml_writer->xmlStartTag("qtimetadatafield");
67        $a_xml_writer->xmlElement("fieldlabel", null, "points");
68        $a_xml_writer->xmlElement("fieldentry", null, $this->object->getPoints());
69        $a_xml_writer->xmlEndTag("qtimetadatafield");
70        $a_xml_writer->xmlStartTag("qtimetadatafield");
71        $a_xml_writer->xmlElement("fieldlabel", null, "width");
72        $a_xml_writer->xmlElement("fieldentry", null, $this->object->getWidth());
73        $a_xml_writer->xmlEndTag("qtimetadatafield");
74        $a_xml_writer->xmlStartTag("qtimetadatafield");
75        $a_xml_writer->xmlElement("fieldlabel", null, "height");
76        $a_xml_writer->xmlElement("fieldentry", null, $this->object->getHeight());
77        $a_xml_writer->xmlEndTag("qtimetadatafield");
78        $a_xml_writer->xmlStartTag("qtimetadatafield");
79        $a_xml_writer->xmlElement("fieldlabel", null, "applet");
80        $a_xml_writer->xmlElement("fieldentry", null, $this->object->getApplet());
81        $a_xml_writer->xmlEndTag("qtimetadatafield");
82        $a_xml_writer->xmlStartTag("qtimetadatafield");
83        $a_xml_writer->xmlElement("fieldlabel", null, "swf");
84        $flashpath = $this->object->getFlashPath() . $this->object->getApplet();
85        $fh = @fopen($flashpath, "rb");
86        $base64 = "";
87        if ($fh != false) {
88            $flashfile = fread($fh, filesize($flashpath));
89            fclose($fh);
90            $base64 = base64_encode($flashfile);
91        }
92        $a_xml_writer->xmlElement("fieldentry", null, $base64);
93        $a_xml_writer->xmlEndTag("qtimetadatafield");
94        $a_xml_writer->xmlStartTag("qtimetadatafield");
95        $a_xml_writer->xmlElement("fieldlabel", null, "params");
96        $a_xml_writer->xmlElement("fieldentry", null, serialize($this->object->getParameters()));
97        $a_xml_writer->xmlEndTag("qtimetadatafield");
98        $a_xml_writer->xmlEndTag("qtimetadata");
99        $a_xml_writer->xmlEndTag("itemmetadata");
100
101        // PART I: qti presentation
102        $attrs = array(
103            "label" => $this->object->getTitle()
104        );
105        $a_xml_writer->xmlStartTag("presentation", $attrs);
106        // add flow to presentation
107        $a_xml_writer->xmlStartTag("flow");
108        // add material with question text to presentation
109        $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
110        // add answers to presentation
111        $a_xml_writer->xmlEndTag("flow");
112        $a_xml_writer->xmlEndTag("presentation");
113
114        $this->exportFeedbackOnly($a_xml_writer);
115
116        $a_xml_writer->xmlEndTag("item");
117        $a_xml_writer->xmlEndTag("questestinterop");
118
119        $xml = $a_xml_writer->xmlDumpMem(false);
120        if (!$a_include_header) {
121            $pos = strpos($xml, "?>");
122            $xml = substr($xml, $pos + 2);
123        }
124        return $xml;
125    }
126}
127