Creates a question from a QTI file. 
   46         $ilUser = $DIC[
'ilUser'];
    50         $presentation = $item->getPresentation();
    52         $selectionLimit = null;
    54         $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
    56         foreach ($presentation->order as $entry) {
    57             switch ($entry[
"type"]) {
    59                     $response = $presentation->response[$entry[
"index"]];
    61                     switch (strtolower(get_class(
$response->getRenderType()))) {
    62                         case "ilqtirenderchoice":
    63                             $shuffle = $rendertype->getShuffle();
    64                             if ($rendertype->getMaxnumber()) {
    65                                 $selectionLimit = $rendertype->getMaxnumber();
    69                             foreach ($rendertype->response_labels as $response_label) {
    70                                 $ident = $response_label->getIdent();
    73                                 foreach ($response_label->material as $mat) {
    75                                     for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
    76                                         $foundmat = $mat->getMaterial($m);
    77                                         if (strcmp($foundmat[
"type"], 
"mattext") == 0) {
    79                                         if (strcmp($foundmat[
"type"], 
"matimage") == 0) {
    80                                             if (strlen($foundmat[
"material"]->getEmbedded())) {
    86                                         for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
    87                                             $foundmat = $mat->getMaterial($m);
    88                                             if (strcmp($foundmat[
"type"], 
"mattext") == 0) {
    89                                                 $answertext .= $foundmat[
"material"]->getContent();
    91                                             if (strcmp($foundmat[
"type"], 
"matimage") == 0) {
    94                                                     "imagetype" => $foundmat[
"material"]->getImageType(),
    95                                                     "label" => $foundmat[
"material"]->getLabel(),
    96                                                     "content" => $foundmat[
"material"]->getContent()
   105                                     "answertext" => $answertext,
   106                                     "imagefile" => $answerimage,
   108                                     "answerorder" => $answerorder++,
   109                                     "points_unchecked" => 0,
   120         $feedbacksgeneric = [];
   121         foreach ($item->resprocessing as $resprocessing) {
   122             foreach ($resprocessing->respcondition as $respcondition) {
   125                 $conditionvar = $respcondition->getConditionvar();
   126                 foreach ($conditionvar->order as $order) {
   127                     switch ($order[
"field"]) {
   132                             $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
   136                 foreach ($respcondition->setvar as $setvar) {
   137                     if (strcmp($ident, 
"") != 0) {
   139                             $answers[$ident][
"action"] = $setvar->getAction();
   140                             $answers[$ident][
"points"] = $setvar->getContent();
   141                             if (count($respcondition->displayfeedback)) {
   142                                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
   143                                     if (strlen($feedbackpointer->getLinkrefid())) {
   144                                         foreach ($item->itemfeedback as $ifb) {
   145                                             if (strcmp($ifb->getIdent(), 
"response_allcorrect") == 0) {
   147                                                 if (count($ifb->material)) {
   148                                                     foreach ($ifb->material as $material) {
   149                                                         $feedbacksgeneric[1] = $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[1] = $material;
   161                                             } elseif (strcmp($ifb->getIdent(), 
"response_onenotcorrect") == 0) {
   163                                                 if (count($ifb->material)) {
   164                                                     foreach ($ifb->material as $material) {
   165                                                         $feedbacksgeneric[0] = $material;
   168                                                 if ((count($ifb->flow_mat) > 0)) {
   169                                                     foreach ($ifb->flow_mat as $fmat) {
   170                                                         if (count($fmat->material)) {
   171                                                             foreach ($fmat->material as $material) {
   172                                                                 $feedbacksgeneric[0] = $material;
   178                                             if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
   180                                                 if (count($ifb->material)) {
   181                                                     foreach ($ifb->material as $material) {
   182                                                         $feedbacks[$ident] = $material;
   185                                                 if ((count($ifb->flow_mat) > 0)) {
   186                                                     foreach ($ifb->flow_mat as $fmat) {
   187                                                         if (count($fmat->material)) {
   188                                                             foreach ($fmat->material as $material) {
   189                                                                 $feedbacks[$ident] = $material;
   200                             $answers[$ident][
"action"] = $setvar->getAction();
   201                             $answers[$ident][
"points_unchecked"] = $setvar->getContent();
   208         $this->
object->setTitle($item->getTitle());
   209         $this->
object->setNrOfTries((
int) $item->getMaxattempts());
   210         $this->
object->setComment($item->getComment());
   211         $this->
object->setAuthor($item->getAuthor());
   212         $this->
object->setOwner($ilUser->getId());
   214         $this->
object->setObjId($questionpool_id);
   215         $this->
object->setShuffle($shuffle);
   216         $this->
object->setSelectionLimit($selectionLimit);
   217         $this->
object->setIsSingleline(
false);
   218         $this->
object->setThumbSize(
   222         foreach ($answers as $answer) {
   223             if ($item->getMetadataEntry(
'singleline') || (is_array($answer[
"imagefile"]) && count($answer[
"imagefile"]) > 0)) {
   224                 $this->
object->setIsSingleline(
true);
   226             $this->
object->addAnswer(
   227                 $answer[
"answertext"],
   229                 $answer[
"points_unchecked"],
   230                 $answer[
"answerorder"],
   231                 $answer[
"imagefile"][
"label"] ?? null
   235         $this->
object->setAdditionalContentEditingMode(
   238         $this->
object->saveToDb();
   239         foreach ($answers as $answer) {
   240             if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0)) {
   241                 $image = base64_decode($answer[
"imagefile"][
"content"]);
   242                 $imagepath = $this->
object->getImagePath();
   243                 if (!file_exists($imagepath)) {
   246                 $imagepath .= $answer[
"imagefile"][
"label"];
   247                 $fh = fopen($imagepath, 
"wb");
   249                     $imagefile = fwrite($fh, $image);
   251                     $this->
object->generateThumbForFile(
   252                         $answer[
"imagefile"][
"label"],
   253                         $this->
object->getImagePath(),
   254                         $this->
object->getThumbSize()
   260         $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
   261         if (!is_null($feedbackSetting)) {
   262             $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedbackSetting);
   266         foreach ($feedbacks as $ident => $material) {
   268             $feedbacks[$ident] = $m;
   270         foreach ($feedbacksgeneric as $correctness => $material) {
   272             $feedbacksgeneric[$correctness] = $m;
   274         $questiontext = $this->
object->getQuestion();
   275         $answers = &$this->
object->getAnswers();
   285                 $DIC[
'ilLog']->write(__METHOD__ . 
': import mob from dir: ' . $importfile);
   289                 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . 
IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $questiontext);
   290                 foreach ($answers as 
$key => $value) {
   291                     $answer_obj = &$answers[
$key];
   292                     $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . 
IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $answer_obj->getAnswertext()));
   294                 foreach ($feedbacks as $ident => $material) {
   295                     $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . 
IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $material);
   297                 foreach ($feedbacksgeneric as $correctness => $material) {
   298                     $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] . 
"\"", 
"src=\"" . 
"il_" . 
IL_INST_ID . 
"_mob_" . $media_object->getId() . 
"\"", $material);
   303         foreach ($answers as 
$key => $value) {
   304             $answer_obj = &$answers[
$key];
   307         foreach ($feedbacks as $ident => $material) {
   308             $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
   315         foreach ($feedbacksgeneric as $correctness => $material) {
   316             $this->
object->feedbackOBJ->importGenericFeedback(
   322         $this->
object->saveToDb();
   325             $q_1_id = $this->
object->getId();
   326             $question_id = $this->
object->duplicate(
true, 
"", 
"", -1, $tst_id);
   327             $tst_object->questions[$question_counter++] = $question_id;
   328             $import_mapping[$item->getIdent()] = [
"pool" => $q_1_id, 
"test" => $question_id];
   330             $import_mapping[$item->getIdent()] = [
"pool" => $this->
object->getId(), 
"test" => 0];
   332         return $import_mapping;
 static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
 
static get(string $a_var)
 
deduceThumbSizeFromImportValue(?int $size)
 
addGeneralMetadata(ilQTIItem $item)
 
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string. 
 
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
 
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
 
static makeDirParents(string $a_dir)
Create a new directory and all parent directories. 
 
importSuggestedSolutions(int $question_id, array $solution_from_import)
 
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
 
static clear(string $a_var)