Creates a question from a QTI file.
31 {
34
35
37 $presentation = $item->getPresentation();
38 $duration = $item->getDuration();
39 $now = getdate();
40 $applet = null;
41 $maxpoints = 0;
42 $javacode = "";
43 $javacodebase = "";
44 $javaarchive = "";
45 $params = array();
46 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
47 $answers = array();
48 foreach ($presentation->order as $entry) {
49 switch ($entry["type"]) {
50 case "material":
51 $material = $presentation->material[$entry["index"]];
52 for (
$i = 0;
$i < $material->getMaterialCount();
$i++) {
53 $mat = $material->getMaterial(
$i);
54 if (strcmp($mat["type"], "mattext") == 0) {
55 $mattext = $mat["material"];
56 if ((strlen($mattext->getLabel()) == 0) && (strlen($this->object->QTIMaterialToString($item->getQuestiontext())) == 0)) {
57 $item->setQuestiontext($mattext->getContent());
58 }
59 if (strcmp($mattext->getLabel(), "points") == 0) {
60 $maxpoints = $mattext->getContent();
61 } elseif (strcmp($mattext->getLabel(), "java_code") == 0) {
62 $javacode = $mattext->getContent();
63 } elseif (strcmp($mattext->getLabel(), "java_codebase") == 0) {
64 $javacodebase = $mattext->getContent();
65 } elseif (strcmp($mattext->getLabel(), "java_archive") == 0) {
66 $javaarchive = $mattext->getContent();
67 } elseif (strlen($mattext->getLabel()) > 0) {
68 array_push($params, array("key" => $mattext->getLabel(), "value" => $mattext->getContent()));
69 }
70 } elseif (strcmp($mat["type"], "matapplet") == 0) {
71 $applet = $mat["material"];
72 }
73 }
74 break;
75 }
76 }
77
78 $feedbacksgeneric = array();
79 foreach ($item->resprocessing as $resprocessing) {
80 foreach ($resprocessing->respcondition as $respcondition) {
81 foreach ($respcondition->displayfeedback as $feedbackpointer) {
82 if (strlen($feedbackpointer->getLinkrefid())) {
83 foreach ($item->itemfeedback as $ifb) {
84 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
85
86 if (count($ifb->material)) {
87 foreach ($ifb->material as $material) {
88 $feedbacksgeneric[1] = $material;
89 }
90 }
91 if ((count($ifb->flow_mat) > 0)) {
92 foreach ($ifb->flow_mat as $fmat) {
93 if (count($fmat->material)) {
94 foreach ($fmat->material as $material) {
95 $feedbacksgeneric[1] = $material;
96 }
97 }
98 }
99 }
100 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
101
102 if (count($ifb->material)) {
103 foreach ($ifb->material as $material) {
104 $feedbacksgeneric[0] = $material;
105 }
106 }
107 if ((count($ifb->flow_mat) > 0)) {
108 foreach ($ifb->flow_mat as $fmat) {
109 if (count($fmat->material)) {
110 foreach ($fmat->material as $material) {
111 $feedbacksgeneric[0] = $material;
112 }
113 }
114 }
115 }
116 }
117 }
118 }
119 }
120 }
121 }
122
124 $this->object->setTitle($item->getTitle());
125 $this->object->setNrOfTries($item->getMaxattempts());
126 $this->object->setComment($item->getComment());
127 $this->object->setAuthor($item->getAuthor());
128 $this->
object->setOwner(
$ilUser->getId());
129 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
130 $this->object->setObjId($questionpool_id);
131 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
132 $this->object->setJavaAppletFilename($applet->getUri());
133 $this->object->setJavaWidth($applet->getWidth());
134 $this->object->setJavaHeight($applet->getHeight());
135 $this->object->setJavaCode($javacode);
136 $this->object->setJavaCodebase($javacodebase);
137 $this->object->setJavaArchive($javaarchive);
138 $this->object->setPoints($maxpoints);
139 foreach ($params as $pair) {
140 $this->object->addParameter($pair["key"], $pair["value"]);
141 }
142
143 $this->object->setAdditionalContentEditingMode(
145 );
146 $this->object->saveToDb();
147 if (count($item->suggested_solutions)) {
148 foreach ($item->suggested_solutions as $suggested_solution) {
149 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
150 }
151 $this->object->saveToDb();
152 }
153 $javaapplet = &base64_decode($applet->getContent());
154 $javapath = $this->object->getJavaPath();
155 if (!file_exists($javapath)) {
156 include_once "./Services/Utilities/classes/class.ilUtil.php";
158 }
159 $javapath .= $this->object->getJavaAppletFilename();
160 $fh = fopen($javapath, "wb");
161 if ($fh == false) {
162
163
164
165
166 } else {
167 $javafile = fwrite($fh, $javaapplet);
168 fclose($fh);
169 }
170
171 foreach ($feedbacksgeneric as $correctness => $material) {
172 $m = $this->object->QTIMaterialToString($material);
173 $feedbacksgeneric[$correctness] = $m;
174 }
175 $questiontext = $this->object->getQuestion();
176 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
177 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
178 include_once "./Services/RTE/classes/class.ilRTE.php";
179 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
180 if ($tst_id > 0) {
182 } else {
184 }
185
187 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
188
191 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
192 foreach ($feedbacksgeneric as $correctness => $material) {
193 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
194 }
195 }
196 }
198 foreach ($feedbacksgeneric as $correctness => $material) {
199 $this->object->feedbackOBJ->importGenericFeedback(
200 $this->object->getId(),
201 $correctness,
203 );
204 }
205 $this->object->saveToDb();
206 if ($tst_id > 0) {
207 $q_1_id = $this->object->getId();
208 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
209 $tst_object->questions[$question_counter++] = $question_id;
210 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
211 } else {
212 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
213 }
214 }
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.