4 include_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();
58 $duration = $item->getDuration();
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 = split(
",", $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);
227 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
228 $extended_shuffle = $item->getMetadataEntry(
"shuffle");
229 $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
230 $this->
object->setElementHeight($item->getMetadataEntry(
"element_height"));
233 foreach ($terms as $term)
235 if (count($term[
'answerimage'])) $this->
saveImage($term[
'answerimage'][
'content'], $term[
'answerimage'][
'label']);
237 foreach ($definitions as $definition)
239 if (count($definition[
'answerimage'])) $this->
saveImage($definition[
'answerimage'][
'content'], $definition[
'answerimage'][
'label']);
242 foreach ($terms as $termindex => $term)
244 $this->
object->addTerm(
new assAnswerMatchingTerm($term[
"term"], $term[
'answerimage'][
'label'], $term[
"ident"]));
246 foreach ($definitions as $definitionindex => $definition)
248 $this->
object->addDefinition(
new assAnswerMatchingDefinition($definition[
"answertext"], $definition[
'answerimage'][
'label'], $definition[
"answerorder"]));
251 if (strlen($extended_shuffle) > 0)
253 $shuffle = $extended_shuffle;
255 $this->
object->setShuffle($shuffle);
257 foreach ($responses as $response)
259 $subset = $response[
"subset"];
260 foreach ($subset as $ident)
262 if (array_key_exists($ident, $definitions))
264 $definition = $definitions[$ident];
266 if (array_key_exists($ident, $terms))
268 $term = $terms[$ident];
274 $this->
object->setAdditionalContentEditingMode(
277 $this->
object->saveToDb();
278 if (count($item->suggested_solutions))
280 foreach ($item->suggested_solutions as $suggested_solution)
282 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
284 $this->
object->saveToDb();
286 foreach ($responses as $response)
288 $subset = $response[
"subset"];
289 foreach ($subset as $ident)
291 if (array_key_exists($ident, $definitions))
293 $definition = $definitions[$ident];
295 if (array_key_exists($ident, $terms))
297 $term = $terms[$ident];
302 foreach ($feedbacksgeneric as $correctness => $material)
304 $m = $this->
object->QTIMaterialToString($material);
305 $feedbacksgeneric[$correctness] = $m;
309 $questiontext = $this->
object->getQuestion();
310 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)
325 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
329 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
330 foreach ($feedbacksgeneric as $correctness => $material)
332 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
337 foreach ($feedbacksgeneric as $correctness => $material)
339 $this->
object->feedbackOBJ->importGenericFeedback(
343 $this->
object->saveToDb();
346 $q_1_id = $this->
object->getId();
347 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
348 $tst_object->questions[$question_counter++] = $question_id;
349 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
353 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
Class for matching question terms.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
addGeneralMetadata(ilQTIItem $item)
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) ...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
Class for matching question imports.
saveImage($data, $filename)
static _replaceMediaObjectImageSrc($a_text, $a_direction=0)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
Class for matching question definitions.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.