Creates a question from a QTI file.
41 $presentation = $item->getPresentation();
42 $duration = $item->getDuration();
46 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
50 foreach ($presentation->order as $entry) {
51 switch ($entry[
"type"]) {
53 $response = $presentation->response[$entry[
"index"]];
57 } elseif (
$response->getIdent() ==
'OQNP') {
59 } elseif (
$response->getIdent() ==
'OQNT') {
61 } elseif (
$response->getIdent() ==
'OQT') {
66 switch (strtolower(get_class($rendertype))) {
67 case "ilqtirenderchoice":
68 $shuffle = $rendertype->getShuffle();
70 foreach ($rendertype->response_labels as $response_label) {
71 $ident = $response_label->getIdent();
73 foreach ($response_label->material as $mat) {
74 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
75 $foundmat = $mat->getMaterial(
$m);
77 if (strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") == 0) {
78 $answerdepth = $foundmat[
"material"]->getContent();
80 if (strcmp($foundmat[
"type"],
"mattext") == 0
81 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0) {
82 $answertext .= $foundmat[
"material"]->getContent();
84 if (strcmp($foundmat[
"type"],
"matimage") == 0
85 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0) {
88 "imagetype" => $foundmat[
"material"]->getImageType(),
89 "label" => $foundmat[
"material"]->getLabel(),
90 "content" => $foundmat[
"material"]->getContent()
95 $answers[$answerorder] =
array(
97 "answertext" => $answertext,
98 "answerimage" => $answerimage,
100 "answerorder" => $answerorder,
101 "answerdepth" => $answerdepth,
112 $responses =
array();
113 $feedbacksgeneric =
array();
114 foreach ($item->resprocessing as $resprocessing) {
115 foreach ($resprocessing->respcondition as $respcondition) {
118 $conditionvar = $respcondition->getConditionvar();
119 foreach ($conditionvar->order as $order) {
120 switch ($order[
"field"]) {
125 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
126 $orderindex = $conditionvar->varequal[$order[
"index"]]->getIndex();
130 foreach ($respcondition->setvar as $setvar) {
131 if (strcmp($ident,
"") != 0) {
132 $answers[$ident][
"solutionorder"] = $orderindex;
133 $answers[$ident][
"action"] = $setvar->getAction();
134 $answers[$ident][
"points"] = $setvar->getContent();
137 if (count($respcondition->displayfeedback)) {
138 foreach ($respcondition->displayfeedback as $feedbackpointer) {
139 if (strlen($feedbackpointer->getLinkrefid())) {
140 foreach ($item->itemfeedback as $ifb) {
141 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
143 if (count($ifb->material)) {
144 foreach ($ifb->material as $material) {
145 $feedbacksgeneric[1] = $material;
148 if ((count($ifb->flow_mat) > 0)) {
149 foreach ($ifb->flow_mat as $fmat) {
150 if (count($fmat->material)) {
151 foreach ($fmat->material as $material) {
152 $feedbacksgeneric[1] = $material;
157 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
159 if (count($ifb->material)) {
160 foreach ($ifb->material as $material) {
161 $feedbacksgeneric[0] = $material;
164 if ((count($ifb->flow_mat) > 0)) {
165 foreach ($ifb->flow_mat as $fmat) {
166 if (count($fmat->material)) {
167 foreach ($fmat->material as $material) {
168 $feedbacksgeneric[0] = $material;
184 $this->
object->setTitle($item->getTitle());
185 $this->
object->setNrOfTries($item->getMaxattempts());
186 $this->
object->setComment($item->getComment());
187 $this->
object->setAuthor($item->getAuthor());
188 $this->
object->setOwner($ilUser->getId());
189 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
190 $this->
object->setOrderingType(
$type);
191 $this->
object->setObjId($questionpool_id);
192 $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
193 $this->
object->setElementHeight($item->getMetadataEntry(
"element_height"));
194 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
195 $this->
object->setShuffle($shuffle);
197 $solanswers =
array();
199 foreach ($answers as $answer) {
200 $solanswers[$answer[
"solutionorder"]] = $answer;
204 foreach ($solanswers as $answer) {
205 $points += $answer[
"points"];
209 if ($element->isExportIdent($answer[
'ident'])) {
210 $element->setExportIdent($answer[
'ident']);
212 $element->setPosition($position++);
213 if (isset($answer[
'answerdepth'])) {
214 $element->setIndentation($answer[
'answerdepth']);
218 if ($this->
object->isImageOrderingType()) {
219 $element->setContent($answer[
"answerimage"][
"label"]);
221 $element->setContent($answer[
"answertext"]);
224 $this->
object->getOrderingElementList()->addElement($element);
226 $points = ($item->getMetadataEntry(
"points") > 0) ? $item->getMetadataEntry(
"points") : $points;
227 $this->
object->setPoints($points);
229 $this->
object->setAdditionalContentEditingMode(
232 $this->
object->saveToDb();
233 if (count($item->suggested_solutions)) {
234 foreach ($item->suggested_solutions as $suggested_solution) {
235 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
237 $this->
object->saveToDb();
239 foreach ($answers as $answer) {
241 include_once
"./Services/Utilities/classes/class.ilUtil.php";
242 if (strlen($answer[
'answerimage'][
'label']) && strlen($answer[
'answerimage'][
'content'])) {
243 $image =&base64_decode($answer[
"answerimage"][
"content"]);
244 $imagepath = $this->
object->getImagePath();
245 if (!file_exists($imagepath)) {
248 $imagepath .= $answer[
"answerimage"][
"label"];
249 $fh = fopen($imagepath,
"wb");
255 $imagefile = fwrite(
$fh, $image);
259 $thumbpath = $imagepath .
"." .
"thumb.jpg";
264 foreach ($feedbacksgeneric as $correctness => $material) {
265 $m = $this->
object->QTIMaterialToString($material);
266 $feedbacksgeneric[$correctness] =
$m;
268 $questiontext = $this->
object->getQuestion();
271 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
272 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
273 include_once
"./Services/RTE/classes/class.ilRTE.php";
274 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
281 $GLOBALS[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
285 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
286 foreach ($this->
object->getOrderingElementList() as $element) {
287 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
289 foreach ($feedbacksgeneric as $correctness => $material) {
290 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
292 foreach ($itemfeedbacks as $ident => $material) {
293 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
298 foreach ($this->
object->getOrderingElementList() as $element) {
301 foreach ($feedbacksgeneric as $correctness => $material) {
302 $this->
object->feedbackOBJ->importGenericFeedback(
308 foreach ($itemfeedbacks as $ident => $material) {
311 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
317 $this->
object->saveToDb();
319 $this->
object->setObjId($tst_id);
320 $tstQid = $this->
object->getId();
321 $qplQid = $this->
object->duplicate(
true, null, null, null, $questionpool_id);
324 $tst_object->questions[$question_counter++] = $tstQid;
325 $import_mapping[$item->getIdent()] =
array(
"pool" => $qplQid,
"test" => $tstQid);
327 $import_mapping[$item->getIdent()] =
array(
"pool" => $this->
object->getId(),
"test" => 0);
static resetOriginalId($questionId)
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
addGeneralMetadata(ilQTIItem $item)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
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...
const OQ_PICTURES
Ordering question constants.
static convertImage( $a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static saveOriginalId($questionId, $originalId)
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')