ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.assTextSubsetImport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
5
16{
30 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
31 {
32 global $ilUser;
33
34 // empty session variable for imported xhtml mobs
35 unset($_SESSION["import_mob_xhtml"]);
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
38 $shuffle = 0;
39 $idents = array();
40 $now = getdate();
41 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
42 $gaps = array();
43 foreach ($presentation->order as $entry) {
44 switch ($entry["type"]) {
45 case "response":
46 $response = $presentation->response[$entry["index"]];
47 if ($response->getResponseType() == RT_RESPONSE_STR) {
48 array_push($idents, $response->getIdent());
49 }
50 break;
51 }
52 }
53 $responses = array();
54 $feedbacksgeneric = array();
55 foreach ($item->resprocessing as $resprocessing) {
56 foreach ($resprocessing->respcondition as $respcondition) {
57 $ident = "";
58 $correctness = 1;
59 $conditionvar = $respcondition->getConditionvar();
60 foreach ($conditionvar->order as $order) {
61 switch ($order["field"]) {
62 case "varsubset":
63 $respident = $conditionvar->varsubset[$order["index"]]->getRespident();
64 $content = $conditionvar->varsubset[$order["index"]]->getContent();
65 if (!is_array($responses[$respident])) {
66 $responses[$respident] = array();
67 }
68 $vars = explode(",", $content);
69 foreach ($vars as $var) {
70 array_push($responses[$respident], array("solution" => $var, "points" => ""));
71 }
72 break;
73 }
74 }
75 foreach ($respcondition->setvar as $setvar) {
76 if ((strcmp($setvar->getVarname(), "matches") == 0) && ($setvar->getAction() == ACTION_ADD)) {
77 foreach ($responses[$respident] as $idx => $solutionarray) {
78 if (strlen($solutionarray["points"] == 0)) {
79 $responses[$respident][$idx]["points"] = $setvar->getContent();
80 }
81 }
82 }
83 }
84 foreach ($resprocessing->respcondition as $respcondition) {
85 foreach ($respcondition->displayfeedback as $feedbackpointer) {
86 if (strlen($feedbackpointer->getLinkrefid())) {
87 foreach ($item->itemfeedback as $ifb) {
88 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
89 // found a feedback for the identifier
90 if (count($ifb->material)) {
91 foreach ($ifb->material as $material) {
92 $feedbacksgeneric[1] = $material;
93 }
94 }
95 if ((count($ifb->flow_mat) > 0)) {
96 foreach ($ifb->flow_mat as $fmat) {
97 if (count($fmat->material)) {
98 foreach ($fmat->material as $material) {
99 $feedbacksgeneric[1] = $material;
100 }
101 }
102 }
103 }
104 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
105 // found a feedback for the identifier
106 if (count($ifb->material)) {
107 foreach ($ifb->material as $material) {
108 $feedbacksgeneric[0] = $material;
109 }
110 }
111 if ((count($ifb->flow_mat) > 0)) {
112 foreach ($ifb->flow_mat as $fmat) {
113 if (count($fmat->material)) {
114 foreach ($fmat->material as $material) {
115 $feedbacksgeneric[0] = $material;
116 }
117 }
118 }
119 }
120 }
121 }
122 }
123 }
124 }
125 }
126 }
127 $this->addGeneralMetadata($item);
128 $this->object->setTitle($item->getTitle());
129 $this->object->setNrOfTries($item->getMaxattempts());
130 $this->object->setComment($item->getComment());
131 $this->object->setAuthor($item->getAuthor());
132 $this->object->setOwner($ilUser->getId());
133 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
134 $this->object->setObjId($questionpool_id);
135 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
136 $textrating = $item->getMetadataEntry("textrating");
137 if (strlen($textrating) == 0) {
138 $textrating = "ci";
139 }
140 $this->object->setTextRating($textrating);
141 $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers"));
142 $response = current($responses);
143 $counter = 0;
144 if (is_array($response)) {
145 foreach ($response as $answer) {
146 $this->object->addAnswer($answer["solution"], $answer["points"], $counter);
147 $counter++;
148 }
149 }
150 // additional content editing mode information
151 $this->object->setAdditionalContentEditingMode(
153 );
154 $this->object->saveToDb();
155 if (count($item->suggested_solutions)) {
156 foreach ($item->suggested_solutions as $suggested_solution) {
157 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
158 }
159 $this->object->saveToDb();
160 }
161 foreach ($feedbacksgeneric as $correctness => $material) {
162 $m = $this->object->QTIMaterialToString($material);
163 $feedbacksgeneric[$correctness] = $m;
164 }
165 // handle the import of media objects in XHTML code
166 $questiontext = $this->object->getQuestion();
167 if (is_array($_SESSION["import_mob_xhtml"])) {
168 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
169 include_once "./Services/RTE/classes/class.ilRTE.php";
170 foreach ($_SESSION["import_mob_xhtml"] as $mob) {
171 if ($tst_id > 0) {
172 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
173 } else {
174 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
175 }
176
177 $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
178
179 $media_object =&ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
180 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
181 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
182 foreach ($feedbacksgeneric as $correctness => $material) {
183 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
184 }
185 }
186 }
187 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
188 foreach ($feedbacksgeneric as $correctness => $material) {
189 $this->object->feedbackOBJ->importGenericFeedback(
190 $this->object->getId(),
191 $correctness,
193 );
194 }
195 $this->object->saveToDb();
196 if ($tst_id > 0) {
197 $q_1_id = $this->object->getId();
198 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
199 $tst_object->questions[$question_counter++] = $question_id;
200 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
201 } else {
202 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
203 }
204 }
205}
sprintf('%.4f', $callTime)
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const RT_RESPONSE_STR
const ACTION_ADD
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)
Class for text subset question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=true)
Create new media object and update page in db and return new media object.
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...
$counter
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$response
$ilUser
Definition: imgupload.php:18