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();
 
   41        $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
 
   43        foreach ($presentation->order as $entry) {
 
   44            switch ($entry[
"type"]) {
 
   46                    $response = $presentation->response[$entry[
"index"]];
 
   48                    switch (strtolower(get_class(
$response->getRenderType()))) {
 
   49                        case "ilqtirenderchoice":
 
   50                            $shuffle = $rendertype->getShuffle();
 
   53                            foreach ($rendertype->response_labels as $response_label) {
 
   54                                $ident = $response_label->getIdent();
 
   56                                $answerimage = array();
 
   57                                foreach ($response_label->material as $mat) {
 
   59                                    for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
 
   60                                        $foundmat = $mat->getMaterial($m);
 
   61                                        if (strcmp($foundmat[
"type"], 
"mattext") == 0) {
 
   63                                        if (strcmp($foundmat[
"type"], 
"matimage") == 0) {
 
   64                                            if (strlen($foundmat[
"material"]->getEmbedded())) {
 
   70                                        for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
 
   71                                            $foundmat = $mat->getMaterial($m);
 
   72                                            if (strcmp($foundmat[
"type"], 
"mattext") == 0) {
 
   73                                                $answertext .= $foundmat[
"material"]->getContent();
 
   75                                            if (strcmp($foundmat[
"type"], 
"matimage") == 0) {
 
   78                                                    "imagetype" => $foundmat[
"material"]->getImageType(),
 
   79                                                    "label" => $foundmat[
"material"]->getLabel(),
 
   80                                                    "content" => $foundmat[
"material"]->getContent()
 
   85                                        $answertext = $this->
object->QTIMaterialToString($mat);
 
   88                                $answers[$ident] = array(
 
   89                                    "answertext" => $answertext,
 
   90                                    "imagefile" => $answerimage,
 
   92                                    "answerorder" => $answerorder++,
 
   93                                    "points_unchecked" => 0,
 
  102        $responses = array();
 
  103        $feedbacks = array();
 
  104        $feedbacksgeneric = array();
 
  105        foreach ($item->resprocessing as $resprocessing) {
 
  106            foreach ($resprocessing->respcondition as $respcondition) {
 
  109                $conditionvar = $respcondition->getConditionvar();
 
  110                foreach ($conditionvar->order as $order) {
 
  111                    switch ($order[
"field"]) {
 
  116                            $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
 
  120                foreach ($respcondition->setvar as $setvar) {
 
  121                    if (strcmp($ident, 
"") != 0) {
 
  123                            $answers[$ident][
"action"] = $setvar->getAction();
 
  124                            $answers[$ident][
"points"] = $setvar->getContent();
 
  125                            if (count($respcondition->displayfeedback)) {
 
  126                                foreach ($respcondition->displayfeedback as $feedbackpointer) {
 
  127                                    if (strlen($feedbackpointer->getLinkrefid())) {
 
  128                                        foreach ($item->itemfeedback as $ifb) {
 
  129                                            if (strcmp($ifb->getIdent(), 
"response_allcorrect") == 0) {
 
  131                                                if (count($ifb->material)) {
 
  132                                                    foreach ($ifb->material as $material) {
 
  133                                                        $feedbacksgeneric[1] = $material;
 
  136                                                if ((count($ifb->flow_mat) > 0)) {
 
  137                                                    foreach ($ifb->flow_mat as $fmat) {
 
  138                                                        if (count($fmat->material)) {
 
  139                                                            foreach ($fmat->material as $material) {
 
  140                                                                $feedbacksgeneric[1] = $material;
 
  145                                            } elseif (strcmp($ifb->getIdent(), 
"response_onenotcorrect") == 0) {
 
  147                                                if (count($ifb->material)) {
 
  148                                                    foreach ($ifb->material as $material) {
 
  149                                                        $feedbacksgeneric[0] = $material;
 
  152                                                if ((count($ifb->flow_mat) > 0)) {
 
  153                                                    foreach ($ifb->flow_mat as $fmat) {
 
  154                                                        if (count($fmat->material)) {
 
  155                                                            foreach ($fmat->material as $material) {
 
  156                                                                $feedbacksgeneric[0] = $material;
 
  162                                            if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
 
  164                                                if (count($ifb->material)) {
 
  165                                                    foreach ($ifb->material as $material) {
 
  166                                                        $feedbacks[$ident] = $material;
 
  169                                                if ((count($ifb->flow_mat) > 0)) {
 
  170                                                    foreach ($ifb->flow_mat as $fmat) {
 
  171                                                        if (count($fmat->material)) {
 
  172                                                            foreach ($fmat->material as $material) {
 
  173                                                                $feedbacks[$ident] = $material;
 
  184                            $answers[$ident][
"action"] = $setvar->getAction();
 
  185                            $answers[$ident][
"points_unchecked"] = $setvar->getContent();
 
  192        $this->
object->setTitle($item->getTitle());
 
  193        $this->
object->setNrOfTries($item->getMaxattempts());
 
  194        $this->
object->setComment($item->getComment());
 
  195        $this->
object->setAuthor($item->getAuthor());
 
  196        $this->
object->setOwner(
$ilUser->getId());
 
  197        $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
 
  198        $this->
object->setObjId($questionpool_id);
 
  199        $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
 
  200        $this->
object->setShuffle($shuffle);
 
  201        $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
 
  202        foreach ($answers as $answer) {
 
  203            if ($item->getMetadataEntry(
'singleline') || (is_array($answer[
"imagefile"]) && count($answer[
"imagefile"]) > 0)) {
 
  204                $this->
object->isSingleline = 
true;
 
  206            $this->
object->addAnswer($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"], $answer[
"imagefile"][
"label"]);
 
  209        $this->
object->setAdditionalContentEditingMode(
 
  212        $this->
object->saveToDb();
 
  213        foreach ($answers as $answer) {
 
  214            if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0)) {
 
  215                $image = &base64_decode($answer[
"imagefile"][
"content"]);
 
  216                $imagepath = $this->
object->getImagePath();
 
  217                include_once 
"./Services/Utilities/classes/class.ilUtil.php";
 
  218                if (!file_exists($imagepath)) {
 
  221                $imagepath .= $answer[
"imagefile"][
"label"];
 
  222                $fh = fopen($imagepath, 
"wb");
 
  225                    $imagefile = fwrite($fh, $image);
 
  231        $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
 
  232        if (!is_null($feedbackSetting)) {
 
  233            $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
 
  236        foreach ($feedbacks as $ident => $material) {
 
  237            $m = $this->
object->QTIMaterialToString($material);
 
  238            $feedbacks[$ident] = $m;
 
  240        foreach ($feedbacksgeneric as $correctness => $material) {
 
  241            $m = $this->
object->QTIMaterialToString($material);
 
  242            $feedbacksgeneric[$correctness] = $m;
 
  245        $questiontext = $this->
object->getQuestion();
 
  246        $answers = &$this->
object->getAnswers();
 
  247        if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
 
  248            include_once 
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
 
  249            include_once 
"./Services/RTE/classes/class.ilRTE.php";
 
  250            foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
 
  258                $DIC[
'ilLog']->write(__METHOD__ . 
': import mob from dir: ' . $importfile);
 
  262                $questiontext = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . 
IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $questiontext);
 
  263                foreach ($answers as $key => $value) {
 
  264                    $answer_obj = $answers[$key];
 
  265                    $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . 
IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $answer_obj->getAnswertext()));
 
  267                foreach ($feedbacks as $ident => $material) {
 
  268                    $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . 
IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $material);
 
  270                foreach ($feedbacksgeneric as $correctness => $material) {
 
  271                    $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . 
IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $material);
 
  276        foreach ($answers as $key => $value) {
 
  277            $answer_obj = &$answers[$key];
 
  280        foreach ($feedbacks as $ident => $material) {
 
  281            $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
 
  282                $this->object->getId(),
 
  288        foreach ($feedbacksgeneric as $correctness => $material) {
 
  289            $this->
object->feedbackOBJ->importGenericFeedback(
 
  290                $this->object->getId(),
 
  295        $this->
object->saveToDb();
 
  296        if (count($item->suggested_solutions)) {
 
  297            foreach ($item->suggested_solutions as $suggested_solution) {
 
  298                $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"], 
true);
 
  300            $this->
object->saveToDb();
 
  303            $q_1_id = $this->
object->getId();
 
  304            $question_id = $this->
object->duplicate(
true, 
null, 
null, 
null, $tst_id);
 
  305            $tst_object->questions[$question_counter++] = $question_id;
 
  306            $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id, 
"test" => $question_id);
 
  308            $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(), 
"test" => 0);
 
An exception for terminatinating execution or to throw for unit testing.
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)
addGeneralMetadata(ilQTIItem $item)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
Class for single choice question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
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.