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)
35 $presentation = $item->getPresentation();
36 $duration = $item->getDuration();
38 $selectionLimit =
null;
40 $created =
sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
42 foreach ($presentation->order as $entry) {
43 switch ($entry[
"type"]) {
45 $response = $presentation->response[$entry[
"index"]];
47 switch (strtolower(get_class(
$response->getRenderType()))) {
48 case "ilqtirenderchoice":
49 $shuffle = $rendertype->getShuffle();
50 if ($rendertype->getMaxnumber()) {
51 $selectionLimit = $rendertype->getMaxnumber();
55 foreach ($rendertype->response_labels as $response_label) {
56 $ident = $response_label->getIdent();
58 $answerimage = array();
59 foreach ($response_label->material as $mat) {
61 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
62 $foundmat = $mat->getMaterial(
$m);
63 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
65 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
66 if (strlen($foundmat[
"material"]->getEmbedded())) {
72 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
73 $foundmat = $mat->getMaterial(
$m);
74 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
75 $answertext .= $foundmat[
"material"]->getContent();
77 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
80 "imagetype" => $foundmat[
"material"]->getImageType(),
81 "label" => $foundmat[
"material"]->getLabel(),
82 "content" => $foundmat[
"material"]->getContent()
87 $answertext = $this->
object->QTIMaterialToString($mat);
90 $answers[$ident] = array(
91 "answertext" => $answertext,
92 "imagefile" => $answerimage,
94 "answerorder" => $answerorder++,
95 "points_unchecked" => 0,
104 $responses = array();
105 $feedbacks = array();
106 $feedbacksgeneric = array();
107 foreach ($item->resprocessing as $resprocessing) {
108 foreach ($resprocessing->respcondition as $respcondition) {
111 $conditionvar = $respcondition->getConditionvar();
112 foreach ($conditionvar->order as $order) {
113 switch ($order[
"field"]) {
118 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
122 foreach ($respcondition->setvar as $setvar) {
123 if (strcmp($ident,
"") != 0) {
125 $answers[$ident][
"action"] = $setvar->getAction();
126 $answers[$ident][
"points"] = $setvar->getContent();
127 if (count($respcondition->displayfeedback)) {
128 foreach ($respcondition->displayfeedback as $feedbackpointer) {
129 if (strlen($feedbackpointer->getLinkrefid())) {
130 foreach ($item->itemfeedback as $ifb) {
131 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
133 if (count($ifb->material)) {
134 foreach ($ifb->material as $material) {
135 $feedbacksgeneric[1] = $material;
138 if ((count($ifb->flow_mat) > 0)) {
139 foreach ($ifb->flow_mat as $fmat) {
140 if (count($fmat->material)) {
141 foreach ($fmat->material as $material) {
142 $feedbacksgeneric[1] = $material;
147 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
149 if (count($ifb->material)) {
150 foreach ($ifb->material as $material) {
151 $feedbacksgeneric[0] = $material;
154 if ((count($ifb->flow_mat) > 0)) {
155 foreach ($ifb->flow_mat as $fmat) {
156 if (count($fmat->material)) {
157 foreach ($fmat->material as $material) {
158 $feedbacksgeneric[0] = $material;
164 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
166 if (count($ifb->material)) {
167 foreach ($ifb->material as $material) {
168 $feedbacks[$ident] = $material;
171 if ((count($ifb->flow_mat) > 0)) {
172 foreach ($ifb->flow_mat as $fmat) {
173 if (count($fmat->material)) {
174 foreach ($fmat->material as $material) {
175 $feedbacks[$ident] = $material;
186 $answers[$ident][
"action"] = $setvar->getAction();
187 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
194 $this->
object->setTitle($item->getTitle());
195 $this->
object->setNrOfTries($item->getMaxattempts());
196 $this->
object->setComment($item->getComment());
197 $this->
object->setAuthor($item->getAuthor());
198 $this->
object->setOwner($ilUser->getId());
199 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
200 $this->
object->setObjId($questionpool_id);
201 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
202 $this->
object->setShuffle($shuffle);
203 $this->
object->setSelectionLimit($selectionLimit);
204 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
206 foreach ($answers as $answer) {
207 if ($item->getMetadataEntry(
'singleline') || (is_array($answer[
"imagefile"]) && count($answer[
"imagefile"]) > 0)) {
208 $this->
object->isSingleline =
true;
210 $this->
object->addAnswer($answer[
"answertext"], $answer[
"points"], $answer[
"points_unchecked"], $answer[
"answerorder"], $answer[
"imagefile"][
"label"]);
213 $this->
object->setAdditionalContentEditingMode(
216 $this->
object->saveToDb();
217 foreach ($answers as $answer) {
218 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0)) {
219 $image =&base64_decode($answer[
"imagefile"][
"content"]);
220 $imagepath = $this->
object->getImagePath();
221 include_once
"./Services/Utilities/classes/class.ilUtil.php";
222 if (!file_exists($imagepath)) {
225 $imagepath .= $answer[
"imagefile"][
"label"];
226 $fh = fopen($imagepath,
"wb");
229 $imagefile = fwrite(
$fh, $image);
235 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
236 if (!is_null($feedbackSetting)) {
237 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
241 foreach ($feedbacks as $ident => $material) {
242 $m = $this->
object->QTIMaterialToString($material);
243 $feedbacks[$ident] =
$m;
245 foreach ($feedbacksgeneric as $correctness => $material) {
246 $m = $this->
object->QTIMaterialToString($material);
247 $feedbacksgeneric[$correctness] =
$m;
249 $questiontext = $this->
object->getQuestion();
250 $answers =&$this->
object->getAnswers();
251 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
252 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
253 include_once
"./Services/RTE/classes/class.ilRTE.php";
254 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
261 $GLOBALS[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
265 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
266 foreach ($answers as
$key => $value) {
267 $answer_obj =&$answers[
$key];
268 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
270 foreach ($feedbacks as $ident => $material) {
271 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
273 foreach ($feedbacksgeneric as $correctness => $material) {
274 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
279 foreach ($answers as
$key => $value) {
280 $answer_obj =&$answers[
$key];
283 foreach ($feedbacks as $ident => $material) {
284 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
285 $this->object->getId(),
290 foreach ($feedbacksgeneric as $correctness => $material) {
291 $this->
object->feedbackOBJ->importGenericFeedback(
292 $this->object->getId(),
297 $this->
object->saveToDb();
298 if (count($item->suggested_solutions)) {
299 foreach ($item->suggested_solutions as $suggested_solution) {
300 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
302 $this->
object->saveToDb();
305 $q_1_id = $this->
object->getId();
306 $question_id = $this->
object->duplicate(
true,
null,
null,
null, $tst_id);
307 $tst_object->questions[$question_counter++] = $question_id;
308 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
310 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Class for multiple choice question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
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)
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.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.