ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.assNumericImport.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 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 $now = getdate();
39 $maxchars = 0;
40 $points = 0;
41 $upperlimit = 0;
42 $lowerlimit = 0;
43 $feedbacksgeneric = array();
44 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
45 foreach ($presentation->order as $entry)
46 {
47 switch ($entry["type"])
48 {
49 case "response":
50 $response = $presentation->response[$entry["index"]];
51 $rendertype = $response->getRenderType();
52 switch (strtolower(get_class($rendertype)))
53 {
54 case "ilqtirenderfib":
55 $maxchars = $rendertype->getMaxchars();
56 break;
57 }
58 break;
59 }
60 }
61
62 foreach ($item->resprocessing as $resprocessing)
63 {
64 foreach ($resprocessing->respcondition as $respcondition)
65 {
66 $conditionvar = $respcondition->getConditionvar();
67 foreach ($conditionvar->order as $order)
68 {
69 switch ($order["field"])
70 {
71 case "varlte":
72 $upperlimit = $conditionvar->varlte[$order["index"]]->getContent();
73 break;
74 case "vargte":
75 $lowerlimit = $conditionvar->vargte[$order["index"]]->getContent();
76 break;
77 }
78 }
79 foreach ($respcondition->setvar as $setvar)
80 {
81 $points = $setvar->getContent();
82 }
83 if (count($respcondition->displayfeedback))
84 {
85 foreach ($respcondition->displayfeedback as $feedbackpointer)
86 {
87 if (strlen($feedbackpointer->getLinkrefid()))
88 {
89 foreach ($item->itemfeedback as $ifb)
90 {
91 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
92 {
93 // found a feedback for the identifier
94 if (count($ifb->material))
95 {
96 foreach ($ifb->material as $material)
97 {
98 $feedbacksgeneric[1] = $material;
99 }
100 }
101 if ((count($ifb->flow_mat) > 0))
102 {
103 foreach ($ifb->flow_mat as $fmat)
104 {
105 if (count($fmat->material))
106 {
107 foreach ($fmat->material as $material)
108 {
109 $feedbacksgeneric[1] = $material;
110 }
111 }
112 }
113 }
114 }
115 else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
116 {
117 // found a feedback for the identifier
118 if (count($ifb->material))
119 {
120 foreach ($ifb->material as $material)
121 {
122 $feedbacksgeneric[0] = $material;
123 }
124 }
125 if ((count($ifb->flow_mat) > 0))
126 {
127 foreach ($ifb->flow_mat as $fmat)
128 {
129 if (count($fmat->material))
130 {
131 foreach ($fmat->material as $material)
132 {
133 $feedbacksgeneric[0] = $material;
134 }
135 }
136 }
137 }
138 }
139 }
140 }
141 }
142 }
143 }
144 }
145
146 $this->addGeneralMetadata($item);
147 $this->object->setTitle($item->getTitle());
148 $this->object->setNrOfTries($item->getMaxattempts());
149 $this->object->setComment($item->getComment());
150 $this->object->setAuthor($item->getAuthor());
151 $this->object->setOwner($ilUser->getId());
152 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
153 $this->object->setObjId($questionpool_id);
154 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
155 $this->object->setMaxChars($maxchars);
156 $this->object->setPoints($points);
157 $this->object->setLowerLimit($lowerlimit);
158 $this->object->setUpperLimit($upperlimit);
159 // additional content editing mode information
160 $this->object->setAdditionalContentEditingMode(
162 );
163 $this->object->saveToDb();
164 if (count($item->suggested_solutions))
165 {
166 foreach ($item->suggested_solutions as $suggested_solution)
167 {
168 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
169 }
170 $this->object->saveToDb();
171 }
172 foreach ($feedbacksgeneric as $correctness => $material)
173 {
174 $m = $this->object->QTIMaterialToString($material);
175 $feedbacksgeneric[$correctness] = $m;
176 }
177 // handle the import of media objects in XHTML code
178 $questiontext = $this->object->getQuestion();
179 if (is_array($_SESSION["import_mob_xhtml"]))
180 {
181 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
182 include_once "./Services/RTE/classes/class.ilRTE.php";
183 foreach ($_SESSION["import_mob_xhtml"] as $mob)
184 {
185 if ($tst_id > 0)
186 {
187 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
188 }
189 else
190 {
191 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
192 }
193
194 $GLOBALS['ilLog']->write(__METHOD__.': import mob from dir: '. $importfile);
195
196 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
197 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
198 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
199 foreach ($feedbacksgeneric as $correctness => $material)
200 {
201 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
202 }
203 }
204 }
205 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
206 foreach ($feedbacksgeneric as $correctness => $material)
207 {
208 $this->object->feedbackOBJ->importGenericFeedback(
209 $this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)
210 );
211 }
212 $this->object->saveToDb();
213 if ($tst_id > 0)
214 {
215 $q_1_id = $this->object->getId();
216 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
217 $tst_object->questions[$question_counter++] = $question_id;
218 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
219 }
220 else
221 {
222 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
223 }
224 }
225}
226
227?>
$_SESSION["AccountId"]
Class for numeric question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
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)
_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...
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilUser
Definition: imgupload.php:15