Creates a question from a QTI file.
{
global $ilUser;
$presentation = $item->getPresentation();
$duration = $item->getDuration();
$shuffle = 0;
$now = getdate();
$foundimage = FALSE;
$created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
$answers = array();
foreach ($presentation->order as $entry)
{
switch ($entry["type"])
{
case "response":
$response = $presentation->response[$entry["index"]];
$rendertype = $response->getRenderType();
switch (strtolower(get_class($rendertype)))
{
case "ilqtirenderchoice":
$shuffle = $rendertype->getShuffle();
$answerorder = 0;
foreach ($rendertype->response_labels as $response_label)
{
$ident = $response_label->getIdent();
$answertext = "";
foreach ($response_label->material as $mat)
{
for ($m = 0; $m < $mat->getMaterialCount(); $m++)
{
$foundmat = $mat->getMaterial($m);
if (strcmp($foundmat["type"], "mattext") == 0)
{
$answertext .= $foundmat["material"]->getContent();
}
if (strcmp($foundmat["type"], "matimage") == 0)
{
$foundimage = TRUE;
$answerimage = array(
"imagetype" => $foundmat["material"]->getImageType(),
"label" => $foundmat["material"]->getLabel(),
"content" => $foundmat["material"]->getContent()
);
}
}
}
$answers[$ident] = array(
"answertext" => $answertext,
"answerimage" => $answerimage,
"points" => 0,
"answerorder" => $answerorder++,
"correctness" => "",
"action" => ""
);
}
break;
}
break;
}
}
$responses = array();
$feedbacksgeneric = array();
foreach ($item->resprocessing as $resprocessing)
{
foreach ($resprocessing->respcondition as $respcondition)
{
$ident = "";
$correctness = 1;
$conditionvar = $respcondition->getConditionvar();
foreach ($conditionvar->order as $order)
{
switch ($order["field"])
{
case "arr_not":
$correctness = 0;
break;
case "varequal":
$ident = $conditionvar->varequal[$order["index"]]->getContent();
$orderindex = $conditionvar->varequal[$order["index"]]->getIndex();
break;
}
}
foreach ($respcondition->setvar as $setvar)
{
if (strcmp($ident, "") != 0)
{
$answers[$ident]["solutionorder"] = $orderindex;
$answers[$ident]["action"] = $setvar->getAction();
$answers[$ident]["points"] = $setvar->getContent();
}
}
if (count($respcondition->displayfeedback))
{
foreach ($respcondition->displayfeedback as $feedbackpointer)
{
if (strlen($feedbackpointer->getLinkrefid()))
{
foreach ($item->itemfeedback as $ifb)
{
if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
{
if (count($ifb->material))
{
foreach ($ifb->material as $material)
{
$feedbacksgeneric[1] = $material;
}
}
if ((count($ifb->flow_mat) > 0))
{
foreach ($ifb->flow_mat as $fmat)
{
if (count($fmat->material))
{
foreach ($fmat->material as $material)
{
$feedbacksgeneric[1] = $material;
}
}
}
}
}
else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
{
if (count($ifb->material))
{
foreach ($ifb->material as $material)
{
$feedbacksgeneric[0] = $material;
}
}
if ((count($ifb->flow_mat) > 0))
{
foreach ($ifb->flow_mat as $fmat)
{
if (count($fmat->material))
{
foreach ($fmat->material as $material)
{
$feedbacksgeneric[0] = $material;
}
}
}
}
}
}
}
}
}
}
}
if ($foundimage)
{
}
$this->object->setTitle($item->getTitle());
$this->object->setComment($item->getComment());
$this->object->setAuthor($item->getAuthor());
$this->object->setOwner($ilUser->getId());
$this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
$this->
object->setOrderingType(
$type);
$this->object->setObjId($questionpool_id);
$this->object->setThumbGeometry($item->getMetadataEntry("thumb_geometry"));
$this->object->setElementHeight($item->getMetadataEntry("element_height"));
$this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
$this->object->setShuffle($shuffle);
$solanswers = array();
foreach ($answers as $answer)
{
$solanswers[$answer["solutionorder"]] = $answer;
}
ksort($solanswers);
foreach ($solanswers as $answer)
{
{
$this->object->addAnswer($answer["answertext"]);
}
else
{
$this->object->addAnswer($answer["answerimage"]["label"]);
}
}
$points = ($item->getMetadataEntry(
"points") > 0) ? $item->getMetadataEntry(
"points") :
$points;
$this->object->saveToDb();
if (count($item->suggested_solutions))
{
foreach ($item->suggested_solutions as $suggested_solution)
{
$this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
}
$this->object->saveToDb();
}
foreach ($answers as $answer)
{
{
include_once "./Services/Utilities/classes/class.ilUtil.php";
$image =& base64_decode($answer["answerimage"]["content"]);
$imagepath = $this->object->getImagePath();
if (!file_exists($imagepath))
{
}
$imagepath .= $answer["answerimage"]["label"];
$fh = fopen($imagepath, "wb");
if ($fh == false)
{
}
else
{
$imagefile = fwrite($fh, $image);
fclose($fh);
}
$thumbpath = $imagepath . "." . "thumb.jpg";
}
}
foreach ($feedbacksgeneric as $correctness => $material)
{
$m = $this->object->QTIMaterialToString($material);
$feedbacksgeneric[$correctness] = $m;
}
$questiontext = $this->object->getQuestion();
$answers =& $this->object->getAnswers();
{
include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
include_once "./Services/RTE/classes/class.ilRTE.php";
foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
{
if ($tst_id > 0)
{
include_once "./Modules/Test/classes/class.ilObjTest.php";
}
else
{
include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
}
$questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
foreach ($answers as
$key => $value)
{
$answer_obj =& $answers[
$key];
$answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
}
foreach ($feedbacksgeneric as $correctness => $material)
{
$feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
}
}
}
foreach ($answers as
$key => $value)
{
$answer_obj =& $answers[
$key];
}
foreach ($feedbacksgeneric as $correctness => $material)
{
}
$this->object->saveToDb();
if ($tst_id > 0)
{
$q_1_id = $this->object->getId();
$question_id = $this->object->duplicate(true);
$tst_object->questions[$question_counter++] = $question_id;
$import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
}
else
{
$import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
}
}