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
{
global $ilias;
include_once "./Services/Math/classes/class.EvalMath.php";
$eval->suppress_errors = TRUE;
include_once("./Services/Xml/classes/class.ilXmlWriter.php");
$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);
$a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
$workingtime = $this->object->getEstimatedWorkingTime();
$duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
$a_xml_writer->xmlElement("duration", NULL, $duration);
$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->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, "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, "externalID");
$a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getExternalID());
$a_xml_writer->xmlEndTag("qtimetadatafield");
$a_xml_writer->xmlEndTag("qtimetadata");
$a_xml_writer->xmlEndTag("itemmetadata");
$attrs = array(
"label" => $this->object->getTitle()
);
$a_xml_writer->xmlStartTag("presentation", $attrs);
$a_xml_writer->xmlStartTag("flow");
$text_parts = preg_split("/\[gap.*?\[\/gap\]/", $this->object->getClozeText());
for ($i = 0; $i <= $this->object->getGapCount(); $i++)
{
if ($i == 0)
{
$this->object->addQTIMaterial($a_xml_writer, $text_parts[$i]);
}
else
{
$this->object->addQTIMaterial($a_xml_writer, $text_parts[$i], TRUE, FALSE);
}
if ($i < $this->object->getGapCount())
{
$gap = $this->object->getGap($i);
switch ($gap->getType())
{
$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);
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;
$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->getMaxWidth()
);
$a_xml_writer->xmlStartTag("render_fib", $attrs);
$a_xml_writer->xmlEndTag("render_fib");
$a_xml_writer->xmlEndTag("response_str");
break;
$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->getMaxWidth()
);
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");
$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");
for ($i = 0; $i < $this->object->getGapCount(); $i++)
{
$gap = $this->object->getGap($i);
switch ($gap->getType())
{
foreach ($gap->getItems() as $answer)
{
$attrs = array(
"continue" => "Yes"
);
$a_xml_writer->xmlStartTag("respcondition", $attrs);
$a_xml_writer->xmlStartTag("conditionvar");
$attrs = array(
"respident" => "gap_$i"
);
$a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
$a_xml_writer->xmlEndTag("conditionvar");
$attrs = array(
"action" => "Add"
);
$a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
$linkrefid = "";
$linkrefid = "$i" . "_Response_" . $answer->getOrder();
$attrs = array(
"feedbacktype" => "Response",
"linkrefid" => $linkrefid
);
$a_xml_writer->xmlElement("displayfeedback", $attrs);
$a_xml_writer->xmlEndTag("respcondition");
}
break;
foreach ($gap->getItems() as $answer)
{
$attrs = array(
"continue" => "Yes"
);
$a_xml_writer->xmlStartTag("respcondition", $attrs);
$a_xml_writer->xmlStartTag("conditionvar");
$attrs = array(
"respident" => "gap_$i"
);
$a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
$a_xml_writer->xmlEndTag("conditionvar");
$attrs = array(
"action" => "Add"
);
$a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
$linkrefid = "$i" . "_Response_" . $answer->getOrder();
$attrs = array(
"feedbacktype" => "Response",
"linkrefid" => $linkrefid
);
$a_xml_writer->xmlElement("displayfeedback", $attrs);
$a_xml_writer->xmlEndTag("respcondition");
}
break;
foreach ($gap->getItems() as $answer)
{
$attrs = array(
"continue" => "Yes"
);
$a_xml_writer->xmlStartTag("respcondition", $attrs);
$a_xml_writer->xmlStartTag("conditionvar");
$attrs = array(
"respident" => "gap_$i"
);
$a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
$a_xml_writer->xmlEndTag("conditionvar");
$attrs = array(
"action" => "Add"
);
$a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
$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->getFeedbackGeneric(1);
if (strlen($feedback_allcorrect))
{
$attrs = array(
"continue" => "Yes"
);
$a_xml_writer->xmlStartTag("respcondition", $attrs);
$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())
{
$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;
$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;
$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");
$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);
$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())
{
$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;
$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;
$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");
$attrs = array(
"feedbacktype" => "Response",
"linkrefid" => "response_onenotcorrect"
);
$a_xml_writer->xmlElement("displayfeedback", $attrs);
$a_xml_writer->xmlEndTag("respcondition");
}
$a_xml_writer->xmlEndTag("resprocessing");
for ($i = 0; $i < $this->object->getGapCount(); $i++)
{
$gap = $this->object->getGap($i);
switch ($gap->getType())
{
foreach ($gap->getItems() as $answer)
{
$linkrefid = "$i" . "_Response_" . $answer->getOrder();
$attrs = array(
"ident" => $linkrefid,
"view" => "All"
);
$a_xml_writer->xmlStartTag("itemfeedback", $attrs);
$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");
}
break;
foreach ($gap->getItems() as $answer)
{
$linkrefid = "$i" . "_Response_" . $answer->getOrder();
$attrs = array(
"ident" => $linkrefid,
"view" => "All"
);
$a_xml_writer->xmlStartTag("itemfeedback", $attrs);
$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");
}
break;
foreach ($gap->getItems() as $answer)
{
$linkrefid = "$i" . "_Response_" . $answer->getOrder();
$attrs = array(
"ident" => $linkrefid,
"view" => "All"
);
$a_xml_writer->xmlStartTag("itemfeedback", $attrs);
$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");
}
break;
}
}
if (strlen($feedback_allcorrect))
{
$attrs = array(
"ident" => "response_allcorrect",
"view" => "All"
);
$a_xml_writer->xmlStartTag("itemfeedback", $attrs);
$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);
$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;
}