4include_once 
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
 
   19                $image =& base64_decode(
$data);
 
   20                $imagepath = $this->
object->getImagePath();
 
   21                include_once 
"./Services/Utilities/classes/class.ilUtil.php";
 
   22                if (!file_exists($imagepath))
 
   27                $fh = fopen($imagepath, 
"wb");
 
   33                        $imagefile = fwrite(
$fh, $image);
 
   51        function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 
   57                $presentation = $item->getPresentation(); 
 
   61                $created = 
sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
 
   62                $definitions = array();
 
   65                foreach ($presentation->order as $entry)
 
   67                        switch ($entry[
"type"])
 
   70                                        $response = $presentation->response[$entry[
"index"]];
 
   71                                        $rendertype = $response->getRenderType();
 
   72                                        switch (strtolower(get_class($rendertype)))
 
   74                                                case "ilqtirenderchoice":
 
   75                                                        $shuffle = $rendertype->getShuffle();
 
   77                                                        foreach ($rendertype->response_labels as $response_label)
 
   79                                                                $ident = $response_label->getIdent();
 
   81                                                                $answerimage = array();
 
   82                                                                foreach ($response_label->material as $mat)
 
   84                                                                        for ($m = 0; $m < $mat->getMaterialCount(); $m++)
 
   86                                                                                $foundmat = $mat->getMaterial($m);
 
   87                                                                                if (strcmp($foundmat[
"type"], 
"mattext") == 0)
 
   89                                                                                        $answertext .= $foundmat[
"material"]->getContent();
 
   91                                                                                if (strcmp($foundmat[
"type"], 
"matimage") == 0)
 
   95                                                                                                "imagetype" => $foundmat[
"material"]->getImageType(),
 
   96                                                                                                "label" => $foundmat[
"material"]->getLabel(),
 
   97                                                                                                "content" => $foundmat[
"material"]->getContent()
 
  102                                                                if (($response_label->getMatchMax() == 1) && (strlen($response_label->getMatchGroup())))
 
  104                                                                        $definitions[$ident] = array(
 
  105                                                                                "answertext" => $answertext,
 
  106                                                                                "answerimage" => $answerimage,
 
  108                                                                                "answerorder" => $ident,
 
  114                                                                        $terms[$ident] = array(
 
  115                                                                                "term" => $answertext,
 
  116                                                                                "answerimage" => $answerimage,
 
  128                $responses = array();
 
  129                $feedbacksgeneric = array();
 
  130                foreach ($item->resprocessing as $resprocessing)
 
  132                        foreach ($resprocessing->respcondition as $respcondition)
 
  136                                $conditionvar = $respcondition->getConditionvar();
 
  137                                foreach ($conditionvar->order as $order)
 
  139                                        switch ($order[
"field"])
 
  142                                                        $subset = explode(
",", $conditionvar->varsubset[$order[
"index"]]->getContent());
 
  146                                foreach ($respcondition->setvar as $setvar)
 
  148                                        array_push($responses, array(
"subset" => $subset, 
"action" => $setvar->getAction(), 
"points" => $setvar->getContent())); 
 
  151                                if (count($respcondition->displayfeedback))
 
  153                                        foreach ($respcondition->displayfeedback as $feedbackpointer)
 
  155                                                if (strlen($feedbackpointer->getLinkrefid()))
 
  157                                                        foreach ($item->itemfeedback as $ifb)
 
  159                                                                if (strcmp($ifb->getIdent(), 
"response_allcorrect") == 0)
 
  162                                                                        if (count($ifb->material))
 
  164                                                                                foreach ($ifb->material as $material)
 
  166                                                                                        $feedbacksgeneric[1] = $material;
 
  169                                                                        if ((count($ifb->flow_mat) > 0))
 
  171                                                                                foreach ($ifb->flow_mat as $fmat)
 
  173                                                                                        if (count($fmat->material))
 
  175                                                                                                foreach ($fmat->material as $material)
 
  177                                                                                                        $feedbacksgeneric[1] = $material;
 
  183                                                                else if (strcmp($ifb->getIdent(), 
"response_onenotcorrect") == 0)
 
  186                                                                        if (count($ifb->material))
 
  188                                                                                foreach ($ifb->material as $material)
 
  190                                                                                        $feedbacksgeneric[0] = $material;
 
  193                                                                        if ((count($ifb->flow_mat) > 0))
 
  195                                                                                foreach ($ifb->flow_mat as $fmat)
 
  197                                                                                        if (count($fmat->material))
 
  199                                                                                                foreach ($fmat->material as $material)
 
  201                                                                                                        $feedbacksgeneric[0] = $material;
 
  215                include_once 
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
 
  216                include_once 
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
 
  217                include_once 
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
 
  218                $this->
object->createNewQuestion();
 
  220                $this->
object->setTitle($item->getTitle());
 
  221                $this->
object->setNrOfTries($item->getMaxattempts());
 
  222                $this->
object->setComment($item->getComment());
 
  223                $this->
object->setAuthor($item->getAuthor());
 
  224                $this->
object->setOwner($ilUser->getId());
 
  225                $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
 
  226                $this->
object->setObjId($questionpool_id);
 
  228                $extended_shuffle = $item->getMetadataEntry(
"shuffle");
 
  229                $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
 
  231                if( strlen($item->getMetadataEntry(
'matching_mode')) )
 
  233                        $this->
object->setMatchingMode($item->getMetadataEntry(
'matching_mode'));
 
  241                foreach ($terms as $term)
 
  243                        if (count($term[
'answerimage'])) $this->
saveImage($term[
'answerimage'][
'content'], $term[
'answerimage'][
'label']);
 
  245                foreach ($definitions as $definition)
 
  247                        if (count($definition[
'answerimage'])) $this->
saveImage($definition[
'answerimage'][
'content'], $definition[
'answerimage'][
'label']);
 
  250                foreach ($terms as $termindex => $term)
 
  252                        $this->
object->addTerm(
new assAnswerMatchingTerm($term[
"term"], $term[
'answerimage'][
'label'], $term[
"ident"]));
 
  254                foreach ($definitions as $definitionindex => $definition)
 
  256                        $this->
object->addDefinition(
new assAnswerMatchingDefinition($definition[
"answertext"], $definition[
'answerimage'][
'label'], $definition[
"answerorder"]));
 
  259                if (strlen($extended_shuffle) > 0)
 
  261                        $shuffle = $extended_shuffle;
 
  263                $this->
object->setShuffle($shuffle);
 
  265                foreach ($responses as $response)
 
  267                        $subset = $response[
"subset"];
 
  268                        foreach ($subset as $ident)
 
  270                                if (array_key_exists($ident, $definitions))
 
  272                                        $definition = $definitions[$ident];
 
  274                                if (array_key_exists($ident, $terms))
 
  276                                        $term = $terms[$ident];
 
  282                $this->
object->setAdditionalContentEditingMode(
 
  285                $this->
object->saveToDb();
 
  286                if (count($item->suggested_solutions))
 
  288                        foreach ($item->suggested_solutions as $suggested_solution)
 
  290                                $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"], 
true);
 
  292                        $this->
object->saveToDb();
 
  294                foreach ($responses as $response)
 
  296                        $subset = $response[
"subset"];
 
  297                        foreach ($subset as $ident)
 
  299                                if (array_key_exists($ident, $definitions))
 
  301                                        $definition = $definitions[$ident];
 
  303                                if (array_key_exists($ident, $terms))
 
  305                                        $term = $terms[$ident];
 
  310                foreach ($feedbacksgeneric as $correctness => $material)
 
  312                        $m = $this->
object->QTIMaterialToString($material);
 
  313                        $feedbacksgeneric[$correctness] = $m;
 
  319                $questiontext = $this->
object->getQuestion();
 
  320                if (is_array(
$_SESSION[
"import_mob_xhtml"]))
 
  322                        include_once 
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
 
  323                        include_once 
"./Services/RTE/classes/class.ilRTE.php";
 
  324                        foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
 
  335                                $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
 
  339                                $questiontext = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $questiontext);
 
  340                                foreach ($feedbacks as $ident => $material)
 
  342                                        $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $material);
 
  344                                foreach ($feedbacksgeneric as $correctness => $material)
 
  346                                        $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $material);
 
  351                foreach ($feedbacks as $ident => $material)
 
  355                        $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
 
  359                foreach ($feedbacksgeneric as $correctness => $material)
 
  361                        $this->
object->feedbackOBJ->importGenericFeedback(
 
  365                $this->
object->saveToDb();
 
  368                        $q_1_id = $this->
object->getId();
 
  369                        $question_id = $this->
object->duplicate(
true, 
null, 
null, 
null, $tst_id);
 
  370                        $tst_object->questions[$question_counter++] = $question_id;
 
  371                        $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id, 
"test" => $question_id);
 
  375                        $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(), 
"test" => 0);
 
  386                list($termId, $definitionId) = explode(
'_', str_replace($prefix, 
'', $feedbackIdent));
 
  388                foreach($this->object->getMatchingPairs() as $index => $pair)
 
  392                        if( $pair->term->identifier != $termId)
 
  397                        if( $pair->definition->identifier != $definitionId)
 
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Class for matching question definitions.
Class for matching question terms.
Class for matching question imports.
saveImage($data, $filename)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
const MATCHING_MODE_1_ON_1
Class for question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
addGeneralMetadata(ilQTIItem $item)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
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...
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.