24 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
50 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
56 $presentation = $item->getPresentation();
57 $duration = $item->getDuration();
65 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
67 foreach ($presentation->order as $entry)
69 switch ($entry[
"type"])
72 $material = $presentation->material[$entry[
"index"]];
73 for ($i = 0; $i < $material->getMaterialCount(); $i++)
75 $mat = $material->getMaterial($i);
76 if (strcmp($mat[
"type"],
"mattext") == 0)
78 $mattext = $mat[
"material"];
79 if ((strlen($mattext->getLabel()) == 0) && (strlen($this->object->QTIMaterialToString($item->getQuestiontext())) == 0))
81 $item->setQuestiontext($mattext->getContent());
83 if (strcmp($mattext->getLabel(),
"points") == 0)
85 $maxpoints = $mattext->getContent();
87 else if (strcmp($mattext->getLabel(),
"java_code") == 0)
89 $javacode = $mattext->getContent();
91 else if (strcmp($mattext->getLabel(),
"java_codebase") == 0)
93 $javacodebase = $mattext->getContent();
95 else if (strcmp($mattext->getLabel(),
"java_archive") == 0)
97 $javaarchive = $mattext->getContent();
99 else if (strlen($mattext->getLabel()) > 0)
101 array_push($params, array(
"key" => $mattext->getLabel(),
"value" => $mattext->getContent()));
104 elseif (strcmp($mat[
"type"],
"matapplet") == 0)
106 $applet = $mat[
"material"];
113 $feedbacksgeneric = array();
114 foreach ($item->resprocessing as $resprocessing)
116 foreach ($resprocessing->respcondition as $respcondition)
118 foreach ($respcondition->displayfeedback as $feedbackpointer)
120 if (strlen($feedbackpointer->getLinkrefid()))
122 foreach ($item->itemfeedback as $ifb)
124 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
127 if (count($ifb->material))
129 foreach ($ifb->material as $material)
131 $feedbacksgeneric[1] = $material;
134 if ((count($ifb->flow_mat) > 0))
136 foreach ($ifb->flow_mat as $fmat)
138 if (count($fmat->material))
140 foreach ($fmat->material as $material)
142 $feedbacksgeneric[1] = $material;
148 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
151 if (count($ifb->material))
153 foreach ($ifb->material as $material)
155 $feedbacksgeneric[0] = $material;
158 if ((count($ifb->flow_mat) > 0))
160 foreach ($ifb->flow_mat as $fmat)
162 if (count($fmat->material))
164 foreach ($fmat->material as $material)
166 $feedbacksgeneric[0] = $material;
178 $this->
object->setTitle($item->getTitle());
179 $this->
object->setNrOfTries($item->getMaxattempts());
180 $this->
object->setComment($item->getComment());
181 $this->
object->setAuthor($item->getAuthor());
182 $this->
object->setOwner($ilUser->getId());
183 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
184 $this->
object->setObjId($questionpool_id);
185 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
186 $this->
object->setJavaAppletFilename($applet->getUri());
187 $this->
object->setJavaWidth($applet->getWidth());
188 $this->
object->setJavaHeight($applet->getHeight());
189 $this->
object->setJavaCode($javacode);
190 $this->
object->setJavaCodebase($javacodebase);
191 $this->
object->setJavaArchive($javaarchive);
192 $this->
object->setPoints($maxpoints);
193 foreach ($params as $pair)
195 $this->
object->addParameter($pair[
"key"], $pair[
"value"]);
197 $this->
object->saveToDb();
198 if (count($item->suggested_solutions))
200 foreach ($item->suggested_solutions as $suggested_solution)
202 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
204 $this->
object->saveToDb();
206 $javaapplet =& base64_decode($applet->getContent());
207 $javapath = $this->
object->getJavaPath();
208 if (!file_exists($javapath))
210 include_once
"./Services/Utilities/classes/class.ilUtil.php";
213 $javapath .= $this->
object->getJavaAppletFilename();
214 $fh = fopen($javapath,
"wb");
223 $javafile = fwrite($fh, $javaapplet);
227 foreach ($feedbacksgeneric as $correctness => $material)
229 $m = $this->
object->QTIMaterialToString($material);
230 $feedbacksgeneric[$correctness] = $m;
232 $questiontext = $this->
object->getQuestion();
233 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
235 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
236 include_once
"./Services/RTE/classes/class.ilRTE.php";
237 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
248 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
252 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
253 foreach ($feedbacksgeneric as $correctness => $material)
255 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
260 foreach ($feedbacksgeneric as $correctness => $material)
264 $this->
object->saveToDb();
267 $q_1_id = $this->
object->getId();
268 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
269 $tst_object->questions[$question_counter++] = $question_id;
270 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
274 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);