Creates a question from a QTI file.
37 $presentation = $item->getPresentation();
38 $duration = $item->getDuration();
40 $questionimage = array();
41 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
43 foreach ($presentation->order as $entry) {
44 switch ($entry[
"type"]) {
46 $response = $presentation->response[$entry[
"index"]];
48 switch (strtolower(get_class($rendertype))) {
49 case "ilqtirenderhotspot":
50 foreach ($rendertype->material as $mat) {
51 for (
$i = 0;
$i < $mat->getMaterialCount();
$i++) {
52 $m = $mat->getMaterial(
$i);
53 if (strcmp(
$m[
"type"],
"matimage") == 0) {
54 $questionimage = array(
55 "imagetype" =>
$m[
"material"]->getImageType(),
56 "label" =>
$m[
"material"]->getLabel(),
57 "content" =>
$m[
"material"]->getContent()
62 foreach ($rendertype->response_labels as $response_label) {
63 $ident = $response_label->getIdent();
65 foreach ($response_label->material as $mat) {
66 $answerhint .= $this->
object->QTIMaterialToString($mat);
68 $answers[$ident] = array(
69 "answerhint" => $answerhint,
70 "areatype" => $response_label->getRarea(),
71 "coordinates" => $response_label->getContent(),
73 "answerorder" => $response_label->getIdent(),
76 "points_unchecked" => 0
86 $feedbacksgeneric = array();
87 foreach ($item->resprocessing as $resprocessing) {
88 foreach ($resprocessing->respcondition as $respcondition) {
91 $conditionvar = $respcondition->getConditionvar();
92 foreach ($conditionvar->order as $order) {
93 switch ($order[
"field"]) {
98 $coordinates = $conditionvar->varinside[$order[
"index"]]->getContent();
101 $coordinates = $conditionvar->varequal[$order[
"index"]]->getContent();
105 foreach ($respcondition->setvar as $setvar) {
106 foreach ($answers as $ident => $answer) {
107 if (strcmp($answer[
"coordinates"], $coordinates) == 0) {
109 $answers[$ident][
"action"] = $setvar->getAction();
110 $answers[$ident][
"points"] = $setvar->getContent();
111 if (count($respcondition->displayfeedback)) {
112 foreach ($respcondition->displayfeedback as $feedbackpointer) {
113 if (strlen($feedbackpointer->getLinkrefid())) {
114 foreach ($item->itemfeedback as $ifb) {
115 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
117 if (count($ifb->material)) {
118 foreach ($ifb->material as $material) {
119 $feedbacksgeneric[1] = $material;
122 if ((count($ifb->flow_mat) > 0)) {
123 foreach ($ifb->flow_mat as $fmat) {
124 if (count($fmat->material)) {
125 foreach ($fmat->material as $material) {
126 $feedbacksgeneric[1] = $material;
131 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
133 if (count($ifb->material)) {
134 foreach ($ifb->material as $material) {
135 $feedbacksgeneric[0] = $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[0] = $material;
148 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
150 if (count($ifb->material)) {
151 foreach ($ifb->material as $material) {
152 $feedbacks[$ident] = $material;
155 if ((count($ifb->flow_mat) > 0)) {
156 foreach ($ifb->flow_mat as $fmat) {
157 if (count($fmat->material)) {
158 foreach ($fmat->material as $material) {
159 $feedbacks[$ident] = $material;
170 $answers[$ident][
"action"] = $setvar->getAction();
171 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
180 $this->
object->setTitle($item->getTitle());
181 $this->
object->setNrOfTries($item->getMaxattempts());
182 $this->
object->setComment($item->getComment());
183 $this->
object->setAuthor($item->getAuthor());
184 $this->
object->setOwner(
$ilUser->getId());
185 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
186 $this->
object->setObjId($questionpool_id);
187 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
188 $this->
object->setIsMultipleChoice($item->getMetadataEntry(
"IS_MULTIPLE_CHOICE"));
189 $areas = array(
"2" =>
"rect",
"1" =>
"circle",
"3" =>
"poly");
190 $this->
object->setImageFilename($questionimage[
"label"]);
191 foreach ($answers as $answer) {
192 $this->
object->addAnswer($answer[
"answerhint"], $answer[
"points"], $answer[
"answerorder"], $answer[
"coordinates"], $areas[$answer[
"areatype"]], $answer[
"points_unchecked"]);
195 $this->
object->setAdditionalContentEditingMode(
198 $this->
object->saveToDb();
199 if (count($item->suggested_solutions)) {
200 foreach ($item->suggested_solutions as $suggested_solution) {
201 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
203 $this->
object->saveToDb();
205 $image = &base64_decode($questionimage[
"content"]);
206 $imagepath = $this->
object->getImagePath();
207 if (!file_exists($imagepath)) {
208 include_once
"./Services/Utilities/classes/class.ilUtil.php";
211 $imagepath .= $questionimage[
"label"];
212 $fh =
fopen($imagepath,
"wb");
219 $imagefile = fwrite($fh, $image);
223 foreach ($feedbacks as $ident => $material) {
224 $m = $this->
object->QTIMaterialToString($material);
225 $feedbacks[$ident] =
$m;
227 foreach ($feedbacksgeneric as $correctness => $material) {
228 $m = $this->
object->QTIMaterialToString($material);
229 $feedbacksgeneric[$correctness] =
$m;
231 $questiontext = $this->
object->getQuestion();
232 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
233 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
234 include_once
"./Services/RTE/classes/class.ilRTE.php";
235 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
243 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
247 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
248 foreach ($feedbacks as $ident => $material) {
249 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
251 foreach ($feedbacksgeneric as $correctness => $material) {
252 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
257 foreach ($feedbacks as $ident => $material) {
258 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
259 $this->object->getId(),
265 foreach ($feedbacksgeneric as $correctness => $material) {
266 $this->
object->feedbackOBJ->importGenericFeedback(
267 $this->object->getId(),
272 $this->
object->saveToDb();
274 $q_1_id = $this->
object->getId();
275 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
276 $tst_object->questions[$question_counter++] = $question_id;
277 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
279 $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)
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...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...