public function simpleExport($orgu_ref_id)
 {
     $nodes = $this->getStructure($orgu_ref_id);
     $writer = new ilXmlWriter();
     $writer->xmlStartTag("OrgUnits");
     foreach ($nodes as $orgu_ref_id) {
         $orgu = new ilObjOrgUnit($orgu_ref_id);
         if ($orgu->getRefId() == ilObjOrgUnit::getRootOrgRefId()) {
             continue;
         }
         $attributes = $this->getAttributesForOrgu($orgu);
         $writer->xmlStartTag("OrgUnit", $attributes);
         $writer->xmlElement("external_id", null, $this->buildExternalId($orgu_ref_id));
         $writer->xmlElement("title", null, $orgu->getTitle());
         $writer->xmlElement("description", null, $orgu->getDescription());
         $writer->xmlEndTag("OrgUnit");
     }
     $writer->xmlEndTag("OrgUnits");
     return $writer;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getQuestionType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // save the accounts definition
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "accounts_content");
     $a_xml_writer->xmlElement("fieldentry", NULL, base64_encode($this->object->getAccountsXML()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // save the question parts
     $parts = array();
     foreach ($this->object->getParts() as $part_obj) {
         $part = array("part_id" => $part_obj->getPartId(), "position" => $part_obj->getPosition(), "text" => $part_obj->getText(), "max_points" => $part_obj->getMaxPoints(), "max_lines" => $part_obj->getMaxLines(), "booking_def" => base64_encode($part_obj->getBookingXML()));
         $parts[] = $part;
     }
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "booking_parts");
     $a_xml_writer->xmlElement("fieldentry", NULL, serialize($parts));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // additional content editing information
     $this->addAdditionalContentEditingModeInformation($a_xml_writer);
     $this->addGeneralMetadata($a_xml_writer);
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add material with text of question parts to presentation
     foreach ($this->object->getParts() as $part_obj) {
         $this->object->addQTIMaterial($a_xml_writer, $part_obj->getText());
     }
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART III: qti itemfeedback
     $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), true);
     $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), false);
     $attrs = array("ident" => "Correct", "view" => "All");
     $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
     // qti flow_mat
     $a_xml_writer->xmlStartTag("flow_mat");
     $a_xml_writer->xmlStartTag("material");
     $a_xml_writer->xmlElement("mattext");
     $a_xml_writer->xmlEndTag("material");
     $a_xml_writer->xmlEndTag("flow_mat");
     $a_xml_writer->xmlEndTag("itemfeedback");
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * export questions to xml
  */
 function toXML($questions)
 {
     if (!is_array($questions)) {
         $questions =& $this->getQuestions();
     }
     if (count($questions) == 0) {
         $questions =& $this->getQuestions();
     }
     $xml = "";
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $attrs = array("xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd");
     $a_xml_writer->xmlStartTag("surveyobject", $attrs);
     $attrs = array("id" => "qpl_" . $this->getId(), "label" => $this->getTitle(), "online" => $this->getOnline());
     $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
     $a_xml_writer->xmlElement("dummy", NULL, "dummy");
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("metadata");
     $a_xml_writer->xmlStartTag("metadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM");
     include_once "./Services/MetaData/classes/class.ilMD.php";
     $md = new ilMD($this->getId(), 0, $this->getType());
     $writer = new ilXmlWriter();
     $md->toXml($writer);
     $metadata = $writer->xmlDumpMem();
     $a_xml_writer->xmlElement("fieldentry", NULL, $metadata);
     $a_xml_writer->xmlEndTag("metadatafield");
     $a_xml_writer->xmlEndTag("metadata");
     $a_xml_writer->xmlEndTag("surveyquestions");
     $a_xml_writer->xmlEndTag("surveyobject");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     $questionxml = "";
     foreach ($questions as $key => $value) {
         $questiontype = $this->getQuestiontype($value);
         include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
         SurveyQuestion::_includeClass($questiontype);
         $question = new $questiontype();
         $question->loadFromDb($value);
         $questionxml .= $question->toXML(false);
     }
     $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, IMAGEMAP_QUESTION_IDENTIFIER);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     $attrs = array("ident" => "IM", "rcardinality" => "Single");
     $a_xml_writer->xmlStartTag("response_xy", $attrs);
     $solution = $this->object->getSuggestedSolution(0);
     if (count($solution)) {
         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
             $a_xml_writer->xmlStartTag("material");
             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
             if (strcmp($matches[1], "") != 0) {
                 $intlink = $solution["internal_link"];
             }
             $attrs = array("label" => "suggested_solution");
             $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
             $a_xml_writer->xmlEndTag("material");
         }
     }
     $a_xml_writer->xmlStartTag("render_hotspot");
     $a_xml_writer->xmlStartTag("material");
     $imagetype = "image/jpeg";
     if (preg_match("/.*\\.(png|gif)\$/", $this->object->getImageFilename(), $matches)) {
         $imagetype = "image/" . $matches[1];
     }
     $attrs = array("imagtype" => $imagetype, "label" => $this->object->getImageFilename());
     if ($a_include_binary) {
         if ($force_image_references) {
             $attrs["uri"] = $this->object->getImagePathWeb() . $this->object->getImageFilename();
             $a_xml_writer->xmlElement("matimage", $attrs);
         } else {
             $attrs["embedded"] = "base64";
             $imagepath = $this->object->getImagePath() . $this->object->getImageFilename();
             $fh = fopen($imagepath, "rb");
             if ($fh == false) {
                 global $ilErr;
                 $ilErr->raiseError($this->object->lng->txt("error_open_image_file"), $ilErr->MESSAGE);
                 return;
             }
             $imagefile = fread($fh, filesize($imagepath));
             fclose($fh);
             $base64 = base64_encode($imagefile);
             $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
         }
     } else {
         $a_xml_writer->xmlElement("matimage", $attrs);
     }
     $a_xml_writer->xmlEndTag("material");
     // add answers
     foreach ($this->object->getAnswers() as $index => $answer) {
         $rared = "";
         switch ($answer->getArea()) {
             case "rect":
                 $rarea = "Rectangle";
                 break;
             case "circle":
                 $rarea = "Ellipse";
                 break;
             case "poly":
                 $rarea = "Bounded";
                 break;
         }
         $attrs = array("ident" => $index, "rarea" => $rarea);
         $a_xml_writer->xmlStartTag("response_label", $attrs);
         $a_xml_writer->xmlData($answer->getCoords());
         $a_xml_writer->xmlStartTag("material");
         $a_xml_writer->xmlElement("mattext", NULL, $answer->getAnswertext());
         $a_xml_writer->xmlEndTag("material");
         $a_xml_writer->xmlEndTag("response_label");
     }
     $a_xml_writer->xmlEndTag("render_hotspot");
     $a_xml_writer->xmlEndTag("response_xy");
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $a_xml_writer->xmlStartTag("resprocessing");
     $a_xml_writer->xmlStartTag("outcomes");
     $a_xml_writer->xmlStartTag("decvar");
     $a_xml_writer->xmlEndTag("decvar");
     $a_xml_writer->xmlEndTag("outcomes");
     // add response conditions
     foreach ($this->object->getAnswers() as $index => $answer) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         if (!$answer->isStateSet()) {
             $a_xml_writer->xmlStartTag("not");
         }
         $areatype = "";
         switch ($answer->getArea()) {
             case "rect":
                 $areatype = "Rectangle";
                 break;
             case "circle":
                 $areatype = "Ellipse";
                 break;
             case "poly":
                 $areatype = "Bounded";
                 break;
         }
         $attrs = array("respident" => "IM", "areatype" => $areatype);
         $a_xml_writer->xmlElement("varinside", $attrs, $answer->getCoords());
         if (!$answer->isStateSet()) {
             $a_xml_writer->xmlEndTag("not");
         }
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti setvar
         $attrs = array("action" => "Add");
         $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
         $linkrefid = "response_{$index}";
         $attrs = array("feedbacktype" => "Response", "linkrefid" => $linkrefid);
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $answers = $this->object->getAnswers();
     $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
     if (strlen($feedback_allcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $bestindex = 0;
         $maxpoints = 0;
         foreach ($answers as $index => $answer) {
             if ($answer->getPoints() > $maxpoints) {
                 $maxpoints = $answer->getPoints();
                 $bestindex = $index;
             }
         }
         $attrs = array("respident" => "IM");
         $areatype = "";
         $answer = $answers[$bestindex];
         switch ($answer->getArea()) {
             case "rect":
                 $areatype = "Rectangle";
                 break;
             case "circle":
                 $areatype = "Ellipse";
                 break;
             case "poly":
                 $areatype = "Bounded";
                 break;
         }
         $attrs = array("respident" => "IM", "areatype" => $areatype);
         $a_xml_writer->xmlElement("varinside", $attrs, $answer->getCoords());
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $bestindex = 0;
         $maxpoints = 0;
         foreach ($answers as $index => $answer) {
             if ($answer->getPoints() > $maxpoints) {
                 $maxpoints = $answer->getPoints();
                 $bestindex = $index;
             }
         }
         $attrs = array("respident" => "IM");
         $a_xml_writer->xmlStartTag("not");
         $areatype = "";
         $answer = $answers[$bestindex];
         switch ($answer->getArea()) {
             case "rect":
                 $areatype = "Rectangle";
                 break;
             case "circle":
                 $areatype = "Ellipse";
                 break;
             case "poly":
                 $areatype = "Bounded";
                 break;
         }
         $attrs = array("respident" => "IM", "areatype" => $areatype);
         $a_xml_writer->xmlElement("varinside", $attrs, $answer->getCoords());
         $a_xml_writer->xmlEndTag("not");
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $a_xml_writer->xmlEndTag("resprocessing");
     // PART III: qti itemfeedback
     foreach ($this->object->getAnswers() as $index => $answer) {
         $linkrefid = "";
         $linkrefid = "response_{$index}";
         $attrs = array("ident" => $linkrefid, "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $this->object->getFeedbackSingleAnswer($index));
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * adds a qti meta data field with given name and value to the passed xml writer
  * (xml writer must be in context of opened "qtimetadata" tag)
  * 
  * @final
  * @access protected
  * @param ilXmlWriter $a_xml_writer
  * @param string $fieldLabel
  * @param string $fieldValue
  */
 protected final function addQtiMetaDataField(ilXmlWriter $a_xml_writer, $fieldLabel, $fieldValue)
 {
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, $fieldLabel);
     $a_xml_writer->xmlElement("fieldentry", NULL, $fieldValue);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
 }
 /**
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getQuestionType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // additional content editing information
     $this->addAdditionalContentEditingModeInformation($a_xml_writer);
     $this->addGeneralMetadata($a_xml_writer);
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "points_wrong");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPointsWrong());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "errortext");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getErrorText());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "textsize");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextSize());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "errordata");
     $serialized = array();
     foreach ($this->object->getErrorData() as $data) {
         array_push($serialized, array($data->text_correct, $data->text_wrong, $data->points));
     }
     $a_xml_writer->xmlElement("fieldentry", NULL, serialize($serialized));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Math/classes/class.EvalMath.php";
     $eval = new EvalMath();
     $eval->suppress_errors = TRUE;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, CLOZE_TEST_IDENTIFIER);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // additional content editing information
     $this->addAdditionalContentEditingModeInformation($a_xml_writer);
     $this->addGeneralMetadata($a_xml_writer);
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "textgaprating");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextgapRating());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "fixedTextLength");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getFixedTextLength());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "identicalScoring");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getIdenticalScoring());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "combinations");
     $a_xml_writer->xmlElement("fieldentry", NULL, base64_encode(json_encode($this->object->getGapCombinations())));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     $questionText = $this->object->getQuestion() ? $this->object->getQuestion() : '&nbsp;';
     $this->object->addQTIMaterial($a_xml_writer, $questionText);
     $text_parts = preg_split("/\\[gap.*?\\[\\/gap\\]/", $this->object->getClozeText());
     // add material with question text to presentation
     for ($i = 0; $i <= $this->object->getGapCount(); $i++) {
         $this->object->addQTIMaterial($a_xml_writer, $text_parts[$i]);
         if ($i < $this->object->getGapCount()) {
             // add gap
             $gap = $this->object->getGap($i);
             switch ($gap->getType()) {
                 case CLOZE_SELECT:
                     // comboboxes
                     $attrs = array("ident" => "gap_{$i}", "rcardinality" => "Single");
                     $a_xml_writer->xmlStartTag("response_str", $attrs);
                     $solution = $this->object->getSuggestedSolution($i);
                     if (count($solution)) {
                         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
                             $attrs = array("label" => "suggested_solution");
                             $a_xml_writer->xmlStartTag("material", $attrs);
                             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
                             if (strcmp($matches[1], "") != 0) {
                                 $intlink = $solution["internal_link"];
                             }
                             $a_xml_writer->xmlElement("mattext", NULL, $intlink);
                             $a_xml_writer->xmlEndTag("material");
                         }
                     }
                     $attrs = array("shuffle" => $gap->getShuffle() ? "Yes" : "No");
                     $a_xml_writer->xmlStartTag("render_choice", $attrs);
                     // add answers
                     foreach ($gap->getItems() as $answeritem) {
                         $attrs = array("ident" => $answeritem->getOrder());
                         $a_xml_writer->xmlStartTag("response_label", $attrs);
                         $a_xml_writer->xmlStartTag("material");
                         $a_xml_writer->xmlElement("mattext", NULL, $answeritem->getAnswertext());
                         $a_xml_writer->xmlEndTag("material");
                         $a_xml_writer->xmlEndTag("response_label");
                     }
                     $a_xml_writer->xmlEndTag("render_choice");
                     $a_xml_writer->xmlEndTag("response_str");
                     break;
                 case CLOZE_TEXT:
                     // text fields
                     $attrs = array("ident" => "gap_{$i}", "rcardinality" => "Single");
                     $a_xml_writer->xmlStartTag("response_str", $attrs);
                     $solution = $this->object->getSuggestedSolution($i);
                     if (count($solution)) {
                         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
                             $attrs = array("label" => "suggested_solution");
                             $a_xml_writer->xmlStartTag("material", $attrs);
                             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
                             if (strcmp($matches[1], "") != 0) {
                                 $intlink = $solution["internal_link"];
                             }
                             $a_xml_writer->xmlElement("mattext", NULL, $intlink);
                             $a_xml_writer->xmlEndTag("material");
                         }
                     }
                     $attrs = array("fibtype" => "String", "prompt" => "Box", "columns" => $gap->getGapSize());
                     $a_xml_writer->xmlStartTag("render_fib", $attrs);
                     $a_xml_writer->xmlEndTag("render_fib");
                     $a_xml_writer->xmlEndTag("response_str");
                     break;
                 case CLOZE_NUMERIC:
                     // numeric fields
                     $attrs = array("ident" => "gap_{$i}", "numtype" => "Decimal", "rcardinality" => "Single");
                     $a_xml_writer->xmlStartTag("response_num", $attrs);
                     $solution = $this->object->getSuggestedSolution($i);
                     if (count($solution)) {
                         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
                             $attrs = array("label" => "suggested_solution");
                             $a_xml_writer->xmlStartTag("material", $attrs);
                             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
                             if (strcmp($matches[1], "") != 0) {
                                 $intlink = $solution["internal_link"];
                             }
                             $a_xml_writer->xmlElement("mattext", NULL, $intlink);
                             $a_xml_writer->xmlEndTag("material");
                         }
                     }
                     $answeritem = $gap->getItem(0);
                     $attrs = array("fibtype" => "Decimal", "prompt" => "Box", "columns" => $gap->getGapSize());
                     if (is_object($answeritem)) {
                         if ($eval->e($answeritem->getLowerBound()) !== FALSE) {
                             $attrs["minnumber"] = $answeritem->getLowerBound();
                         }
                         if ($eval->e($answeritem->getUpperBound()) !== FALSE) {
                             $attrs["maxnumber"] = $answeritem->getUpperBound();
                         }
                     }
                     $a_xml_writer->xmlStartTag("render_fib", $attrs);
                     $a_xml_writer->xmlEndTag("render_fib");
                     $a_xml_writer->xmlEndTag("response_num");
                     break;
             }
         }
     }
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $a_xml_writer->xmlStartTag("resprocessing");
     $a_xml_writer->xmlStartTag("outcomes");
     $a_xml_writer->xmlStartTag("decvar");
     $a_xml_writer->xmlEndTag("decvar");
     $a_xml_writer->xmlEndTag("outcomes");
     // add response conditions
     for ($i = 0; $i < $this->object->getGapCount(); $i++) {
         $gap = $this->object->getGap($i);
         switch ($gap->getType()) {
             case CLOZE_SELECT:
                 foreach ($gap->getItems() as $answer) {
                     $attrs = array("continue" => "Yes");
                     $a_xml_writer->xmlStartTag("respcondition", $attrs);
                     // qti conditionvar
                     $a_xml_writer->xmlStartTag("conditionvar");
                     $attrs = array("respident" => "gap_{$i}");
                     $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
                     $a_xml_writer->xmlEndTag("conditionvar");
                     // qti setvar
                     $attrs = array("action" => "Add");
                     $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
                     // qti displayfeedback
                     $linkrefid = "";
                     $linkrefid = "{$i}" . "_Response_" . $answer->getOrder();
                     $attrs = array("feedbacktype" => "Response", "linkrefid" => $linkrefid);
                     $a_xml_writer->xmlElement("displayfeedback", $attrs);
                     $a_xml_writer->xmlEndTag("respcondition");
                 }
                 break;
             case CLOZE_TEXT:
                 foreach ($gap->getItems() as $answer) {
                     $attrs = array("continue" => "Yes");
                     $a_xml_writer->xmlStartTag("respcondition", $attrs);
                     // qti conditionvar
                     $a_xml_writer->xmlStartTag("conditionvar");
                     $attrs = array("respident" => "gap_{$i}");
                     $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
                     $a_xml_writer->xmlEndTag("conditionvar");
                     // qti setvar
                     $attrs = array("action" => "Add");
                     $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
                     // qti displayfeedback
                     $linkrefid = "{$i}" . "_Response_" . $answer->getOrder();
                     $attrs = array("feedbacktype" => "Response", "linkrefid" => $linkrefid);
                     $a_xml_writer->xmlElement("displayfeedback", $attrs);
                     $a_xml_writer->xmlEndTag("respcondition");
                 }
                 break;
             case CLOZE_NUMERIC:
                 foreach ($gap->getItems() as $answer) {
                     $attrs = array("continue" => "Yes");
                     $a_xml_writer->xmlStartTag("respcondition", $attrs);
                     // qti conditionvar
                     $a_xml_writer->xmlStartTag("conditionvar");
                     $attrs = array("respident" => "gap_{$i}");
                     $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
                     $a_xml_writer->xmlEndTag("conditionvar");
                     // qti setvar
                     $attrs = array("action" => "Add");
                     $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
                     // qti displayfeedback
                     $linkrefid = "{$i}" . "_Response_" . $answer->getOrder();
                     $attrs = array("feedbacktype" => "Response", "linkrefid" => $linkrefid);
                     $a_xml_writer->xmlElement("displayfeedback", $attrs);
                     $a_xml_writer->xmlEndTag("respcondition");
                 }
                 break;
         }
     }
     $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), true);
     if (strlen($feedback_allcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         for ($i = 0; $i < $this->object->getGapCount(); $i++) {
             $gap = $this->object->getGap($i);
             $indexes = $gap->getBestSolutionIndexes();
             if ($i > 0) {
                 $a_xml_writer->xmlStartTag("and");
             }
             switch ($gap->getType()) {
                 case CLOZE_SELECT:
                     $k = 0;
                     foreach ($indexes as $key) {
                         if ($k > 0) {
                             $a_xml_writer->xmlStartTag("or");
                         }
                         $attrs = array("respident" => "gap_{$i}");
                         $answer = $gap->getItem($key);
                         $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
                         if ($k > 0) {
                             $a_xml_writer->xmlEndTag("or");
                         }
                         $k++;
                     }
                     break;
                 case CLOZE_TEXT:
                     $k = 0;
                     foreach ($indexes as $key) {
                         if ($k > 0) {
                             $a_xml_writer->xmlStartTag("or");
                         }
                         $attrs = array("respident" => "gap_{$i}");
                         $answer = $gap->getItem($key);
                         $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
                         if ($k > 0) {
                             $a_xml_writer->xmlEndTag("or");
                         }
                         $k++;
                     }
                     break;
                 case CLOZE_NUMERIC:
                     $k = 0;
                     foreach ($indexes as $key) {
                         if ($k > 0) {
                             $a_xml_writer->xmlStartTag("or");
                         }
                         $attrs = array("respident" => "gap_{$i}");
                         $answer = $gap->getItem($key);
                         $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
                         if ($k > 0) {
                             $a_xml_writer->xmlEndTag("or");
                         }
                         $k++;
                     }
                     break;
             }
             if ($i > 0) {
                 $a_xml_writer->xmlEndTag("and");
             }
         }
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), false);
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $a_xml_writer->xmlStartTag("not");
         for ($i = 0; $i < $this->object->getGapCount(); $i++) {
             $gap = $this->object->getGap($i);
             $indexes = $gap->getBestSolutionIndexes();
             if ($i > 0) {
                 $a_xml_writer->xmlStartTag("and");
             }
             switch ($gap->getType()) {
                 case CLOZE_SELECT:
                     $k = 0;
                     foreach ($indexes as $key) {
                         if ($k > 0) {
                             $a_xml_writer->xmlStartTag("or");
                         }
                         $attrs = array("respident" => "gap_{$i}");
                         $answer = $gap->getItem($key);
                         $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
                         if ($k > 0) {
                             $a_xml_writer->xmlEndTag("or");
                         }
                         $k++;
                     }
                     break;
                 case CLOZE_TEXT:
                     $k = 0;
                     foreach ($indexes as $key) {
                         if ($k > 0) {
                             $a_xml_writer->xmlStartTag("or");
                         }
                         $attrs = array("respident" => "gap_{$i}");
                         $answer = $gap->getItem($key);
                         $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
                         if ($k > 0) {
                             $a_xml_writer->xmlEndTag("or");
                         }
                         $k++;
                     }
                     break;
                 case CLOZE_NUMERIC:
                     $k = 0;
                     foreach ($indexes as $key) {
                         if ($k > 0) {
                             $a_xml_writer->xmlStartTag("or");
                         }
                         $attrs = array("respident" => "gap_{$i}");
                         $answer = $gap->getItem($key);
                         $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
                         if ($k > 0) {
                             $a_xml_writer->xmlEndTag("or");
                         }
                         $k++;
                     }
                     break;
             }
             if ($i > 0) {
                 $a_xml_writer->xmlEndTag("and");
             }
         }
         $a_xml_writer->xmlEndTag("not");
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $a_xml_writer->xmlEndTag("resprocessing");
     // PART III: qti itemfeedback
     for ($i = 0; $i < $this->object->getGapCount(); $i++) {
         $gap = $this->object->getGap($i);
         switch ($gap->getType()) {
             case CLOZE_SELECT:
                 break;
             case CLOZE_TEXT:
                 break;
             case CLOZE_NUMERIC:
                 break;
         }
         /*foreach ($gap->getItems() as $answer)
         			{
         				$linkrefid = "$i" . "_Response_" . $answer->getOrder();
         				$attrs = array(
         					"ident" => $linkrefid,
         					"view" => "All"
         				);
         				$a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         				// qti flow_mat
         				$a_xml_writer->xmlStartTag("flow_mat");
         //				$a_xml_writer->xmlStartTag("material");
         //				$a_xml_writer->xmlElement("mattext");
         //				$a_xml_writer->xmlEndTag("material");
         				$fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
         					$this->object->getId(), $index
         				);
         				$this->object->addQTIMaterial($a_xml_writer, $fb);
         				$a_xml_writer->xmlEndTag("flow_mat");
         				$a_xml_writer->xmlEndTag("itemfeedback");
         			}*/
         $attrs = array("ident" => $i, "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         //				$a_xml_writer->xmlStartTag("material");
         //				$a_xml_writer->xmlElement("mattext");
         //				$a_xml_writer->xmlEndTag("material");
         $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->object->getId(), $i);
         $this->object->addQTIMaterial($a_xml_writer, $fb);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Get xml of object values
  *
  * @param ilXmlWriter $a_xml_writer 
  * @param int $a_obj_id
  */
 public static function _appendXMLByObjId(ilXmlWriter $a_xml_writer, $a_obj_id)
 {
     $a_xml_writer->xmlStartTag('AdvancedMetaData');
     self::preloadByObjIds(array($a_obj_id));
     $values_records = self::preloadedRead(ilObject::_lookupType($a_obj_id), $a_obj_id);
     foreach ($values_records as $values_record) {
         $defs = $values_record->getDefinitions();
         foreach ($values_record->getADTGroup()->getElements() as $element_id => $element) {
             $def = $defs[$element_id];
             $value = null;
             if (!$element->isNull()) {
                 $value = $def->getValueForXML($element);
             }
             $a_xml_writer->xmlElement('Value', array('id' => $def->getImportId()), $value);
         }
     }
     $a_xml_writer->xmlEndTag('AdvancedMetaData');
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once 'Services/Xml/classes/class.ilXmlWriter.php';
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getQuestionType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     foreach ($this->object->getVariables() as $variable) {
         $var = array("precision" => $variable->getPrecision(), "intprecision" => $variable->getIntprecision(), "rangemin" => $variable->getRangeMin(), "rangemax" => $variable->getRangeMax(), "unit" => is_object($variable->getUnit()) ? $variable->getUnit()->getUnit() : "", "unitvalue" => is_object($variable->getUnit()) ? $variable->getUnit()->getId() : "");
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, $variable->getVariable());
         $a_xml_writer->xmlElement("fieldentry", NULL, serialize($var));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     foreach ($this->object->getResults() as $result) {
         $resultunits = $this->object->getResultUnits($result);
         $ru = array();
         foreach ($resultunits as $unit) {
             array_push($ru, array("unit" => $unit->getUnit(), "unitvalue" => $unit->getId()));
         }
         $res = array("precision" => $result->getPrecision(), "tolerance" => $result->getTolerance(), "rangemin" => $result->getRangeMin(), "rangemax" => $result->getRangeMax(), "points" => $result->getPoints(), "formula" => $result->getFormula(), "rating" => $result->getRatingSimple() ? "" : array("sign" => $result->getRatingSign(), "value" => $result->getRatingValue(), "unit" => $result->getRatingUnit()), "unit" => is_object($result->getUnit()) ? $result->getUnit()->getUnit() : "", "unitvalue" => is_object($result->getUnit()) ? $result->getUnit()->getId() : "", "resultunits" => $ru);
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, $result->getResult());
         $a_xml_writer->xmlElement("fieldentry", NULL, serialize($res));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     // additional content editing information
     $this->addAdditionalContentEditingModeInformation($a_xml_writer);
     $this->addGeneralMetadata($a_xml_writer);
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $xml = new ilXmlWriter();
     // set xml header
     $xml->xmlHeader();
     $xml->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $xml->xmlStartTag("item", $attrs);
     // add question description
     $xml->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $xml->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $xml->xmlStartTag("itemmetadata");
     $xml->xmlStartTag("qtimetadata");
     $xml->xmlStartTag("qtimetadatafield");
     $xml->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $xml->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $xml->xmlEndTag("qtimetadatafield");
     $xml->xmlStartTag("qtimetadatafield");
     $xml->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $xml->xmlElement("fieldentry", NULL, KPRIM_CHOICE_QUESTION_IDENTIFIER);
     $xml->xmlEndTag("qtimetadatafield");
     $xml->xmlStartTag("qtimetadatafield");
     $xml->xmlElement("fieldlabel", NULL, "AUTHOR");
     $xml->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $xml->xmlEndTag("qtimetadatafield");
     // additional content editing information
     $this->addAdditionalContentEditingModeInformation($xml);
     $this->addGeneralMetadata($xml);
     $xml->xmlStartTag("qtimetadatafield");
     $xml->xmlElement("fieldlabel", NULL, "answer_type");
     $xml->xmlElement("fieldentry", NULL, $this->object->getAnswerType());
     $xml->xmlEndTag("qtimetadatafield");
     $xml->xmlStartTag("qtimetadatafield");
     $xml->xmlElement("fieldlabel", NULL, "thumb_size");
     $xml->xmlElement("fieldentry", NULL, $this->object->getThumbSize());
     $xml->xmlEndTag("qtimetadatafield");
     $xml->xmlStartTag("qtimetadatafield");
     $xml->xmlElement("fieldlabel", NULL, "option_label_setting");
     $xml->xmlElement("fieldentry", NULL, $this->object->getOptionLabel());
     $xml->xmlEndTag("qtimetadatafield");
     $xml->xmlStartTag("qtimetadatafield");
     $xml->xmlElement("fieldlabel", NULL, "custom_true_option_label");
     $xml->xmlElement("fieldentry", NULL, $this->object->getCustomTrueOptionLabel());
     $xml->xmlEndTag("qtimetadatafield");
     $xml->xmlStartTag("qtimetadatafield");
     $xml->xmlElement("fieldlabel", NULL, "custom_false_option_label");
     $xml->xmlElement("fieldentry", NULL, $this->object->getCustomFalseOptionLabel());
     $xml->xmlEndTag("qtimetadatafield");
     $xml->xmlStartTag("qtimetadatafield");
     $xml->xmlElement("fieldlabel", NULL, "feedback_setting");
     $xml->xmlElement("fieldentry", NULL, $this->object->getSpecificFeedbackSetting());
     $xml->xmlEndTag("qtimetadatafield");
     $xml->xmlEndTag("qtimetadata");
     $xml->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $xml->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $xml->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($xml, $this->object->getQuestion());
     // add answers to presentation
     $attrs = array("ident" => "MCMR", "rcardinality" => "Multiple");
     $xml->xmlStartTag("response_lid", $attrs);
     $solution = $this->object->getSuggestedSolution(0);
     if (count($solution)) {
         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
             $xml->xmlStartTag("material");
             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
             if (strcmp($matches[1], "") != 0) {
                 $intlink = $solution["internal_link"];
             }
             $attrs = array("label" => "suggested_solution");
             $xml->xmlElement("mattext", $attrs, $intlink);
             $xml->xmlEndTag("material");
         }
     }
     // shuffle output
     $attrs = array();
     if ($this->object->isShuffleAnswersEnabled()) {
         $attrs = array("shuffle" => "Yes");
     } else {
         $attrs = array("shuffle" => "No");
     }
     $xml->xmlStartTag("render_choice", $attrs);
     // add answers
     $answers =& $this->object->getAnswers();
     $akeys = array_keys($answers);
     foreach ($akeys as $index) {
         $answer = $this->object->getAnswer($index);
         $xml->xmlStartTag('response_label', array('ident' => $answer->getPosition()));
         if (strlen($answer->getImageFile())) {
             $this->object->addQTIMaterial($xml, $answer->getAnswertext(), FALSE, FALSE);
             $imagetype = "image/jpeg";
             if (preg_match("/.*\\.(png|gif)\$/", $answer->getImageFile(), $matches)) {
                 $imagetype = "image/" . $matches[1];
             }
             if ($force_image_references) {
                 $attrs = array("imagtype" => $imagetype, "label" => $answer->getImageFile(), "uri" => $answer->getImageWebPath());
                 $xml->xmlElement("matimage", $attrs);
             } else {
                 $imagepath = $answer->getImageFsPath();
                 $fh = @fopen($imagepath, "rb");
                 if ($fh != false) {
                     $imagefile = fread($fh, filesize($imagepath));
                     fclose($fh);
                     $base64 = base64_encode($imagefile);
                     $attrs = array("imagtype" => $imagetype, "label" => $answer->getImageFile(), "embedded" => "base64");
                     $xml->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
                 }
             }
             $xml->xmlEndTag("material");
         } else {
             $this->object->addQTIMaterial($xml, $answer->getAnswertext());
         }
         $xml->xmlEndTag("response_label");
     }
     $xml->xmlEndTag("render_choice");
     $xml->xmlEndTag("response_lid");
     $xml->xmlEndTag("flow");
     $xml->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $xml->xmlStartTag('resprocessing');
     $xml->xmlStartTag('outcomes');
     $xml->xmlElement('decvar', array('varname' => 'SCORE', 'vartype' => 'Decimal', 'defaultval' => '0', 'minvalue' => $this->getMinPoints(), 'maxvalue' => $this->getMaxPoints()));
     $xml->xmlEndTag('outcomes');
     foreach ($answers as $answer) {
         $xml->xmlStartTag('respcondition', array('continue' => 'Yes'));
         $xml->xmlStartTag('conditionvar');
         $xml->xmlElement('varequal', array('respident' => $answer->getPosition()), $answer->getCorrectness());
         $xml->xmlEndTag('conditionvar');
         $xml->xmlElement('displayfeedback', array('feedbacktype' => 'Response', 'linkrefid' => "response_{$answer->getPosition()}"));
         $xml->xmlEndTag('respcondition');
     }
     $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), true);
     $xml->xmlStartTag('respcondition', array('continue' => 'Yes'));
     $xml->xmlStartTag('conditionvar');
     $xml->xmlStartTag('and');
     foreach ($answers as $answer) {
         $xml->xmlElement('varequal', array('respident' => $answer->getPosition()), $answer->getCorrectness());
     }
     $xml->xmlEndTag('and');
     $xml->xmlEndTag('conditionvar');
     $xml->xmlElement('setvar', array('action' => 'Add'), $this->object->getPoints());
     if (strlen($feedback_allcorrect)) {
         $xml->xmlElement('displayfeedback', array('feedbacktype' => 'Response', 'linkrefid' => 'response_allcorrect'));
     }
     $xml->xmlEndTag('respcondition');
     $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), false);
     $xml->xmlStartTag('respcondition', array('continue' => 'Yes'));
     $xml->xmlStartTag('conditionvar');
     $xml->xmlStartTag('or');
     foreach ($answers as $answer) {
         $xml->xmlStartTag('not');
         $xml->xmlElement('varequal', array('respident' => $answer->getPosition()), $answer->getCorrectness());
         $xml->xmlEndTag('not');
     }
     $xml->xmlEndTag('or');
     $xml->xmlEndTag('conditionvar');
     $xml->xmlElement('setvar', array('action' => 'Add'), 0);
     if (strlen($feedback_onenotcorrect)) {
         $xml->xmlElement('displayfeedback', array('feedbacktype' => 'Response', 'linkrefid' => 'response_onenotcorrect'));
     }
     $xml->xmlEndTag('respcondition');
     $xml->xmlEndTag('resprocessing');
     foreach ($answers as $answer) {
         $xml->xmlStartTag('itemfeedback', array('ident' => "response_{$answer->getPosition()}", 'view' => 'All'));
         $xml->xmlStartTag('flow_mat');
         $this->object->addQTIMaterial($xml, $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->object->getId(), $answer->getPosition()));
         $xml->xmlEndTag('flow_mat');
         $xml->xmlEndTag('itemfeedback');
     }
     if (strlen($feedback_allcorrect)) {
         $xml->xmlStartTag('itemfeedback', array('ident' => 'response_allcorrect', 'view' => 'All'));
         $xml->xmlStartTag('flow_mat');
         $this->object->addQTIMaterial($xml, $feedback_allcorrect);
         $xml->xmlEndTag('flow_mat');
         $xml->xmlEndTag('itemfeedback');
     }
     if (strlen($feedback_onenotcorrect)) {
         $xml->xmlStartTag('itemfeedback', array('ident' => 'response_onenotcorrect', 'view' => 'All'));
         $xml->xmlStartTag('flow_mat');
         $this->object->addQTIMaterial($xml, $feedback_onenotcorrect);
         $xml->xmlEndTag('flow_mat');
         $xml->xmlEndTag('itemfeedback');
     }
     $xml->xmlEndTag("item");
     $xml->xmlEndTag("questestinterop");
     $xml = $xml->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
Example #11
0
 /**
  * Process exporter
  *
  * @param
  * @return
  */
 function processExporter($a_comp, $a_class, $a_entity, $a_target_release, $a_id)
 {
     $success = true;
     if (!is_array($a_id)) {
         if ($a_id == "") {
             return;
         }
         $a_id = array($a_id);
     }
     // get exporter object
     $export_class_file = "./" . $a_comp . "/classes/class." . $a_class . ".php";
     //echo "1-".$export_class_file."-"; exit;
     if (!is_file($export_class_file)) {
         echo "1-not found:" . $export_class_file . "-";
         exit;
         return false;
     }
     include_once $export_class_file;
     $exp = new $a_class();
     if (!isset($this->cnt[$a_comp])) {
         $this->cnt[$a_comp] = 1;
     } else {
         $this->cnt[$a_comp]++;
     }
     $set_dir_relative = $a_comp . "/set_" . $this->cnt[$a_comp];
     $set_dir_absolute = $this->export_run_dir . "/" . $set_dir_relative;
     ilUtil::makeDirParents($set_dir_absolute);
     $exp->init();
     $sv = $exp->determineSchemaVersion($a_entity, $a_target_release);
     // process head dependencies
     $sequence = $exp->getXmlExportHeadDependencies($a_entity, $a_target_release, $a_id);
     foreach ($sequence as $s) {
         $comp = explode("/", $s["component"]);
         $exp_class = "il" . $comp[1] . "Exporter";
         $s = $this->processExporter($s["component"], $exp_class, $s["entity"], $a_target_release, $s["ids"]);
         if (!$s) {
             $success = false;
         }
     }
     // write export.xml file
     $export_writer = new ilXmlWriter();
     $export_writer->xmlHeader();
     $attribs = array("InstallationId" => IL_INST_ID, "InstallationUrl" => ILIAS_HTTP_PATH, "Entity" => $a_entity, "SchemaVersion" => $sv["schema_version"], "TargetRelease" => $a_target_release, "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xmlns:exp" => "http://www.ilias.de/Services/Export/exp/4_1", "xsi:schemaLocation" => "http://www.ilias.de/Services/Export/exp/4_1 " . ILIAS_HTTP_PATH . "/xml/ilias_export_4_1.xsd");
     if ($sv["namespace"] != "" && $sv["xsd_file"] != "") {
         $attribs["xsi:schemaLocation"] .= " " . $sv["namespace"] . " " . ILIAS_HTTP_PATH . "/xml/" . $sv["xsd_file"];
         $attribs["xmlns"] = $sv["namespace"];
     }
     if ($sv["uses_dataset"]) {
         $attribs["xsi:schemaLocation"] .= " " . "http://www.ilias.de/Services/DataSet/ds/4_3 " . ILIAS_HTTP_PATH . "/xml/ilias_ds_4_3.xsd";
         $attribs["xmlns:ds"] = "http://www.ilias.de/Services/DataSet/ds/4_3";
     }
     $export_writer->xmlStartTag('exp:Export', $attribs);
     $dir_cnt = 1;
     foreach ($a_id as $id) {
         $exp->setExportDirectories($set_dir_relative . "/expDir_" . $dir_cnt, $set_dir_absolute . "/expDir_" . $dir_cnt);
         $export_writer->xmlStartTag('exp:ExportItem', array("Id" => $id));
         //$xml = $exp->getXmlRepresentation($a_entity, $a_target_release, $id);
         $xml = $exp->getXmlRepresentation($a_entity, $sv["schema_version"], $id);
         $export_writer->appendXml($xml);
         $export_writer->xmlEndTag('exp:ExportItem');
         $dir_cnt++;
     }
     $export_writer->xmlEndTag('exp:Export');
     $export_writer->xmlDumpFile($set_dir_absolute . "/export.xml", false);
     $this->manifest_writer->xmlElement("ExportFile", array("Component" => $a_comp, "Path" => $set_dir_relative . "/export.xml"));
     // process tail dependencies
     $sequence = $exp->getXmlExportTailDependencies($a_entity, $a_target_release, $a_id);
     foreach ($sequence as $s) {
         $comp = explode("/", $s["component"]);
         $exp_class = "il" . $comp[1] . "Exporter";
         $s = $this->processExporter($s["component"], $exp_class, $s["entity"], $a_target_release, $s["ids"]);
         if (!$s) {
             $success = false;
         }
     }
     return $success;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, NUMERIC_QUESTION_IDENTIFIER);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // additional content editing information
     $this->addAdditionalContentEditingModeInformation($a_xml_writer);
     $this->addGeneralMetadata($a_xml_writer);
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     $attrs = array("ident" => "NUM", "rcardinality" => "Single", "numtype" => "Decimal");
     $a_xml_writer->xmlStartTag("response_num", $attrs);
     $solution = $this->object->getSuggestedSolution(0);
     if (count($solution)) {
         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
             $a_xml_writer->xmlStartTag("material");
             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
             if (strcmp($matches[1], "") != 0) {
                 $intlink = $solution["internal_link"];
             }
             $attrs = array("label" => "suggested_solution");
             $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
             $a_xml_writer->xmlEndTag("material");
         }
     }
     // shuffle output
     $attrs = array("fibtype" => "Decimal", "maxchars" => $this->object->getMaxChars());
     $a_xml_writer->xmlStartTag("render_fib", $attrs);
     $a_xml_writer->xmlEndTag("render_fib");
     $a_xml_writer->xmlEndTag("response_num");
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $a_xml_writer->xmlStartTag("resprocessing");
     $a_xml_writer->xmlStartTag("outcomes");
     $a_xml_writer->xmlStartTag("decvar");
     $a_xml_writer->xmlEndTag("decvar");
     $a_xml_writer->xmlEndTag("outcomes");
     // add response conditions
     $a_xml_writer->xmlStartTag("respcondition");
     // qti conditionvar
     $a_xml_writer->xmlStartTag("conditionvar");
     $attrs = array("respident" => "NUM");
     $a_xml_writer->xmlElement("vargte", $attrs, $this->object->getLowerLimit());
     $a_xml_writer->xmlElement("varlte", $attrs, $this->object->getUpperLimit());
     $a_xml_writer->xmlEndTag("conditionvar");
     // qti setvar
     $attrs = array("action" => "Add");
     $a_xml_writer->xmlElement("setvar", $attrs, $this->object->getPoints());
     // qti displayfeedback
     $attrs = array("feedbacktype" => "Response", "linkrefid" => "Correct");
     $a_xml_writer->xmlElement("displayfeedback", $attrs);
     $a_xml_writer->xmlEndTag("respcondition");
     $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), true);
     if (strlen($feedback_allcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $attrs = array("respident" => "NUM");
         $a_xml_writer->xmlElement("vargte", $attrs, $this->object->getLowerLimit());
         $a_xml_writer->xmlElement("varlte", $attrs, $this->object->getUpperLimit());
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), false);
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $a_xml_writer->xmlStartTag("not");
         $attrs = array("respident" => "NUM");
         $a_xml_writer->xmlElement("vargte", $attrs, $this->object->getLowerLimit());
         $a_xml_writer->xmlElement("varlte", $attrs, $this->object->getUpperLimit());
         $a_xml_writer->xmlEndTag("not");
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $a_xml_writer->xmlEndTag("resprocessing");
     // PART III: qti itemfeedback
     $attrs = array("ident" => "Correct", "view" => "All");
     $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
     // qti flow_mat
     $a_xml_writer->xmlStartTag("flow_mat");
     $a_xml_writer->xmlStartTag("material");
     $a_xml_writer->xmlElement("mattext");
     $a_xml_writer->xmlEndTag("material");
     $a_xml_writer->xmlEndTag("flow_mat");
     $a_xml_writer->xmlEndTag("itemfeedback");
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Get xml representation
  *
  * @param	string		entity
  * @param	string		schema version
  * @param	string		id
  * @return	string		xml string
  */
 public function getXmlRepresentation($a_entity, $a_schema_version, $a_id)
 {
     $parts = explode(":", $a_id);
     if (sizeof($parts) != 2) {
         return;
     }
     $obj_id = $parts[0];
     $rec_id = $parts[1];
     // any data for current record and object?
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php';
     $raw = ilAdvancedMDValues::findByObjectId($obj_id);
     if (!$raw) {
         return;
     }
     // gather sub-item data from value entries
     $sub_items = array();
     foreach ($raw as $item) {
         $sub_items[$item["sub_type"]][] = $item["sub_id"];
     }
     // gather all relevant data
     $items = array();
     foreach ($sub_items as $sub_type => $sub_ids) {
         foreach (array_unique($sub_ids) as $sub_id) {
             $values_record = new ilAdvancedMDValues($rec_id, $obj_id, $sub_type, $sub_id);
             $defs = $values_record->getDefinitions();
             $values_record->read();
             foreach ($values_record->getADTGroup()->getElements() as $element_id => $element) {
                 if (!$element->isNull()) {
                     $def = $defs[$element_id];
                     $items[$rec_id][] = array('id' => $def->getImportId(), 'sub_type' => $sub_type, 'sub_id' => $sub_id, 'value' => $def->getValueForXML($element));
                 }
             }
         }
     }
     // we only want non-empty fields
     if (sizeof($items)) {
         $xml = new ilXmlWriter();
         foreach ($items as $record_id => $record_items) {
             // no need to state record id here
             $xml->xmlStartTag('AdvancedMetaData');
             foreach ($record_items as $item) {
                 $xml->xmlElement('Value', array('id' => $item['id'], 'sub_type' => $item['sub_type'], 'sub_id' => $item['sub_id']), $item['value']);
             }
             $xml->xmlEndTag('AdvancedMetaData');
         }
         return $xml->xmlDumpMem(false);
     }
 }
 /**
  * Write xml of template action
  * @param ilXmlWriter $writer
  */
 public function toXml(ilXmlWriter $writer)
 {
     $writer->xmlStartTag('localRoleAction');
     $il_id = 'il_' . IL_INST_ID . '_' . ilObject::_lookupType($this->getRoleTemplateId()) . '_' . $this->getRoleTemplateId();
     $writer->xmlStartTag('roleTemplate', array('id' => $il_id));
     include_once './Services/AccessControl/classes/class.ilRoleXmlExport.php';
     $exp = new ilRoleXmlExport();
     $exp->setMode(ilRoleXmlExport::MODE_DTPL);
     $exp->addRole($this->getRoleTemplateId(), ROLE_FOLDER_ID);
     $exp->write();
     $writer->appendXML($exp->xmlDumpMem(FALSE));
     $writer->xmlEndTag('roleTemplate');
     $writer->xmlEndTag('localRoleAction');
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, SINGLE_CHOICE_QUESTION_IDENTIFIER);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // additional content editing information
     $this->addAdditionalContentEditingModeInformation($a_xml_writer);
     $this->addGeneralMetadata($a_xml_writer);
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "thumb_size");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getThumbSize());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     $attrs = array();
     $attrs = array("ident" => "MCSR", "rcardinality" => "Single");
     $a_xml_writer->xmlStartTag("response_lid", $attrs);
     $solution = $this->object->getSuggestedSolution(0);
     if (count($solution)) {
         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
             $a_xml_writer->xmlStartTag("material");
             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
             if (strcmp($matches[1], "") != 0) {
                 $intlink = $solution["internal_link"];
             }
             $attrs = array("label" => "suggested_solution");
             $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
             $a_xml_writer->xmlEndTag("material");
         }
     }
     // shuffle output
     $attrs = array();
     if ($this->object->getShuffle()) {
         $attrs = array("shuffle" => "Yes");
     } else {
         $attrs = array("shuffle" => "No");
     }
     $a_xml_writer->xmlStartTag("render_choice", $attrs);
     $answers =& $this->object->getAnswers();
     $akeys = array_keys($answers);
     if ($this->object->getShuffle() && $a_shuffle) {
         $akeys = $this->object->pcArrayShuffle($akeys);
     }
     // add answers
     foreach ($akeys as $index) {
         $answer = $answers[$index];
         $attrs = array("ident" => $index);
         $a_xml_writer->xmlStartTag("response_label", $attrs);
         if (strlen($answer->getImage())) {
             $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), FALSE, FALSE);
             $imagetype = "image/jpeg";
             if (preg_match("/.*\\.(png|gif)\$/", $answer->getImage(), $matches)) {
                 $imagetype = "image/" . $matches[1];
             }
             if ($force_image_references) {
                 $attrs = array("imagtype" => $imagetype, "label" => $answer->getImage(), "uri" => $this->object->getImagePathWeb() . $answer->getImage());
                 $a_xml_writer->xmlElement("matimage", $attrs);
             } else {
                 $imagepath = $this->object->getImagePath() . $answer->getImage();
                 $fh = @fopen($imagepath, "rb");
                 if ($fh != false) {
                     $imagefile = fread($fh, filesize($imagepath));
                     fclose($fh);
                     $base64 = base64_encode($imagefile);
                     $attrs = array("imagtype" => $imagetype, "label" => $answer->getImage(), "embedded" => "base64");
                     $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
                 }
             }
             $a_xml_writer->xmlEndTag("material");
         } else {
             $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
         }
         $a_xml_writer->xmlEndTag("response_label");
     }
     $a_xml_writer->xmlEndTag("render_choice");
     $a_xml_writer->xmlEndTag("response_lid");
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $a_xml_writer->xmlStartTag("resprocessing");
     $a_xml_writer->xmlStartTag("outcomes");
     $a_xml_writer->xmlStartTag("decvar");
     $a_xml_writer->xmlEndTag("decvar");
     $a_xml_writer->xmlEndTag("outcomes");
     // add response conditions
     foreach ($answers as $index => $answer) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $attrs = array();
         $attrs = array("respident" => "MCSR");
         $a_xml_writer->xmlElement("varequal", $attrs, $index);
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti setvar
         $attrs = array("action" => "Add");
         $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
         // qti displayfeedback
         $linkrefid = "response_{$index}";
         $attrs = array("feedbacktype" => "Response", "linkrefid" => $linkrefid);
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), true);
     if (strlen($feedback_allcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $bestindex = 0;
         $maxpoints = 0;
         foreach ($answers as $index => $answer) {
             if ($answer->getPoints() > $maxpoints) {
                 $maxpoints = $answer->getPoints();
                 $bestindex = $index;
             }
         }
         $attrs = array("respident" => "MCSR");
         $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), false);
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $bestindex = 0;
         $maxpoints = 0;
         foreach ($answers as $index => $answer) {
             if ($answer->getPoints() > $maxpoints) {
                 $maxpoints = $answer->getPoints();
                 $bestindex = $index;
             }
         }
         $attrs = array("respident" => "MCSR");
         $a_xml_writer->xmlStartTag("not");
         $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
         $a_xml_writer->xmlEndTag("not");
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $a_xml_writer->xmlEndTag("resprocessing");
     // PART III: qti itemfeedback
     foreach ($answers as $index => $answer) {
         $linkrefid = "response_{$index}";
         $attrs = array("ident" => $linkrefid, "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->object->getId(), $index);
         $this->object->addQTIMaterial($a_xml_writer, $fb);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getQuestionType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     //
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "option_string");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getOptionString());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     //
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "sample_solution");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getSampleSolution());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART III: qti itemfeedback
     $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), true);
     $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), false);
     $attrs = array("ident" => "Correct", "view" => "All");
     $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
     // qti flow_mat
     $a_xml_writer->xmlStartTag("flow_mat");
     $a_xml_writer->xmlStartTag("material");
     $a_xml_writer->xmlElement("mattext");
     $a_xml_writer->xmlEndTag("material");
     $a_xml_writer->xmlEndTag("flow_mat");
     $a_xml_writer->xmlEndTag("itemfeedback");
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getQuestionType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "maxsize");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getMaxSize());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "allowedextensions");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAllowedExtensions());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     $this->exportFeedbackOnly($a_xml_writer);
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getQuestionType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // additional content editing information
     $this->addAdditionalContentEditingModeInformation($a_xml_writer);
     $this->addGeneralMetadata($a_xml_writer);
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "width");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getWidth());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "height");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getHeight());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "applet");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getApplet());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "swf");
     $flashpath = $this->object->getFlashPath() . $this->object->getApplet();
     $fh = @fopen($flashpath, "rb");
     $base64 = "";
     if ($fh != FALSE) {
         $flashfile = fread($fh, filesize($flashpath));
         fclose($fh);
         $base64 = base64_encode($flashfile);
     }
     $a_xml_writer->xmlElement("fieldentry", NULL, $base64);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "params");
     $a_xml_writer->xmlElement("fieldentry", NULL, serialize($this->object->getParameters()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     $this->exportFeedbackOnly($a_xml_writer);
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
Example #19
0
 function exportScorm($a_inst, $a_target_dir, $ver, &$expLog)
 {
     copy('./xml/ilias_co_3_7.dtd', $a_target_dir . '/ilias_co_3_7.dtd');
     copy('./Modules/Scorm2004/templates/xsl/sco.xsl', $a_target_dir . '/sco.xsl');
     $a_xml_writer = new ilXmlWriter();
     // MetaData
     //file_put_contents($a_target_dir.'/indexMD.xml','<lom xmlns="http://ltsc.ieee.org/xsd/LOM"><general/><classification/></lom>');
     $this->exportXMLMetaData($a_xml_writer);
     $metadata_xml = $a_xml_writer->xmlDumpMem(false);
     $a_xml_writer->_XmlWriter;
     $xsl = file_get_contents("./Modules/Scorm2004/templates/xsl/metadata.xsl");
     $args = array('/_xml' => $metadata_xml, '/_xsl' => $xsl);
     $xh = xslt_create();
     $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
     xslt_free($xh);
     file_put_contents($a_target_dir . '/indexMD.xml', $output);
     $a_xml_writer = new ilXmlWriter();
     // set dtd definition
     $a_xml_writer->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.de/download/dtd/ilias_co_3_7.dtd\">");
     // set generated comment
     $a_xml_writer->xmlSetGenCmt("Export of ILIAS Content Module " . $this->getId() . " of installation " . $a_inst . ".");
     // set xml header
     $a_xml_writer->xmlHeader();
     global $ilBench;
     $a_xml_writer->xmlStartTag("ContentObject", array("Type" => "SCORM2004SCO"));
     $this->exportXMLMetaData($a_xml_writer);
     $this->exportXMLPageObjects($a_target_dir, $a_xml_writer, $a_inst, $expLog);
     $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
     $this->exportHTML($a_inst, $a_target_dir, $expLog);
     //overwrite scorm.js for scrom 1.2
     if ($ver == "12") {
         copy('./Modules/Scorm2004/scripts/scorm_12.js', $a_target_dir . '/js/scorm.js');
     }
     $a_xml_writer->xmlEndTag("ContentObject");
     $a_xml_writer->xmlDumpFile($a_target_dir . '/index.xml', false);
     $a_xml_writer->_XmlWriter;
     // export sco data (currently only objective) to sco.xml
     if ($this->getType() == "sco") {
         $objectives_text = "";
         $a_xml_writer = new ilXmlWriter();
         $tr_data = $this->getObjectives();
         foreach ($tr_data as $data) {
             $objectives_text .= $data->getObjectiveID();
         }
         $a_xml_writer->xmlStartTag("sco");
         $a_xml_writer->xmlElement("objective", null, $objectives_text);
         $a_xml_writer->xmlEndTag("sco");
         $a_xml_writer->xmlDumpFile($a_target_dir . '/sco.xml', false);
         $a_xml_writer->_XmlWriter;
     }
 }
 /**
  * Write link XML
  * @param ilXmlWriter $writer
  * @return 
  */
 public function toXML(ilXmlWriter $writer)
 {
     foreach (self::getAllItemIds($this->getLinkResourceId()) as $link_id) {
         $link = self::lookupItem($this->getLinkResourceId(), $link_id);
         $writer->xmlStartTag('WebLink', array('id' => $link['link_id'], 'active' => $link['active'] ? 1 : 0, 'valid' => $link['valid'] ? 1 : 0, 'disableValidation' => $link['disable_check'] ? 1 : 0));
         $writer->xmlElement('Title', array(), $link['title']);
         $writer->xmlElement('Description', array(), $link['description']);
         $writer->xmlElement('Target', array(), $link['target']);
         // Dynamic parameters
         include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
         foreach (ilParameterAppender::_getParams($link_id) as $param_id => $param) {
             $value = '';
             switch ($param['value']) {
                 case LINKS_USER_ID:
                     $value = 'userId';
                     break;
                 case LINKS_LOGIN:
                     $value = 'userName';
                     break;
                 case LINKS_MATRICULATION:
                     $value = 'matriculation';
                     break;
             }
             if (!$value) {
                 // Fix for deprecated LINKS_SESSION
                 continue;
             }
             $writer->xmlElement('DynamicParameter', array('id' => $param_id, 'name' => $param['name'], 'type' => $value));
         }
         $writer->xmlEndTag('WebLink');
     }
     return true;
 }
Example #21
0
 /**
  * 
  * @param object $a_table
  * @param object $a_file [optional]
  * @return 
  */
 function buildInsertStatementsXML($a_table, $a_basedir)
 {
     global $ilLog;
     include_once './Services/Xml/classes/class.ilXmlWriter.php';
     $w = new ilXmlWriter();
     $w->xmlStartTag('Table', array('name' => $a_table));
     $set = $this->il_db->query("SELECT * FROM `" . $a_table . "`");
     $ins_st = "";
     $first = true;
     while ($rec = $this->il_db->fetchAssoc($set)) {
         #$ilLog->write('Num: '.$num++);
         $w->xmlStartTag('Row');
         $fields = array();
         $types = array();
         $values = array();
         foreach ($rec as $f => $v) {
             if ($this->fields[$f]['type'] == 'text' and $this->fields[$f]['length'] >= 1000) {
                 $v = $this->shortenText($a_table, $f, $v, $this->fields[$f]['length']);
             }
             $w->xmlElement('Value', array('name' => $f, 'type' => $this->fields[$f]['type']), $v);
         }
         $w->xmlEndTag('Row');
     }
     $w->xmlEndTag('Table');
     $w->xmlDumpFile($a_basedir . '/' . $a_table . '.xml', FALSE);
 }
Example #22
0
 public static function _exportContainerSettings(ilXmlWriter $a_xml, $a_obj_id)
 {
     // container settings
     $settings = self::_getContainerSettings($a_obj_id);
     if (sizeof($settings)) {
         $a_xml->xmlStartTag("ContainerSettings");
         foreach ($settings as $keyword => $value) {
             // :TODO: proper custom icon export/import
             if (stristr($keyword, "icon")) {
                 continue;
             }
             $a_xml->xmlStartTag('ContainerSetting', array('id' => $keyword));
             $a_xml->xmlData($value);
             $a_xml->xmlEndTag("ContainerSetting");
         }
         $a_xml->xmlEndTag("ContainerSettings");
     }
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, JAVAAPPLET_QUESTION_IDENTIFIER);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     $solution = $this->object->getSuggestedSolution(0);
     if (count($solution)) {
         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
             $a_xml_writer->xmlStartTag("material");
             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
             if (strcmp($matches[1], "") != 0) {
                 $intlink = $solution["internal_link"];
             }
             $attrs = array("label" => "suggested_solution");
             $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
             $a_xml_writer->xmlEndTag("material");
         }
     }
     $a_xml_writer->xmlStartTag("material");
     $attrs = array("label" => "applet data", "uri" => $this->object->getJavaAppletFilename(), "height" => $this->object->getJavaHeight(), "width" => $this->object->getJavaWidth(), "embedded" => "base64");
     $javapath = $this->object->getJavaPath() . $this->object->getJavaAppletFilename();
     $fh = @fopen($javapath, "rb");
     if ($fh == false) {
         return;
     }
     $javafile = fread($fh, filesize($javapath));
     fclose($fh);
     $base64 = base64_encode($javafile);
     $a_xml_writer->xmlElement("matapplet", $attrs, $base64);
     if ($this->object->buildParamsOnly()) {
         if ($this->object->getJavaCode()) {
             $attrs = array("label" => "java_code");
             $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCode());
         }
         if ($this->object->getJavaCodebase()) {
             $attrs = array("label" => "java_codebase");
             $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCodebase());
         }
         if ($this->object->getJavaArchive()) {
             $attrs = array("label" => "java_archive");
             $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaArchive());
         }
         for ($i = 0; $i < $this->object->getParameterCount(); $i++) {
             $param = $this->object->getParameter($i);
             $attrs = array("label" => $param["name"]);
             $a_xml_writer->xmlElement("mattext", $attrs, $param["value"]);
         }
     }
     $a_xml_writer->xmlEndTag("material");
     $a_xml_writer->xmlStartTag("material");
     $attrs = array("label" => "points");
     $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getPoints());
     $a_xml_writer->xmlEndTag("material");
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
     $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
     if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
         $a_xml_writer->xmlStartTag("resprocessing");
         $a_xml_writer->xmlStartTag("outcomes");
         $a_xml_writer->xmlStartTag("decvar");
         $a_xml_writer->xmlEndTag("decvar");
         $a_xml_writer->xmlEndTag("outcomes");
         if (strlen($feedback_allcorrect)) {
             $attrs = array("continue" => "Yes");
             $a_xml_writer->xmlStartTag("respcondition", $attrs);
             // qti conditionvar
             $a_xml_writer->xmlStartTag("conditionvar");
             $attrs = array("respident" => "points");
             $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
             $a_xml_writer->xmlEndTag("conditionvar");
             // qti displayfeedback
             $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect");
             $a_xml_writer->xmlElement("displayfeedback", $attrs);
             $a_xml_writer->xmlEndTag("respcondition");
         }
         if (strlen($feedback_onenotcorrect)) {
             $attrs = array("continue" => "Yes");
             $a_xml_writer->xmlStartTag("respcondition", $attrs);
             // qti conditionvar
             $a_xml_writer->xmlStartTag("conditionvar");
             $a_xml_writer->xmlStartTag("not");
             $attrs = array("respident" => "points");
             $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
             $a_xml_writer->xmlEndTag("not");
             $a_xml_writer->xmlEndTag("conditionvar");
             // qti displayfeedback
             $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect");
             $a_xml_writer->xmlElement("displayfeedback", $attrs);
             $a_xml_writer->xmlEndTag("respcondition");
         }
         $a_xml_writer->xmlEndTag("resprocessing");
     }
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the test
  *
  * @return string The QTI xml representation of the test
  * @access public
  */
 function toXML()
 {
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlSetDtdDef("<!DOCTYPE questestinterop SYSTEM \"ims_qtiasiv1p2p1.dtd\">");
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_tst_" . $this->getTestId(), "title" => $this->getTitle());
     $a_xml_writer->xmlStartTag("assessment", $attrs);
     // add qti comment
     $a_xml_writer->xmlElement("qticomment", NULL, $this->getDescription());
     // add qti duration
     if ($this->enable_processing_time) {
         preg_match("/(\\d+):(\\d+):(\\d+)/", $this->processing_time, $matches);
         $a_xml_writer->xmlElement("duration", NULL, sprintf("P0Y0M0DT%dH%dM%dS", $matches[1], $matches[2], $matches[3]));
     }
     // add the rest of the preferences in qtimetadata tags, because there is no correspondent definition in QTI
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // anonymity
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "anonymity");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getAnonymity()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // random test
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "random_test");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->isRandomTest()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // sequence settings
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "sequence_settings");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getSequenceSettings());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // author
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "author");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // reset processing time
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "reset_processing_time");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getResetProcessingTime());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // count system
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "count_system");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getCountSystem());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // multiple choice scoring
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "mc_scoring");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getMCScoring());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // multiple choice scoring
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "score_cutting");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getScoreCutting());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // multiple choice scoring
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "password");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getPassword());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // allowed users
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "allowedUsers");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAllowedUsers());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // allowed users time gap
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "allowedUsersTimeGap");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAllowedUsersTimeGap());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // pass scoring
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "pass_scoring");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getPassScoring());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // score reporting date
     if ($this->getReportingDate()) {
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, "reporting_date");
         preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $this->reporting_date, $matches);
         $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("P%dY%dM%dDT%dH%dM%dS", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     // number of tries
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "nr_of_tries");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getNrOfTries()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // kiosk
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "kiosk");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getKiosk()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // use previous answers
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "use_previous_answers");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getUsePreviousAnswers());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // hide title points
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "title_output");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getTitleOutput()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // random question count
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "random_question_count");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getRandomQuestionCount()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // results presentation
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "results_presentation");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getResultsPresentation()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // solution details
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_summary");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getListOfQuestionsSettings()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // solution details
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "score_reporting");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getScoreReporting()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // solution details
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "instant_verification");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getInstantFeedbackSolution()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // answer specific feedback
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "answer_feedback");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getAnswerFeedback()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // answer specific feedback of reached points
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "answer_feedback_points");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getAnswerFeedbackPoints()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show cancel
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_cancel");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShowCancel()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show marker
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_marker");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShowMarker()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // fixed participants
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "fixed_participants");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getFixedParticipants()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show final statement
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "showfinalstatement");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShowFinalStatement() ? "1" : "0"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show introduction only
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "showinfo");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShowInfo() ? "1" : "0"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // mail notification
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "mailnotification");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getMailNotification());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // mail notification type
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "mailnottype");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getMailNotificationType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // export settings
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "exportsettings");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getExportSettings());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // force JavaScript
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "forcejs");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getForceJS() ? "1" : "0"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // custom style
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "customstyle");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getCustomStyle());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // shuffle questions
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "shuffle_questions");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShuffleQuestions()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // processing time
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "processing_time");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getProcessingTime());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // starting time
     if ($this->getStartingTime()) {
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, "starting_time");
         preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $this->starting_time, $matches);
         $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("P%dY%dM%dDT%dH%dM%dS", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     // ending time
     if ($this->getEndingTime()) {
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, "ending_time");
         preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $this->ending_time, $matches);
         $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("P%dY%dM%dDT%dH%dM%dS", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     foreach ($this->mark_schema->mark_steps as $index => $mark) {
         // mark steps
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, "mark_step_{$index}");
         $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("<short>%s</short><official>%s</official><percentage>%.2f</percentage><passed>%d</passed>", $mark->getShortName(), $mark->getOfficialName(), $mark->getMinimumLevel(), $mark->getPassed()));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     $a_xml_writer->xmlEndTag("qtimetadata");
     // add qti objectives
     $a_xml_writer->xmlStartTag("objectives");
     $this->addQTIMaterial($a_xml_writer, $this->getIntroduction());
     $a_xml_writer->xmlEndTag("objectives");
     // add qti assessmentcontrol
     if ($this->getInstantFeedbackSolution() == 1) {
         $attrs = array("solutionswitch" => "Yes");
     } else {
         $attrs = NULL;
     }
     $a_xml_writer->xmlElement("assessmentcontrol", $attrs, NULL);
     if (strlen($this->getFinalStatement())) {
         // add qti presentation_material
         $a_xml_writer->xmlStartTag("presentation_material");
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->addQTIMaterial($a_xml_writer, $this->getFinalStatement());
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("presentation_material");
     }
     $attrs = array("ident" => "1");
     $a_xml_writer->xmlElement("section", $attrs, NULL);
     $a_xml_writer->xmlEndTag("assessment");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     foreach ($this->questions as $question_id) {
         $question =& ilObjTest::_instanciateQuestion($question_id);
         $qti_question = $question->toXML(false);
         $qti_question = preg_replace("/<questestinterop>/", "", $qti_question);
         $qti_question = preg_replace("/<\\/questestinterop>/", "", $qti_question);
         if (strpos($xml, "</section>") !== false) {
             $xml = str_replace("</section>", "{$qti_question}</section>", $xml);
         } else {
             $xml = str_replace("<section ident=\"1\"/>", "<section ident=\"1\">\n{$qti_question}</section>", $xml);
         }
     }
     return $xml;
 }
Example #25
0
 /**
  * Returns a QTI xml representation of the test
  *
  * @return string The QTI xml representation of the test
  */
 public function toXML()
 {
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlSetDtdDef("<!DOCTYPE questestinterop SYSTEM \"ims_qtiasiv1p2p1.dtd\">");
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_tst_" . $this->getTestId(), "title" => $this->getTitle());
     $a_xml_writer->xmlStartTag("assessment", $attrs);
     // add qti comment
     $a_xml_writer->xmlElement("qticomment", NULL, $this->getDescription());
     // add qti duration
     if ($this->enable_processing_time) {
         preg_match("/(\\d+):(\\d+):(\\d+)/", $this->processing_time, $matches);
         $a_xml_writer->xmlElement("duration", NULL, sprintf("P0Y0M0DT%dH%dM%dS", $matches[1], $matches[2], $matches[3]));
     }
     // add the rest of the preferences in qtimetadata tags, because there is no correspondent definition in QTI
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // anonymity
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "anonymity");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getAnonymity()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // question set type (fixed, random, dynamic, ...)
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "question_set_type");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getQuestionSetType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // sequence settings
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "sequence_settings");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getSequenceSettings());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // author
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "author");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // reset processing time
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "reset_processing_time");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getResetProcessingTime());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // count system
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "count_system");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getCountSystem());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // multiple choice scoring
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "mc_scoring");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getMCScoring());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // multiple choice scoring
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "score_cutting");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getScoreCutting());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // multiple choice scoring
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "password");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getPassword());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // allowed users
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "allowedUsers");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAllowedUsers());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // allowed users time gap
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "allowedUsersTimeGap");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAllowedUsersTimeGap());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // pass scoring
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "pass_scoring");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getPassScoring());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // score reporting date
     if ($this->getReportingDate()) {
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, "reporting_date");
         preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $this->reporting_date, $matches);
         $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("P%dY%dM%dDT%dH%dM%dS", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     // number of tries
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "nr_of_tries");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getNrOfTries()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // kiosk
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "kiosk");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getKiosk()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     //redirection_mode
     $a_xml_writer->xmlStartTag('qtimetadatafield');
     $a_xml_writer->xmlElement("fieldlabel", NULL, "redirection_mode");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getRedirectionMode());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     //redirection_url
     $a_xml_writer->xmlStartTag('qtimetadatafield');
     $a_xml_writer->xmlElement("fieldlabel", NULL, "redirection_url");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getRedirectionUrl());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // use previous answers
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "use_previous_answers");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getUsePreviousAnswers());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // hide title points
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "title_output");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getTitleOutput()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // results presentation
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "results_presentation");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getResultsPresentation()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // examid in test pass
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "examid_in_test_pass");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->isShowExamIdInTestPassEnabled()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // examid in kiosk
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "examid_in_test_res");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->isShowExamIdInTestResultsEnabled()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // solution details
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_summary");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getListOfQuestionsSettings()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // solution details
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "score_reporting");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getScoreReporting()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // solution details
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "instant_verification");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getInstantFeedbackSolution()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // answer specific feedback
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "answer_feedback");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getAnswerFeedback()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // answer specific feedback of reached points
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "answer_feedback_points");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getAnswerFeedbackPoints()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // highscore
     $highscore_metadata = array('highscore_enabled' => array('value' => $this->getHighscoreEnabled()), 'highscore_anon' => array('value' => $this->getHighscoreAnon()), 'highscore_achieved_ts' => array('value' => $this->getHighscoreAchievedTS()), 'highscore_score' => array('value' => $this->getHighscoreScore()), 'highscore_percentage' => array('value' => $this->getHighscorePercentage()), 'highscore_hints' => array('value' => $this->getHighscoreHints()), 'highscore_wtime' => array('value' => $this->getHighscoreWTime()), 'highscore_own_table' => array('value' => $this->getHighscoreOwnTable()), 'highscore_top_table' => array('value' => $this->getHighscoreTopTable()), 'highscore_top_num' => array('value' => $this->getHighscoreTopNum()));
     foreach ($highscore_metadata as $label => $data) {
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, $label);
         $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $data['value']));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     // show cancel
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_cancel");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShowCancel()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show marker
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_marker");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShowMarker()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // fixed participants
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "fixed_participants");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getFixedParticipants()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show final statement
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "showfinalstatement");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShowFinalStatement() ? "1" : "0"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show introduction only
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "showinfo");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShowInfo() ? "1" : "0"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // mail notification
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "mailnotification");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getMailNotification());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // mail notification type
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "mailnottype");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getMailNotificationType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // export settings
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "exportsettings");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getExportSettings());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // force JavaScript
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "forcejs");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getForceJS() ? "1" : "0"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // custom style
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "customstyle");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getCustomStyle());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // shuffle questions
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "shuffle_questions");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getShuffleQuestions()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // processing time
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "processing_time");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getProcessingTime());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // enable_examview
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "enable_examview");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getEnableExamview());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show_examview_html
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_examview_html");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getShowExamviewHtml());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show_examview_pdf
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_examview_pdf");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getShowExamviewPdf());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // enable_archiving
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "enable_archiving");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getEnableArchiving());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // sign_submission
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "sign_submission");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getSignSubmission());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // char_selector_availability
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "char_selector_availability");
     $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("%d", $this->getCharSelectorAvailability()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // char_selector_definition
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "char_selector_definition");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getCharSelectorDefinition());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // skill_service
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "skill_service");
     $a_xml_writer->xmlElement("fieldentry", NULL, (int) $this->isSkillServiceEnabled());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // result_tax_filters
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "result_tax_filters");
     $a_xml_writer->xmlElement("fieldentry", NULL, serialize((array) $this->getResultFilterTaxIds()));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show_grading_status
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_grading_status");
     $a_xml_writer->xmlElement("fieldentry", NULL, (int) $this->isShowGradingStatusEnabled());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // show_grading_mark
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "show_grading_mark");
     $a_xml_writer->xmlElement("fieldentry", NULL, (int) $this->isShowGradingMarkEnabled());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // starting time
     if ($this->getStartingTime()) {
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, "starting_time");
         preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $this->starting_time, $matches);
         $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("P%dY%dM%dDT%dH%dM%dS", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     // ending time
     if ($this->getEndingTime()) {
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, "ending_time");
         preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $this->ending_time, $matches);
         $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("P%dY%dM%dDT%dH%dM%dS", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     foreach ($this->mark_schema->mark_steps as $index => $mark) {
         // mark steps
         $a_xml_writer->xmlStartTag("qtimetadatafield");
         $a_xml_writer->xmlElement("fieldlabel", NULL, "mark_step_{$index}");
         $a_xml_writer->xmlElement("fieldentry", NULL, sprintf("<short>%s</short><official>%s</official><percentage>%.2f</percentage><passed>%d</passed>", $mark->getShortName(), $mark->getOfficialName(), $mark->getMinimumLevel(), $mark->getPassed()));
         $a_xml_writer->xmlEndTag("qtimetadatafield");
     }
     $a_xml_writer->xmlEndTag("qtimetadata");
     // add qti objectives
     $a_xml_writer->xmlStartTag("objectives");
     $this->addQTIMaterial($a_xml_writer, $this->getIntroduction());
     $a_xml_writer->xmlEndTag("objectives");
     // add qti assessmentcontrol
     if ($this->getInstantFeedbackSolution() == 1) {
         $attrs = array("solutionswitch" => "Yes");
     } else {
         $attrs = NULL;
     }
     $a_xml_writer->xmlElement("assessmentcontrol", $attrs, NULL);
     if (strlen($this->getFinalStatement())) {
         // add qti presentation_material
         $a_xml_writer->xmlStartTag("presentation_material");
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->addQTIMaterial($a_xml_writer, $this->getFinalStatement());
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("presentation_material");
     }
     $attrs = array("ident" => "1");
     $a_xml_writer->xmlElement("section", $attrs, NULL);
     $a_xml_writer->xmlEndTag("assessment");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     foreach ($this->questions as $question_id) {
         $question =& ilObjTest::_instanciateQuestion($question_id);
         $qti_question = $question->toXML(false);
         $qti_question = preg_replace("/<questestinterop>/", "", $qti_question);
         $qti_question = preg_replace("/<\\/questestinterop>/", "", $qti_question);
         if (strpos($xml, "</section>") !== false) {
             $xml = str_replace("</section>", "{$qti_question}</section>", $xml);
         } else {
             $xml = str_replace("<section ident=\"1\"/>", "<section ident=\"1\">\n{$qti_question}</section>", $xml);
         }
     }
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, TEXT_QUESTION_IDENTIFIER);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "textrating");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextRating());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     /*
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "keywords");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getKeywords());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     */
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "matchcondition");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->matchcondition);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "termscoring");
     $scores = serialize($this->object->getAnswers());
     $a_xml_writer->xmlElement("fieldentry", NULL, $scores);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "termrelation");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getKeywordRelation());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "specificfeedback");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getKeywordRelation());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add information on response rendering
     $attrs = array("ident" => "TEXT", "rcardinality" => "Ordered");
     $a_xml_writer->xmlStartTag("response_str", $attrs);
     $attrs = array("fibtype" => "String", "prompt" => "Box");
     if ($this->object->getMaxNumOfChars() > 0) {
         $attrs["maxchars"] = $this->object->getMaxNumOfChars();
     }
     $a_xml_writer->xmlStartTag("render_fib", $attrs);
     $attrs = array("ident" => "A");
     $a_xml_writer->xmlStartTag("response_label", $attrs);
     $a_xml_writer->xmlEndTag("response_label");
     $a_xml_writer->xmlEndTag("render_fib");
     $solution = $this->object->getSuggestedSolution(0);
     if (count($solution)) {
         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
             $a_xml_writer->xmlStartTag("material");
             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
             if (strcmp($matches[1], "") != 0) {
                 $intlink = $solution["internal_link"];
             }
             $attrs = array("label" => "suggested_solution");
             $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
             $a_xml_writer->xmlEndTag("material");
         }
     }
     $a_xml_writer->xmlEndTag("response_str");
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $attrs = array("scoremodel" => "HumanRater");
     $a_xml_writer->xmlStartTag("resprocessing", $attrs);
     $a_xml_writer->xmlStartTag("outcomes");
     $attrs = array("varname" => "WritingScore", "vartype" => "Integer", "minvalue" => "0", "maxvalue" => $this->object->getPoints());
     $a_xml_writer->xmlStartTag("decvar", $attrs);
     $a_xml_writer->xmlEndTag("decvar");
     $a_xml_writer->xmlEndTag("outcomes");
     $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
     $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
     if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
         if (strlen($feedback_allcorrect)) {
             $attrs = array("continue" => "Yes");
             $a_xml_writer->xmlStartTag("respcondition", $attrs);
             // qti conditionvar
             $a_xml_writer->xmlStartTag("conditionvar");
             $attrs = array("respident" => "points");
             $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
             $a_xml_writer->xmlEndTag("conditionvar");
             // qti displayfeedback
             $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect");
             $a_xml_writer->xmlElement("displayfeedback", $attrs);
             $a_xml_writer->xmlEndTag("respcondition");
         }
         if (strlen($feedback_onenotcorrect)) {
             $attrs = array("continue" => "Yes");
             $a_xml_writer->xmlStartTag("respcondition", $attrs);
             // qti conditionvar
             $a_xml_writer->xmlStartTag("conditionvar");
             $a_xml_writer->xmlStartTag("not");
             $attrs = array("respident" => "points");
             $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
             $a_xml_writer->xmlEndTag("not");
             $a_xml_writer->xmlEndTag("conditionvar");
             // qti displayfeedback
             $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect");
             $a_xml_writer->xmlElement("displayfeedback", $attrs);
             $a_xml_writer->xmlEndTag("respcondition");
         }
     }
     $a_xml_writer->xmlStartTag("respcondition");
     $a_xml_writer->xmlStartTag("conditionvar");
     $a_xml_writer->xmlElement("other", NULL, "tutor_rated");
     $a_xml_writer->xmlEndTag("conditionvar");
     $a_xml_writer->xmlEndTag("respcondition");
     $a_xml_writer->xmlEndTag("resprocessing");
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getQuestionType());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "textrating");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextRating());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "requestedanswers");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getCorrectAnswers());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     // removed additional metadata from assFormulaQuestion
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     $attrs = array();
     $attrs = array("ident" => "SYNTAX TREE", "rcardinality" => "Multiple");
     $a_xml_writer->xmlStartTag("response_lid", $attrs);
     $solution = $this->object->getSuggestedSolution(0);
     if (count($solution)) {
         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
             $a_xml_writer->xmlStartTag("material");
             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
             if (strcmp($matches[1], "") != 0) {
                 $intlink = $solution["internal_link"];
             }
             $attrs = array("label" => "suggested_solution");
             $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
             $a_xml_writer->xmlEndTag("material");
         }
     }
     // shuffle output
     $attrs = array();
     $a_xml_writer->xmlStartTag("render_choice", $attrs);
     $answers =& $this->object->getAnswers();
     $akeys = array_keys($answers);
     if ($this->object->getShuffle() && $a_shuffle) {
         $akeys = $this->object->pcArrayShuffle($akeys);
     }
     // add answers
     foreach ($akeys as $index) {
         $answer = $answers[$index];
         $attrs = array("ident" => $index);
         $a_xml_writer->xmlStartTag("response_label", $attrs);
         $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
         $a_xml_writer->xmlEndTag("response_label");
     }
     $a_xml_writer->xmlEndTag("render_choice");
     $a_xml_writer->xmlEndTag("response_lid");
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $a_xml_writer->xmlStartTag("resprocessing");
     $a_xml_writer->xmlStartTag("outcomes");
     $a_xml_writer->xmlStartTag("decvar");
     $a_xml_writer->xmlEndTag("decvar");
     $a_xml_writer->xmlEndTag("outcomes");
     // add response conditions
     foreach ($answers as $index => $answer) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $attrs = array();
         $attrs = array("respident" => "SyntaxTree");
         $a_xml_writer->xmlElement("varequal", $attrs, $index);
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti setvar
         $attrs = array("action" => "Add");
         $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
         // qti displayfeedback
         $linkrefid = "response_{$index}";
         $attrs = array("feedbacktype" => "Response", "linkrefid" => $linkrefid);
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
     if (strlen($feedback_allcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $bestindex = 0;
         $maxpoints = 0;
         foreach ($answers as $index => $answer) {
             if ($answer->getPoints() > $maxpoints) {
                 $maxpoints = $answer->getPoints();
                 $bestindex = $index;
             }
         }
         $attrs = array("respident" => "SyntaxTree");
         $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $bestindex = 0;
         $maxpoints = 0;
         foreach ($answers as $index => $answer) {
             if ($answer->getPoints() > $maxpoints) {
                 $maxpoints = $answer->getPoints();
                 $bestindex = $index;
             }
         }
         $attrs = array("respident" => "SyntaxTree");
         $a_xml_writer->xmlStartTag("not");
         $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
         $a_xml_writer->xmlEndTag("not");
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $a_xml_writer->xmlEndTag("resprocessing");
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, MATCHING_QUESTION_IDENTIFIER);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     // additional content editing information
     $this->addAdditionalContentEditingModeInformation($a_xml_writer);
     $this->addGeneralMetadata($a_xml_writer);
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "shuffle");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getShuffle());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "thumb_geometry");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getThumbGeometry());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, 'matching_mode');
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getMatchingMode());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     $attrs = array("ident" => "MQ", "rcardinality" => "Multiple");
     $a_xml_writer->xmlStartTag("response_grp", $attrs);
     $solution = $this->object->getSuggestedSolution(0);
     if (count($solution)) {
         if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
             $a_xml_writer->xmlStartTag("material");
             $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
             if (strcmp($matches[1], "") != 0) {
                 $intlink = $solution["internal_link"];
             }
             $attrs = array("label" => "suggested_solution");
             $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
             $a_xml_writer->xmlEndTag("material");
         }
     }
     // shuffle output
     $attrs = array();
     if ($this->object->getShuffle()) {
         $attrs = array("shuffle" => "Yes");
     } else {
         $attrs = array("shuffle" => "No");
     }
     $a_xml_writer->xmlStartTag("render_choice", $attrs);
     // add answertext
     $matchingtext_orders = array();
     foreach ($this->object->getMatchingPairs() as $index => $matchingpair) {
         array_push($matchingtext_orders, $matchingpair->term->identifier);
     }
     $termids = array();
     foreach ($this->object->getTerms() as $term) {
         array_push($termids, $term->identifier);
     }
     // add answers
     foreach ($this->object->getDefinitions() as $definition) {
         $attrs = array("ident" => $definition->identifier, "match_max" => "1", "match_group" => join($termids, ","));
         $a_xml_writer->xmlStartTag("response_label", $attrs);
         $a_xml_writer->xmlStartTag("material");
         if (strlen($definition->picture)) {
             if ($force_image_references) {
                 $attrs = array("imagtype" => "image/jpeg", "label" => $definition->picture, "uri" => $this->object->getImagePathWeb() . $definition->picture);
                 $a_xml_writer->xmlElement("matimage", $attrs);
             } else {
                 $imagepath = $this->object->getImagePath() . $definition->picture;
                 $fh = @fopen($imagepath, "rb");
                 if ($fh != false) {
                     $imagefile = fread($fh, filesize($imagepath));
                     fclose($fh);
                     $base64 = base64_encode($imagefile);
                     $attrs = array("imagtype" => "image/jpeg", "label" => $definition->picture, "embedded" => "base64");
                     $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
                 }
             }
         }
         if (strlen($definition->text)) {
             $attrs = array("texttype" => "text/plain");
             if ($this->object->isHTML($definition->text)) {
                 $attrs["texttype"] = "text/xhtml";
             }
             $a_xml_writer->xmlElement("mattext", $attrs, $definition->text);
         }
         $a_xml_writer->xmlEndTag("material");
         $a_xml_writer->xmlEndTag("response_label");
     }
     // add matchingtext
     foreach ($this->object->getTerms() as $term) {
         $attrs = array("ident" => $term->identifier);
         $a_xml_writer->xmlStartTag("response_label", $attrs);
         $a_xml_writer->xmlStartTag("material");
         if (strlen($term->picture)) {
             if ($force_image_references) {
                 $attrs = array("imagtype" => "image/jpeg", "label" => $term->picture, "uri" => $this->object->getImagePathWeb() . $term->picture);
                 $a_xml_writer->xmlElement("matimage", $attrs);
             } else {
                 $imagepath = $this->object->getImagePath() . $term->picture;
                 $fh = @fopen($imagepath, "rb");
                 if ($fh != false) {
                     $imagefile = fread($fh, filesize($imagepath));
                     fclose($fh);
                     $base64 = base64_encode($imagefile);
                     $attrs = array("imagtype" => "image/jpeg", "label" => $term->picture, "embedded" => "base64");
                     $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
                 }
             }
         }
         if (strlen($term->text)) {
             $attrs = array("texttype" => "text/plain");
             if ($this->object->isHTML($term->text)) {
                 $attrs["texttype"] = "text/xhtml";
             }
             $a_xml_writer->xmlElement("mattext", $attrs, $term->text);
         }
         $a_xml_writer->xmlEndTag("material");
         $a_xml_writer->xmlEndTag("response_label");
     }
     $a_xml_writer->xmlEndTag("render_choice");
     $a_xml_writer->xmlEndTag("response_grp");
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $a_xml_writer->xmlStartTag("resprocessing");
     $a_xml_writer->xmlStartTag("outcomes");
     $a_xml_writer->xmlStartTag("decvar");
     $a_xml_writer->xmlEndTag("decvar");
     $a_xml_writer->xmlEndTag("outcomes");
     // add response conditions
     foreach ($this->object->getMatchingPairs() as $matchingpair) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $attrs = array("respident" => "MQ");
         $a_xml_writer->xmlElement("varsubset", $attrs, $matchingpair->term->identifier . "," . $matchingpair->definition->identifier);
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti setvar
         $attrs = array("action" => "Add");
         $a_xml_writer->xmlElement("setvar", $attrs, $matchingpair->points);
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "correct_" . $matchingpair->term->identifier . "_" . $matchingpair->definition_identifier);
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), true);
     if (strlen($feedback_allcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         foreach ($this->object->getMatchingPairs() as $matchingpair) {
             $attrs = array("respident" => "MQ");
             $a_xml_writer->xmlElement("varsubset", $attrs, $matchingpair->term->identifier . "," . $matchingpair->definition->identifier);
         }
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation($this->object->getId(), false);
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("continue" => "Yes");
         $a_xml_writer->xmlStartTag("respcondition", $attrs);
         // qti conditionvar
         $a_xml_writer->xmlStartTag("conditionvar");
         $a_xml_writer->xmlStartTag("not");
         foreach ($this->object->getMatchingPairs() as $matchingpair) {
             $attrs = array("respident" => "MQ");
             $a_xml_writer->xmlElement("varsubset", $attrs, $matchingpair->term->identifier . "," . $matchingpair->definition->identifier);
         }
         $a_xml_writer->xmlEndTag("not");
         $a_xml_writer->xmlEndTag("conditionvar");
         // qti displayfeedback
         $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect");
         $a_xml_writer->xmlElement("displayfeedback", $attrs);
         $a_xml_writer->xmlEndTag("respcondition");
     }
     $a_xml_writer->xmlEndTag("resprocessing");
     // PART III: qti itemfeedback
     foreach ($this->object->getMatchingPairs() as $matchingpair) {
         $attrs = array("ident" => "correct_" . $matchingpair->term->identifier . "_" . $matchingpair->definition->identifier, "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $a_xml_writer->xmlStartTag("material");
         $a_xml_writer->xmlElement("mattext");
         $a_xml_writer->xmlEndTag("material");
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the question
  *
  * Returns a QTI xml representation of the question and sets the internal
  * domxml variable with the DOM XML representation of the QTI xml representation
  *
  * @return string The QTI xml representation of the question
  * @access public
  */
 function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
 {
     global $ilias;
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $a_xml_writer->xmlStartTag("questestinterop");
     $attrs = array("ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(), "title" => $this->object->getTitle(), "maxattempts" => $this->object->getNrOfTries());
     $a_xml_writer->xmlStartTag("item", $attrs);
     // add question description
     $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
     // add estimated working time
     $workingtime = $this->object->getEstimatedWorkingTime();
     $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
     $a_xml_writer->xmlElement("duration", NULL, $duration);
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("itemmetadata");
     $a_xml_writer->xmlStartTag("qtimetadata");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
     $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
     $a_xml_writer->xmlElement("fieldentry", NULL, TEXTSUBSET_QUESTION_IDENTIFIER);
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "textrating");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextRating());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "correctanswers");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getCorrectAnswers());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlStartTag("qtimetadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
     $a_xml_writer->xmlEndTag("qtimetadatafield");
     $a_xml_writer->xmlEndTag("qtimetadata");
     $a_xml_writer->xmlEndTag("itemmetadata");
     // PART I: qti presentation
     $attrs = array("label" => $this->object->getTitle());
     $a_xml_writer->xmlStartTag("presentation", $attrs);
     // add flow to presentation
     $a_xml_writer->xmlStartTag("flow");
     // add material with question text to presentation
     $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
     // add answers to presentation
     for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++) {
         $attrs = array("ident" => "TEXTSUBSET_" . sprintf("%02d", $counter), "rcardinality" => "Single");
         $a_xml_writer->xmlStartTag("response_str", $attrs);
         $solution = $this->object->getSuggestedSolution(0);
         if (count($solution)) {
             if (preg_match("/il_(\\d*?)_(\\w+)_(\\d+)/", $solution["internal_link"], $matches)) {
                 $a_xml_writer->xmlStartTag("material");
                 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
                 if (strcmp($matches[1], "") != 0) {
                     $intlink = $solution["internal_link"];
                 }
                 $attrs = array("label" => "suggested_solution");
                 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
                 $a_xml_writer->xmlEndTag("material");
             }
         }
         // shuffle output
         $attrs = array("fibtype" => "String", "columns" => $this->object->getMaxTextboxWidth());
         $a_xml_writer->xmlStartTag("render_fib", $attrs);
         $a_xml_writer->xmlEndTag("render_fib");
         $a_xml_writer->xmlEndTag("response_str");
     }
     $a_xml_writer->xmlEndTag("flow");
     $a_xml_writer->xmlEndTag("presentation");
     // PART II: qti resprocessing
     $a_xml_writer->xmlStartTag("resprocessing");
     $a_xml_writer->xmlStartTag("outcomes");
     $a_xml_writer->xmlStartTag("decvar");
     $a_xml_writer->xmlEndTag("decvar");
     $attribs = array("varname" => "matches", "defaultval" => "0");
     $a_xml_writer->xmlElement("decvar", $attribs, NULL);
     $a_xml_writer->xmlEndTag("outcomes");
     // add response conditions
     for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++) {
         $scoregroups =& $this->object->joinAnswers();
         foreach ($scoregroups as $points => $scoreanswers) {
             $attrs = array("continue" => "Yes");
             $a_xml_writer->xmlStartTag("respcondition", $attrs);
             // qti conditionvar
             $a_xml_writer->xmlStartTag("conditionvar");
             $attrs = array("respident" => "TEXTSUBSET_" . sprintf("%02d", $counter));
             $a_xml_writer->xmlElement("varsubset", $attrs, join(",", $scoreanswers));
             $a_xml_writer->xmlEndTag("conditionvar");
             // qti setvar
             $attrs = array("varname" => "matches", "action" => "Add");
             $a_xml_writer->xmlElement("setvar", $attrs, $points);
             // qti displayfeedback
             $attrs = array("feedbacktype" => "Response", "linkrefid" => "Matches_" . sprintf("%02d", $counter));
             $a_xml_writer->xmlElement("displayfeedback", $attrs);
             $a_xml_writer->xmlEndTag("respcondition");
         }
     }
     $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
     $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
     if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
         if (strlen($feedback_allcorrect)) {
             $attrs = array("continue" => "Yes");
             $a_xml_writer->xmlStartTag("respcondition", $attrs);
             // qti conditionvar
             $a_xml_writer->xmlStartTag("conditionvar");
             $attrs = array("respident" => "points");
             $a_xml_writer->xmlElement("varsubset", $attrs, $this->object->getMaximumPoints());
             $a_xml_writer->xmlEndTag("conditionvar");
             // qti displayfeedback
             $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_allcorrect");
             $a_xml_writer->xmlElement("displayfeedback", $attrs);
             $a_xml_writer->xmlEndTag("respcondition");
         }
         if (strlen($feedback_onenotcorrect)) {
             $attrs = array("continue" => "Yes");
             $a_xml_writer->xmlStartTag("respcondition", $attrs);
             // qti conditionvar
             $a_xml_writer->xmlStartTag("conditionvar");
             $a_xml_writer->xmlStartTag("not");
             $attrs = array("respident" => "points");
             $a_xml_writer->xmlElement("varsubset", $attrs, $this->object->getMaximumPoints());
             $a_xml_writer->xmlEndTag("not");
             $a_xml_writer->xmlEndTag("conditionvar");
             // qti displayfeedback
             $attrs = array("feedbacktype" => "Response", "linkrefid" => "response_onenotcorrect");
             $a_xml_writer->xmlElement("displayfeedback", $attrs);
             $a_xml_writer->xmlEndTag("respcondition");
         }
     }
     $a_xml_writer->xmlEndTag("resprocessing");
     // PART III: qti itemfeedback
     for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++) {
         $attrs = array("ident" => "Matches_" . sprintf("%02d", $counter), "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $a_xml_writer->xmlStartTag("material");
         $a_xml_writer->xmlElement("mattext");
         $a_xml_writer->xmlEndTag("material");
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_allcorrect)) {
         $attrs = array("ident" => "response_allcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     if (strlen($feedback_onenotcorrect)) {
         $attrs = array("ident" => "response_onenotcorrect", "view" => "All");
         $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
         // qti flow_mat
         $a_xml_writer->xmlStartTag("flow_mat");
         $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
         $a_xml_writer->xmlEndTag("flow_mat");
         $a_xml_writer->xmlEndTag("itemfeedback");
     }
     $a_xml_writer->xmlEndTag("item");
     $a_xml_writer->xmlEndTag("questestinterop");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     if (!$a_include_header) {
         $pos = strpos($xml, "?>");
         $xml = substr($xml, $pos + 2);
     }
     return $xml;
 }
 /**
  * To Xml.
  * This method writes only the subset Field
  * Use class.ilAdvancedMDRecordXMLWriter to generate a complete xml presentation.
  *
  * @access public
  * @param object ilXmlWriter
  * 
  */
 public function toXML(ilXmlWriter $writer)
 {
     switch ($this->getFieldType()) {
         case self::TYPE_TEXT:
             $type = 'Text';
             break;
         case self::TYPE_SELECT:
             $type = 'Select';
             break;
         case self::TYPE_DATE:
             $type = 'Date';
             break;
         case self::TYPE_DATETIME:
             $type = 'DateTime';
             break;
     }
     $writer->xmlStartTag('Field', array('id' => $this->generateImportId(), 'searchable' => $this->isSearchable() ? 'Yes' : 'No', 'fieldType' => $type));
     $writer->xmlElement('FieldTitle', null, $this->getTitle());
     $writer->xmlElement('FieldDescription', null, $this->getDescription());
     $writer->xmlElement('FieldPosition', null, $this->getPosition());
     foreach ($this->getFieldValues() as $value) {
         if (strlen($value)) {
             $writer->xmlElement('FieldValue', null, $value);
         }
     }
     $writer->xmlEndTag('Field');
 }