Creates a question from a QTI file.
31 {
33
34
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
38 $now = getdate();
39 $maxchars = 0;
40 $maxpoints = 0;
41 $created =
sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
42 foreach ($presentation->order as $entry) {
43 switch ($entry["type"]) {
44 case "response":
45 $response = $presentation->response[$entry[
"index"]];
47 switch (strtolower(get_class($rendertype))) {
48 case "ilqtirenderfib":
49 $maxchars = $rendertype->getMaxchars();
50 break;
51 }
52 break;
53 }
54 }
55
56 $feedbacksgeneric = array();
57 foreach ($item->resprocessing as $resprocessing) {
58 $outcomes = $resprocessing->getOutcomes();
59 foreach ($outcomes->decvar as $decvar) {
60 $maxpoints = $decvar->getMaxvalue();
61 }
62
63 foreach ($resprocessing->respcondition as $respcondition) {
64 foreach ($respcondition->displayfeedback as $feedbackpointer) {
65 if (strlen($feedbackpointer->getLinkrefid())) {
66 foreach ($item->itemfeedback as $ifb) {
67 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
68
69 if (count($ifb->material)) {
70 foreach ($ifb->material as $material) {
71 $feedbacksgeneric[1] = $material;
72 }
73 }
74 if ((count($ifb->flow_mat) > 0)) {
75 foreach ($ifb->flow_mat as $fmat) {
76 if (count($fmat->material)) {
77 foreach ($fmat->material as $material) {
78 $feedbacksgeneric[1] = $material;
79 }
80 }
81 }
82 }
83 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
84
85 if (count($ifb->material)) {
86 foreach ($ifb->material as $material) {
87 $feedbacksgeneric[0] = $material;
88 }
89 }
90 if ((count($ifb->flow_mat) > 0)) {
91 foreach ($ifb->flow_mat as $fmat) {
92 if (count($fmat->material)) {
93 foreach ($fmat->material as $material) {
94 $feedbacksgeneric[0] = $material;
95 }
96 }
97 }
98 }
99 }
100 }
101 }
102 }
103 }
104 }
106 $this->object->setTitle($item->getTitle());
107 $this->object->setNrOfTries($item->getMaxattempts());
108 $this->object->setComment($item->getComment());
109 $this->object->setAuthor($item->getAuthor());
110 $this->object->setOwner($ilUser->getId());
111 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
112 $this->object->setObjId($questionpool_id);
113 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
114 $this->object->setPoints($maxpoints);
115 $this->object->setMaxNumOfChars($maxchars);
116 $textrating = $item->getMetadataEntry("textrating");
117 if (strlen($textrating)) {
118 $this->object->setTextRating($textrating);
119 }
120 $this->object->matchcondition = (strlen($item->getMetadataEntry('matchcondition'))) ? $item->getMetadataEntry('matchcondition') : 0;
121
122 require_once './Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php';
123 $no_keywords_found=true;
124
126 for (
$i = 0;
$i < count($termscoring);
$i++) {
127 $this->
object->addAnswer($termscoring[
$i]->getAnswertext(), $termscoring[
$i]->getPoints());
128 $no_keywords_found=false;
129 }
130 if (count($termscoring)) {
131 $this->object->setKeywordRelation($item->getMetadataEntry('termrelation'));
132 }
133
134 $keywords = $item->getMetadataEntry("keywords");
135 if (strlen($keywords)) {
136 #$this->object->setKeywords($keywords);
137 $answers = explode(' ', $keywords);
138 foreach ($answers as $answer) {
139 $this->object->addAnswer($answer, 0);
140 }
141 $this->object->setKeywordRelation('one');
142 $no_keywords_found=false;
143 }
144 if ($no_keywords_found) {
145 $this->object->setKeywordRelation('non');
146 }
147
148
149 $this->object->setAdditionalContentEditingMode(
151 );
152 $this->object->saveToDb();
153 if (count($item->suggested_solutions)) {
154 foreach ($item->suggested_solutions as $suggested_solution) {
155 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
156 }
157 $this->object->saveToDb();
158 }
159 foreach ($feedbacksgeneric as $correctness => $material) {
160 $m = $this->
object->QTIMaterialToString($material);
161 $feedbacksgeneric[$correctness] =
$m;
162 }
163
164 $questiontext = $this->object->getQuestion();
165
167
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
178 $GLOBALS[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
179
182 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
183 foreach ($feedbacks as $ident => $material) {
184 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
185 }
186 foreach ($feedbacksgeneric as $correctness => $material) {
187 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
188 }
189 }
190 }
192 foreach ($feedbacks as $ident => $material) {
194
195 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
196 $this->object->getId(),
199 );
200 }
201 foreach ($feedbacksgeneric as $correctness => $material) {
202 $this->object->feedbackOBJ->importGenericFeedback(
203 $this->object->getId(),
204 $correctness,
206 );
207 }
208 $this->object->saveToDb();
209 if ($tst_id > 0) {
210 $q_1_id = $this->object->getId();
211 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
212 $tst_object->questions[$question_counter++] = $question_id;
213 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
214 } else {
215 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
216 }
217 }
sprintf('%.4f', $callTime)
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
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)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
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...
$GLOBALS['loaded']
Global hash that tracks already loaded includes.