4include_once 
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
 
   30    public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 
   37        $presentation = $item->getPresentation();
 
   38        $duration = $item->getDuration();
 
   40        $packageIliasVersion = $item->getIliasSourceVersion(
'ILIAS_VERSION');
 
   41        $seperate_question_field = $item->getMetadataEntry(
"question");
 
   44        if (!$packageIliasVersion || version_compare($packageIliasVersion, 
'5.0.0', 
'<')) {
 
   45            $questiontext = 
' ';
 
   46        } elseif ($seperate_question_field) {
 
   48                $seperate_question_field,
 
   49                $item->getIliasSourceNic()
 
   56        $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
 
   58        foreach ($presentation->order as $entry) {
 
   59            switch ($entry[
"type"]) {
 
   62                    $materialString = $this->
object->QTIMaterialToString(
 
   63                        $presentation->material[$entry[
"index"]]
 
   66                    if ($questiontext === 
null) {
 
   67                        $questiontext = $materialString;
 
   69                        array_push($clozetext, $materialString);
 
   74                    $response = $presentation->response[$entry[
"index"]];
 
   76                    array_push($clozetext, 
"<<" . 
$response->getIdent() . 
">>");
 
   78                    switch (strtolower(get_class(
$response->getRenderType()))) {
 
   79                        case "ilqtirenderfib":
 
   80                            switch (
$response->getRenderType()->getFibtype()) {
 
   89                                            "minnumber" => 
$response->getRenderType()->getMinnumber(),
 
   90                                            "maxnumber" => 
$response->getRenderType()->getMaxnumber(),
 
   91                                            'gap_size' => 
$response->getRenderType()->getMaxchars()
 
  101                                              "answers" => array(),
 
  102                                              'gap_size' => 
$response->getRenderType()->getMaxchars()
 
  108                        case "ilqtirenderchoice":
 
  110                            $shuffle = $rendertype->getShuffle();
 
  112                            foreach ($rendertype->response_labels as $response_label) {
 
  113                                $ident = $response_label->getIdent();
 
  115                                foreach ($response_label->material as $mat) {
 
  116                                    $answertext .= $this->
object->QTIMaterialToString($mat);
 
  118                                $answers[$ident] = array(
 
  119                                    "answertext" => $answertext,
 
  121                                    "answerorder" => $answerorder++,
 
  123                                    "shuffle" => $rendertype->getShuffle()
 
  126                            array_push($gaps, array(
"ident" => 
$response->getIdent(), 
"type" => 
CLOZE_SELECT, 
"shuffle" => $rendertype->getShuffle(), 
"answers" => $answers));
 
  132        $responses = array();
 
  133        $feedbacks = array();
 
  134        $feedbacksgeneric = array();
 
  135        foreach ($item->resprocessing as $resprocessing) {
 
  136            foreach ($resprocessing->respcondition as $respcondition) {
 
  139                $conditionvar = $respcondition->getConditionvar();
 
  140                foreach ($conditionvar->order as $order) {
 
  141                    switch ($order[
"field"]) {
 
  143                            $equals = $conditionvar->varequal[$order[
"index"]]->getContent();
 
  144                            $gapident = $conditionvar->varequal[$order[
"index"]]->getRespident();
 
  148                foreach ($respcondition->setvar as $setvar) {
 
  149                    if (strcmp($gapident, 
"") != 0) {
 
  150                        foreach ($gaps as $gi => $g) {
 
  151                            if (strcmp($g[
"ident"], $gapident) == 0) {
 
  153                                    foreach ($gaps[$gi][
"answers"] as 
$ai => $answer) {
 
  154                                        if (strcmp($answer[
"answertext"], $equals) == 0) {
 
  155                                            $gaps[$gi][
"answers"][
$ai][
"action"] = $setvar->getAction();
 
  156                                            $gaps[$gi][
"answers"][
$ai][
"points"] = $setvar->getContent();
 
  160                                    array_push($gaps[$gi][
"answers"], array(
 
  161                                        "answertext" => $equals,
 
  162                                        "points" => $setvar->getContent(),
 
  163                                        "answerorder" => count($gaps[$gi][
"answers"]),
 
  164                                        "action" => $setvar->getAction()
 
  168                                    array_push($gaps[$gi][
"answers"], array(
 
  169                                        "answertext" => $equals,
 
  170                                        "points" => $setvar->getContent(),
 
  171                                        "answerorder" => count($gaps[$gi][
"answers"]),
 
  172                                        "action" => $setvar->getAction()
 
  180                if (count($respcondition->displayfeedback)) {
 
  181                    foreach ($respcondition->displayfeedback as $feedbackpointer) {
 
  182                        if (strlen($feedbackpointer->getLinkrefid())) {
 
  183                            foreach ($item->itemfeedback as $ifb) {
 
  184                                if (strcmp($ifb->getIdent(), 
"response_allcorrect") == 0) {
 
  186                                    if (count($ifb->material)) {
 
  187                                        foreach ($ifb->material as $material) {
 
  188                                            $feedbacksgeneric[1] = $material;
 
  191                                    if ((count($ifb->flow_mat) > 0)) {
 
  192                                        foreach ($ifb->flow_mat as $fmat) {
 
  193                                            if (count($fmat->material)) {
 
  194                                                foreach ($fmat->material as $material) {
 
  195                                                    $feedbacksgeneric[1] = $material;
 
  200                                } elseif (strcmp($ifb->getIdent(), 
"response_onenotcorrect") == 0) {
 
  202                                    if (count($ifb->material)) {
 
  203                                        foreach ($ifb->material as $material) {
 
  204                                            $feedbacksgeneric[0] = $material;
 
  207                                    if ((count($ifb->flow_mat) > 0)) {
 
  208                                        foreach ($ifb->flow_mat as $fmat) {
 
  209                                            if (count($fmat->material)) {
 
  210                                                foreach ($fmat->material as $material) {
 
  211                                                    $feedbacksgeneric[0] = $material;
 
  218                                    if (count($ifb->material)) {
 
  219                                        foreach ($ifb->material as $material) {
 
  220                                            $feedbacks[$ifb->getIdent()] = $material;
 
  223                                    if ((count($ifb->flow_mat) > 0)) {
 
  224                                        foreach ($ifb->flow_mat as $fmat) {
 
  225                                            if (count($fmat->material)) {
 
  226                                                foreach ($fmat->material as $material) {
 
  227                                                    $feedbacks[$ifb->getIdent()] = $material;
 
  241        $this->
object->setTitle($item->getTitle());
 
  242        $this->
object->setNrOfTries($item->getMaxattempts());
 
  243        $this->
object->setComment($item->getComment());
 
  244        $this->
object->setAuthor($item->getAuthor());
 
  245        $this->
object->setOwner(
$ilUser->getId());
 
  246        $this->
object->setObjId($questionpool_id);
 
  247        $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
 
  248        $textgap_rating = $item->getMetadataEntry(
"textgaprating");
 
  249        $this->
object->setFixedTextLength($item->getMetadataEntry(
"fixedTextLength"));
 
  250        $this->
object->setIdenticalScoring($item->getMetadataEntry(
"identicalScoring"));
 
  251        $this->
object->setFeedbackMode(
 
  252            strlen($item->getMetadataEntry(
"feedback_mode")) ?
 
  255        $combination = json_decode(base64_decode($item->getMetadataEntry(
"combinations")));
 
  256        if (strlen($textgap_rating) == 0) {
 
  257            $textgap_rating = 
"ci";
 
  259        $this->
object->setTextgapRating($textgap_rating);
 
  261        foreach ($gaps as $gapidx => $gap) {
 
  262            $gapcontent = array();
 
  263            include_once 
"./Modules/TestQuestionPool/classes/class.assClozeGap.php";
 
  265            foreach ($gap[
"answers"] as 
$index => $answer) {
 
  266                include_once 
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
 
  267                $gapanswer = 
new assAnswerCloze($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"]);
 
  268                $gapanswer->setGapSize($gap[
"gap_size"]);
 
  269                switch ($clozegap->getType()) {
 
  271                        $clozegap->setShuffle($answer[
"shuffle"]);
 
  274                        $gapanswer->setLowerBound($gap[
"minnumber"]);
 
  275                        $gapanswer->setUpperBound($gap[
"maxnumber"]);
 
  278                $clozegap->setGapSize($gap[
"gap_size"]);
 
  279                $clozegap->addItem($gapanswer);
 
  280                array_push($gapcontent, $answer[
"answertext"]);
 
  282            $this->
object->addGapAtIndex($clozegap, $gapidx);
 
  283            $gaptext[$gap[
"ident"]] = 
"[gap]" . join(
",", $gapcontent) . 
"[/gap]";
 
  286        $this->
object->setQuestion($questiontext);
 
  287        $clozetext = join(
"", $clozetext);
 
  289        foreach ($gaptext as $idx => $val) {
 
  290            $clozetext = str_replace(
"<<" . $idx . 
">>", $val, $clozetext);
 
  292        $this->
object->setClozeTextValue($clozetext);
 
  295        $this->
object->setAdditionalContentEditingMode(
 
  298        $this->
object->saveToDb();
 
  301        foreach ($feedbacks as $ident => $material) {
 
  302            $m = $this->
object->QTIMaterialToString($material);
 
  303            $feedbacks[$ident] = 
$m;
 
  305        foreach ($feedbacksgeneric as $correctness => $material) {
 
  306            $m = $this->
object->QTIMaterialToString($material);
 
  307            $feedbacksgeneric[$correctness] = 
$m;
 
  309        $questiontext = $this->
object->getQuestion();
 
  310        $clozetext = $this->
object->getClozeText();
 
  311        if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
 
  312            include_once 
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
 
  313            include_once 
"./Services/RTE/classes/class.ilRTE.php";
 
  314            foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
 
  321                $DIC[
'ilLog']->write(__METHOD__ . 
': import mob from dir: ' . $importfile);
 
  324                $questiontext = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $questiontext);
 
  325                $clozetext = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $clozetext);
 
  326                foreach ($feedbacks as $ident => $material) {
 
  327                    $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $material);
 
  329                foreach ($feedbacksgeneric as $correctness => $material) {
 
  330                    $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $material);
 
  336        foreach ($feedbacks as $ident => $material) {
 
  338            $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
 
  339                $this->object->getId(),
 
  340                $fbIdentifier->getQuestionIndex(),
 
  341                $fbIdentifier->getAnswerIndex(),
 
  345        foreach ($feedbacksgeneric as $correctness => $material) {
 
  346            $this->
object->feedbackOBJ->importGenericFeedback(
 
  347                $this->object->getId(),
 
  352        $this->
object->saveToDb();
 
  353        if (count($item->suggested_solutions)) {
 
  354            foreach ($item->suggested_solutions as $suggested_solution) {
 
  355                $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"], 
true);
 
  357            $this->
object->saveToDb();
 
  360            $q_1_id = $this->
object->getId();
 
  361            $question_id = $this->
object->duplicate(
true, 
null, 
null, 
null, $tst_id);
 
  362            $tst_object->questions[$question_counter++] = $question_id;
 
  363            $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id, 
"test" => $question_id);
 
  365            $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(), 
"test" => 0);
 
  367        $this->
object->saveToDb();
 
  368        if (is_array($combination) && count($combination) > 0) {
 
  369            require_once 
'./Modules/TestQuestionPool/classes/class.assClozeGapCombination.php';
 
  373        $this->
object->saveToDb();
 
  382        require_once 
'Modules/TestQuestionPool/classes/feedback/class.ilAssSpecificFeedbackIdentifier.php';
 
  385        $ident = explode(
'_', $ident);
 
  387        if (count($ident) > 1) {
 
  388            $fbIdentifier->setQuestionIndex($ident[0]);
 
  389            $fbIdentifier->setAnswerIndex($ident[1]);
 
  391            $fbIdentifier->setQuestionIndex($ident[0]);
 
  392            $fbIdentifier->setAnswerIndex(0);
 
  395        return $fbIdentifier;
 
An exception for terminatinating execution or to throw for unit testing.
Class for cloze question numeric answers.
static clearGapCombinationsFromDb($question_id)
static importGapCombinationToDb($question_id, $gap_combinations)
Class for cloze question gaps.
Class for cloze question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
buildFeedbackIdentifier($ident)
Class for question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
processNonAbstractedImageReferences($text, $sourceNic)
addGeneralMetadata(ilQTIItem $item)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
const FB_MODE_GAP_QUESTION
constants for different feedback modes (per gap or per gap-answers/options)
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
const CLOZE_TEXT
Cloze question constants.