4 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
35 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
41 $presentation = $item->getPresentation();
46 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
50 foreach ($presentation->order as $entry)
52 switch ($entry[
"type"])
55 $response = $presentation->response[$entry[
"index"]];
56 $type = $response->getIdent();
57 if($response->getIdent() ==
'OQP' )
59 else if($response->getIdent() ==
'OQNP')
61 else if($response->getIdent() ==
'OQNT')
63 else if($response->getIdent() ==
'OQT')
66 $rendertype = $response->getRenderType();
67 switch (strtolower(get_class($rendertype)))
69 case "ilqtirenderchoice":
70 $shuffle = $rendertype->getShuffle();
72 foreach ($rendertype->response_labels as $response_label)
74 $ident = $response_label->getIdent();
76 foreach ($response_label->material as $mat)
78 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
80 $foundmat = $mat->getMaterial($m);
82 if (strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") == 0)
84 $answerdepth = $foundmat[
"material"]->getContent();
86 if (strcmp($foundmat[
"type"],
"mattext") == 0
87 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0)
89 $answertext .= $foundmat[
"material"]->getContent();
91 if (strcmp($foundmat[
"type"],
"matimage") == 0
92 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0)
96 "imagetype" => $foundmat[
"material"]->getImageType(),
97 "label" => $foundmat[
"material"]->getLabel(),
98 "content" => $foundmat[
"material"]->getContent()
103 $answers[$answerorder] =
array(
105 "answertext" => $answertext,
106 "answerimage" => $answerimage,
108 "answerorder" => $answerorder,
109 "answerdepth" => $answerdepth,
120 $responses =
array();
121 $feedbacksgeneric =
array();
122 foreach ($item->resprocessing as $resprocessing)
124 foreach ($resprocessing->respcondition as $respcondition)
128 $conditionvar = $respcondition->getConditionvar();
129 foreach ($conditionvar->order as $order)
131 switch ($order[
"field"])
137 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
138 $orderindex = $conditionvar->varequal[$order[
"index"]]->getIndex();
142 foreach ($respcondition->setvar as $setvar)
144 if (strcmp($ident,
"") != 0)
146 $answers[$ident][
"solutionorder"] = $orderindex;
147 $answers[$ident][
"action"] = $setvar->getAction();
148 $answers[$ident][
"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;
217 $this->
object->setTitle($item->getTitle());
218 $this->
object->setNrOfTries($item->getMaxattempts());
219 $this->
object->setComment($item->getComment());
220 $this->
object->setAuthor($item->getAuthor());
221 $this->
object->setOwner($ilUser->getId());
222 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
223 $this->
object->setOrderingType($type);
224 $this->
object->setObjId($questionpool_id);
225 $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
226 $this->
object->setElementHeight($item->getMetadataEntry(
"element_height"));
228 $this->
object->setShuffle($shuffle);
230 $solanswers =
array();
232 foreach ($answers as $answer)
234 $solanswers[$answer[
"solutionorder"]] = $answer;
238 foreach ($solanswers as $answer)
240 $points += $answer[
"points"];
244 if( $element->isExportIdent($answer[
'ident']) )
246 $element->setExportIdent($answer[
'ident']);
250 $element->setPosition($position++);
251 if(isset($answer[
'answerdepth']))
253 $element->setIndentation($answer[
'answerdepth']);
257 if( $this->
object->isImageOrderingType() )
259 $element->setContent($answer[
"answerimage"][
"label"]);
263 $element->setContent($answer[
"answertext"]);
266 $this->
object->getOrderingElementList()->addElement($element);
268 $points = ($item->getMetadataEntry(
"points") > 0) ? $item->getMetadataEntry(
"points") : $points;
269 $this->
object->setPoints($points);
271 $this->
object->setAdditionalContentEditingMode(
274 $this->
object->saveToDb();
275 if (count($item->suggested_solutions))
277 foreach ($item->suggested_solutions as $suggested_solution)
279 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
281 $this->
object->saveToDb();
283 foreach ($answers as $answer)
287 include_once
"./Services/Utilities/classes/class.ilUtil.php";
288 if( strlen($answer[
'answerimage'][
'label']) && strlen($answer[
'answerimage'][
'content']) )
290 $image =& base64_decode($answer[
"answerimage"][
"content"]);
291 $imagepath = $this->
object->getImagePath();
292 if (!file_exists($imagepath))
296 $imagepath .= $answer[
"answerimage"][
"label"];
297 $fh = fopen($imagepath,
"wb");
306 $imagefile = fwrite(
$fh, $image);
310 $thumbpath = $imagepath .
"." .
"thumb.jpg";
315 foreach ($feedbacksgeneric as $correctness => $material)
317 $m = $this->
object->QTIMaterialToString($material);
318 $feedbacksgeneric[$correctness] = $m;
320 $questiontext = $this->
object->getQuestion();
323 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
325 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
326 include_once
"./Services/RTE/classes/class.ilRTE.php";
327 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
338 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
342 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
343 foreach($this->
object->getOrderingElementList() as $element)
345 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
347 foreach ($feedbacksgeneric as $correctness => $material)
349 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
351 foreach ($itemfeedbacks as $ident => $material)
353 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
358 foreach($this->
object->getOrderingElementList() as $element)
362 foreach ($feedbacksgeneric as $correctness => $material)
364 $this->
object->feedbackOBJ->importGenericFeedback(
368 foreach ($itemfeedbacks as $ident => $material)
372 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
376 $this->
object->saveToDb();
379 $this->
object->setObjId($tst_id);
380 $tstQid = $this->
object->getId();
381 $qplQid = $this->
object->duplicate(
true, null, null, null, $questionpool_id);
384 $tst_object->questions[$question_counter++] = $tstQid;
385 $import_mapping[$item->getIdent()] =
array(
"pool" => $qplQid,
"test" => $tstQid);
389 $import_mapping[$item->getIdent()] =
array(
"pool" => $this->
object->getId(),
"test" => 0);
static resetOriginalId($questionId)
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
addGeneralMetadata(ilQTIItem $item)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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 _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...
Class for ordering question imports.
const OQ_PICTURES
Ordering question constants.
static saveOriginalId($questionId, $originalId)
Create styles array
The data for the language used.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
Create new PHPExcel object
obj_idprivate
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')