Creates a question from a QTI file.
31 {
34
35
37 $presentation = $item->getPresentation();
38 $duration = $item->getDuration();
39 $now = getdate();
40 $maxchars = 0;
41 $points = 0;
42 $upperlimit = 0;
43 $lowerlimit = 0;
44 $feedbacksgeneric = array();
45 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
46 foreach ($presentation->order as $entry) {
47 switch ($entry["type"]) {
48 case "response":
49 $response = $presentation->response[$entry[
"index"]];
51 switch (strtolower(get_class($rendertype))) {
52 case "ilqtirenderfib":
53 $maxchars = $rendertype->getMaxchars();
54 break;
55 }
56 break;
57 }
58 }
59
60 foreach ($item->resprocessing as $resprocessing) {
61 foreach ($resprocessing->respcondition as $respcondition) {
62 $conditionvar = $respcondition->getConditionvar();
63 foreach ($conditionvar->order as $order) {
64 switch ($order["field"]) {
65 case "varlte":
66 $upperlimit = $conditionvar->varlte[$order["index"]]->getContent();
67 break;
68 case "vargte":
69 $lowerlimit = $conditionvar->vargte[$order["index"]]->getContent();
70 break;
71 }
72 }
73 foreach ($respcondition->setvar as $setvar) {
74 $points = $setvar->getContent();
75 }
76 if (count($respcondition->displayfeedback)) {
77 foreach ($respcondition->displayfeedback as $feedbackpointer) {
78 if (strlen($feedbackpointer->getLinkrefid())) {
79 foreach ($item->itemfeedback as $ifb) {
80 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
81
82 if (count($ifb->material)) {
83 foreach ($ifb->material as $material) {
84 $feedbacksgeneric[1] = $material;
85 }
86 }
87 if ((count($ifb->flow_mat) > 0)) {
88 foreach ($ifb->flow_mat as $fmat) {
89 if (count($fmat->material)) {
90 foreach ($fmat->material as $material) {
91 $feedbacksgeneric[1] = $material;
92 }
93 }
94 }
95 }
96 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
97
98 if (count($ifb->material)) {
99 foreach ($ifb->material as $material) {
100 $feedbacksgeneric[0] = $material;
101 }
102 }
103 if ((count($ifb->flow_mat) > 0)) {
104 foreach ($ifb->flow_mat as $fmat) {
105 if (count($fmat->material)) {
106 foreach ($fmat->material as $material) {
107 $feedbacksgeneric[0] = $material;
108 }
109 }
110 }
111 }
112 }
113 }
114 }
115 }
116 }
117 }
118 }
119
121 $this->object->setTitle($item->getTitle());
122 $this->object->setNrOfTries($item->getMaxattempts());
123 $this->object->setComment($item->getComment());
124 $this->object->setAuthor($item->getAuthor());
125 $this->
object->setOwner(
$ilUser->getId());
126 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
127 $this->object->setObjId($questionpool_id);
128 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
129 $this->object->setMaxChars($maxchars);
130 $this->object->setPoints($points);
131 $this->object->setLowerLimit($lowerlimit);
132 $this->object->setUpperLimit($upperlimit);
133
134 $this->object->setAdditionalContentEditingMode(
136 );
137 $this->object->saveToDb();
138 if (count($item->suggested_solutions)) {
139 foreach ($item->suggested_solutions as $suggested_solution) {
140 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
141 }
142 $this->object->saveToDb();
143 }
144 foreach ($feedbacksgeneric as $correctness => $material) {
145 $m = $this->object->QTIMaterialToString($material);
146 $feedbacksgeneric[$correctness] = $m;
147 }
148
149 $questiontext = $this->object->getQuestion();
150 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
151 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
152 include_once "./Services/RTE/classes/class.ilRTE.php";
153 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
154 if ($tst_id > 0) {
156 } else {
158 }
159
161 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
162
165 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
166 foreach ($feedbacksgeneric as $correctness => $material) {
167 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
168 }
169 }
170 }
172 foreach ($feedbacksgeneric as $correctness => $material) {
173 $this->object->feedbackOBJ->importGenericFeedback(
174 $this->object->getId(),
175 $correctness,
177 );
178 }
179 $this->object->saveToDb();
180 if ($tst_id > 0) {
181 $q_1_id = $this->object->getId();
182 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
183 $tst_object->questions[$question_counter++] = $question_id;
184 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
185 } else {
186 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
187 }
188 }
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...