4 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
30 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
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();
52 foreach ($rendertype->response_labels as $response_label) {
53 $ident = $response_label->getIdent();
55 $answerimage =
array();
56 foreach ($response_label->material as $mat) {
58 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
59 $foundmat = $mat->getMaterial(
$m);
60 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
62 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
63 if (strlen($foundmat[
"material"]->getEmbedded())) {
69 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
70 $foundmat = $mat->getMaterial(
$m);
71 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
72 $answertext .= $foundmat[
"material"]->getContent();
74 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
77 "imagetype" => $foundmat[
"material"]->getImageType(),
78 "label" => $foundmat[
"material"]->getLabel(),
79 "content" => $foundmat[
"material"]->getContent()
84 $answertext = $this->
object->QTIMaterialToString($mat);
87 $answers[$ident] =
array(
88 "answertext" => $answertext,
89 "imagefile" => $answerimage,
91 "answerorder" => $answerorder++,
92 "points_unchecked" => 0,
101 $responses =
array();
102 $feedbacks =
array();
103 $feedbacksgeneric =
array();
104 foreach ($item->resprocessing as $resprocessing) {
105 foreach ($resprocessing->respcondition as $respcondition) {
108 $conditionvar = $respcondition->getConditionvar();
109 foreach ($conditionvar->order as $order) {
110 switch ($order[
"field"]) {
115 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
119 foreach ($respcondition->setvar as $setvar) {
120 if (strcmp($ident,
"") != 0) {
122 $answers[$ident][
"action"] = $setvar->getAction();
123 $answers[$ident][
"points"] = $setvar->getContent();
124 if (count($respcondition->displayfeedback)) {
125 foreach ($respcondition->displayfeedback as $feedbackpointer) {
126 if (strlen($feedbackpointer->getLinkrefid())) {
127 foreach ($item->itemfeedback as $ifb) {
128 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
130 if (count($ifb->material)) {
131 foreach ($ifb->material as $material) {
132 $feedbacksgeneric[1] = $material;
135 if ((count($ifb->flow_mat) > 0)) {
136 foreach ($ifb->flow_mat as $fmat) {
137 if (count($fmat->material)) {
138 foreach ($fmat->material as $material) {
139 $feedbacksgeneric[1] = $material;
144 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
146 if (count($ifb->material)) {
147 foreach ($ifb->material as $material) {
148 $feedbacksgeneric[0] = $material;
151 if ((count($ifb->flow_mat) > 0)) {
152 foreach ($ifb->flow_mat as $fmat) {
153 if (count($fmat->material)) {
154 foreach ($fmat->material as $material) {
155 $feedbacksgeneric[0] = $material;
161 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
163 if (count($ifb->material)) {
164 foreach ($ifb->material as $material) {
165 $feedbacks[$ident] = $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 $feedbacks[$ident] = $material;
183 $answers[$ident][
"action"] = $setvar->getAction();
184 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
191 $this->
object->setTitle($item->getTitle());
192 $this->
object->setNrOfTries($item->getMaxattempts());
193 $this->
object->setComment($item->getComment());
194 $this->
object->setAuthor($item->getAuthor());
195 $this->
object->setOwner($ilUser->getId());
196 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
197 $this->
object->setObjId($questionpool_id);
198 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
199 $this->
object->setShuffle($shuffle);
200 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
201 foreach ($answers as $answer) {
202 if ($item->getMetadataEntry(
'singleline') || (is_array($answer[
"imagefile"]) && count($answer[
"imagefile"]) > 0)) {
203 $this->
object->isSingleline =
true;
205 $this->
object->addAnswer($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"], $answer[
"imagefile"][
"label"]);
208 $this->
object->setAdditionalContentEditingMode(
211 $this->
object->saveToDb();
212 foreach ($answers as $answer) {
213 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0)) {
214 $image =&base64_decode($answer[
"imagefile"][
"content"]);
215 $imagepath = $this->
object->getImagePath();
216 include_once
"./Services/Utilities/classes/class.ilUtil.php";
217 if (!file_exists($imagepath)) {
220 $imagepath .= $answer[
"imagefile"][
"label"];
221 $fh = fopen($imagepath,
"wb");
224 $imagefile = fwrite(
$fh, $image);
230 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
231 if (!is_null($feedbackSetting)) {
232 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedbackSetting);
235 foreach ($feedbacks as $ident => $material) {
236 $m = $this->
object->QTIMaterialToString($material);
237 $feedbacks[$ident] =
$m;
239 foreach ($feedbacksgeneric as $correctness => $material) {
240 $m = $this->
object->QTIMaterialToString($material);
241 $feedbacksgeneric[$correctness] =
$m;
244 $questiontext = $this->
object->getQuestion();
245 $answers =&$this->
object->getAnswers();
246 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
247 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
248 include_once
"./Services/RTE/classes/class.ilRTE.php";
249 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
256 $GLOBALS[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
260 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
261 foreach ($answers as
$key => $value) {
262 $answer_obj = $answers[
$key];
263 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
265 foreach ($feedbacks as $ident => $material) {
266 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
268 foreach ($feedbacksgeneric as $correctness => $material) {
269 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
274 foreach ($answers as
$key => $value) {
275 $answer_obj =&$answers[
$key];
278 foreach ($feedbacks as $ident => $material) {
279 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
285 foreach ($feedbacksgeneric as $correctness => $material) {
286 $this->
object->feedbackOBJ->importGenericFeedback(
292 $this->
object->saveToDb();
293 if (count($item->suggested_solutions)) {
294 foreach ($item->suggested_solutions as $suggested_solution) {
295 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
297 $this->
object->saveToDb();
300 $q_1_id = $this->
object->getId();
301 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
302 $tst_object->questions[$question_counter++] = $question_id;
303 $import_mapping[$item->getIdent()] =
array(
"pool" => $q_1_id,
"test" => $question_id);
305 $import_mapping[$item->getIdent()] =
array(
"pool" => $this->
object->getId(),
"test" => 0);
static makeDirParents($a_dir)
Create a new directory and all parent directories.
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 single choice question imports.
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.