Creates a question from a QTI file.
31 {
34
35
37 $presentation = $item->getPresentation();
38 $duration = $item->getDuration();
39 $shuffle = 0;
40 $idents = array();
41 $now = getdate();
42 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
43 $gaps = array();
44 foreach ($presentation->order as $entry) {
45 switch ($entry["type"]) {
46 case "response":
47 $response = $presentation->response[$entry[
"index"]];
49 array_push($idents,
$response->getIdent());
50 }
51 break;
52 }
53 }
54 $responses = array();
55 $feedbacksgeneric = array();
56 foreach ($item->resprocessing as $resprocessing) {
57 foreach ($resprocessing->respcondition as $respcondition) {
58 $ident = "";
59 $correctness = 1;
60 $conditionvar = $respcondition->getConditionvar();
61 foreach ($conditionvar->order as $order) {
62 switch ($order["field"]) {
63 case "varsubset":
64 $respident = $conditionvar->varsubset[$order["index"]]->getRespident();
65 $content = $conditionvar->varsubset[$order["index"]]->getContent();
66 if (!is_array($responses[$respident])) {
67 $responses[$respident] = array();
68 }
69 $vars = explode(",", $content);
70 foreach ($vars as $var) {
71 array_push($responses[$respident], array("solution" => $var, "points" => ""));
72 }
73 break;
74 }
75 }
76 foreach ($respcondition->setvar as $setvar) {
77 if ((strcmp($setvar->getVarname(),
"matches") == 0) && ($setvar->getAction() ==
ACTION_ADD)) {
78 foreach ($responses[$respident] as $idx => $solutionarray) {
79 if (strlen($solutionarray["points"] == 0)) {
80 $responses[$respident][$idx]["points"] = $setvar->getContent();
81 }
82 }
83 }
84 }
85 foreach ($resprocessing->respcondition as $respcondition) {
86 foreach ($respcondition->displayfeedback as $feedbackpointer) {
87 if (strlen($feedbackpointer->getLinkrefid())) {
88 foreach ($item->itemfeedback as $ifb) {
89 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
90
91 if (count($ifb->material)) {
92 foreach ($ifb->material as $material) {
93 $feedbacksgeneric[1] = $material;
94 }
95 }
96 if ((count($ifb->flow_mat) > 0)) {
97 foreach ($ifb->flow_mat as $fmat) {
98 if (count($fmat->material)) {
99 foreach ($fmat->material as $material) {
100 $feedbacksgeneric[1] = $material;
101 }
102 }
103 }
104 }
105 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
106
107 if (count($ifb->material)) {
108 foreach ($ifb->material as $material) {
109 $feedbacksgeneric[0] = $material;
110 }
111 }
112 if ((count($ifb->flow_mat) > 0)) {
113 foreach ($ifb->flow_mat as $fmat) {
114 if (count($fmat->material)) {
115 foreach ($fmat->material as $material) {
116 $feedbacksgeneric[0] = $material;
117 }
118 }
119 }
120 }
121 }
122 }
123 }
124 }
125 }
126 }
127 }
129 $this->object->setTitle($item->getTitle());
130 $this->object->setNrOfTries($item->getMaxattempts());
131 $this->object->setComment($item->getComment());
132 $this->object->setAuthor($item->getAuthor());
133 $this->
object->setOwner(
$ilUser->getId());
134 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
135 $this->object->setObjId($questionpool_id);
136 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
137 $textrating = $item->getMetadataEntry("textrating");
138 if (strlen($textrating) == 0) {
139 $textrating = "ci";
140 }
141 $this->object->setTextRating($textrating);
142 $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers"));
144 $counter = 0;
147 $this->object->addAnswer($answer["solution"], $answer["points"], $counter);
148 $counter++;
149 }
150 }
151
152 $this->object->setAdditionalContentEditingMode(
154 );
155 $this->object->saveToDb();
156 if (count($item->suggested_solutions)) {
157 foreach ($item->suggested_solutions as $suggested_solution) {
158 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
159 }
160 $this->object->saveToDb();
161 }
162 foreach ($feedbacksgeneric as $correctness => $material) {
163 $m = $this->
object->QTIMaterialToString($material);
164 $feedbacksgeneric[$correctness] =
$m;
165 }
166
167 $questiontext = $this->object->getQuestion();
168 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
169 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
170 include_once "./Services/RTE/classes/class.ilRTE.php";
171 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
172 if ($tst_id > 0) {
174 } else {
176 }
177
179 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
180
183 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
184 foreach ($feedbacksgeneric as $correctness => $material) {
185 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
186 }
187 }
188 }
190 foreach ($feedbacksgeneric as $correctness => $material) {
191 $this->object->feedbackOBJ->importGenericFeedback(
192 $this->object->getId(),
193 $correctness,
195 );
196 }
197 $this->object->saveToDb();
198 if ($tst_id > 0) {
199 $q_1_id = $this->object->getId();
200 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
201 $tst_object->questions[$question_counter++] = $question_id;
202 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
203 } else {
204 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
205 }
206 }
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...