Creates a question from a QTI file.
42 $presentation = $item->getPresentation();
43 $duration = $item->getDuration();
47 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
51 foreach ($presentation->order as $entry) {
52 switch ($entry[
"type"]) {
54 $response = $presentation->response[$entry[
"index"]];
58 } elseif (
$response->getIdent() ==
'OQNP') {
60 } elseif (
$response->getIdent() ==
'OQNT') {
62 } elseif (
$response->getIdent() ==
'OQT') {
67 switch (strtolower(get_class($rendertype))) {
68 case "ilqtirenderchoice":
69 $shuffle = $rendertype->getShuffle();
71 foreach ($rendertype->response_labels as $response_label) {
72 $ident = $response_label->getIdent();
74 foreach ($response_label->material as $mat) {
75 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
76 $foundmat = $mat->getMaterial(
$m);
78 if (strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") == 0) {
79 $answerdepth = $foundmat[
"material"]->getContent();
81 if (strcmp($foundmat[
"type"],
"mattext") == 0
82 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0) {
83 $answertext .= $foundmat[
"material"]->getContent();
85 if (strcmp($foundmat[
"type"],
"matimage") == 0
86 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0) {
89 "imagetype" => $foundmat[
"material"]->getImageType(),
90 "label" => $foundmat[
"material"]->getLabel(),
91 "content" => $foundmat[
"material"]->getContent()
96 $answers[$answerorder] = array(
98 "answertext" => $answertext,
99 "answerimage" => $answerimage,
101 "answerorder" => $answerorder,
102 "answerdepth" => $answerdepth,
113 $responses = array();
114 $feedbacksgeneric = array();
115 foreach ($item->resprocessing as $resprocessing) {
116 foreach ($resprocessing->respcondition as $respcondition) {
119 $conditionvar = $respcondition->getConditionvar();
120 foreach ($conditionvar->order as $order) {
121 switch ($order[
"field"]) {
126 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
127 $orderindex = $conditionvar->varequal[$order[
"index"]]->getIndex();
131 foreach ($respcondition->setvar as $setvar) {
132 if (strcmp($ident,
"") != 0) {
133 $answers[$ident][
"solutionorder"] = $orderindex;
134 $answers[$ident][
"action"] = $setvar->getAction();
135 $answers[$ident][
"points"] = $setvar->getContent();
138 if (count($respcondition->displayfeedback)) {
139 foreach ($respcondition->displayfeedback as $feedbackpointer) {
140 if (strlen($feedbackpointer->getLinkrefid())) {
141 foreach ($item->itemfeedback as $ifb) {
142 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
144 if (count($ifb->material)) {
145 foreach ($ifb->material as $material) {
146 $feedbacksgeneric[1] = $material;
149 if ((count($ifb->flow_mat) > 0)) {
150 foreach ($ifb->flow_mat as $fmat) {
151 if (count($fmat->material)) {
152 foreach ($fmat->material as $material) {
153 $feedbacksgeneric[1] = $material;
158 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
160 if (count($ifb->material)) {
161 foreach ($ifb->material as $material) {
162 $feedbacksgeneric[0] = $material;
165 if ((count($ifb->flow_mat) > 0)) {
166 foreach ($ifb->flow_mat as $fmat) {
167 if (count($fmat->material)) {
168 foreach ($fmat->material as $material) {
169 $feedbacksgeneric[0] = $material;
185 $this->
object->setTitle($item->getTitle());
186 $this->
object->setNrOfTries($item->getMaxattempts());
187 $this->
object->setComment($item->getComment());
188 $this->
object->setAuthor($item->getAuthor());
189 $this->
object->setOwner(
$ilUser->getId());
190 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
191 $this->
object->setOrderingType(
$type);
192 $this->
object->setObjId($questionpool_id);
193 $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
194 $this->
object->setElementHeight($item->getMetadataEntry(
"element_height"));
195 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
196 $this->
object->setShuffle($shuffle);
198 $solanswers = array();
200 foreach ($answers as $answer) {
201 $solanswers[$answer[
"solutionorder"]] = $answer;
205 foreach ($solanswers as $answer) {
206 $points += $answer[
"points"];
210 if ($element->isExportIdent($answer[
'ident'])) {
211 $element->setExportIdent($answer[
'ident']);
213 $element->setPosition($position++);
214 if (isset($answer[
'answerdepth'])) {
215 $element->setIndentation($answer[
'answerdepth']);
219 if ($this->object->isImageOrderingType()) {
220 $element->setContent($answer[
"answerimage"][
"label"]);
222 $element->setContent($answer[
"answertext"]);
225 $this->
object->getOrderingElementList()->addElement($element);
227 $points = ($item->getMetadataEntry(
"points") > 0) ? $item->getMetadataEntry(
"points") : $points;
228 $this->
object->setPoints($points);
230 $this->
object->setAdditionalContentEditingMode(
233 $this->
object->saveToDb();
234 if (count($item->suggested_solutions)) {
235 foreach ($item->suggested_solutions as $suggested_solution) {
236 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
238 $this->
object->saveToDb();
240 foreach ($answers as $answer) {
242 include_once
"./Services/Utilities/classes/class.ilUtil.php";
243 if (strlen($answer[
'answerimage'][
'label']) && strlen($answer[
'answerimage'][
'content'])) {
244 $image = &base64_decode($answer[
"answerimage"][
"content"]);
245 $imagepath = $this->
object->getImagePath();
246 if (!file_exists($imagepath)) {
249 $imagepath .= $answer[
"answerimage"][
"label"];
250 $fh =
fopen($imagepath,
"wb");
257 $imagefile = fwrite($fh, $image);
261 $thumbpath = $imagepath .
"." .
"thumb.jpg";
266 foreach ($feedbacksgeneric as $correctness => $material) {
267 $m = $this->
object->QTIMaterialToString($material);
268 $feedbacksgeneric[$correctness] =
$m;
270 $questiontext = $this->
object->getQuestion();
273 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
274 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
275 include_once
"./Services/RTE/classes/class.ilRTE.php";
276 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
284 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
288 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
289 foreach ($this->object->getOrderingElementList() as $element) {
290 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
292 foreach ($feedbacksgeneric as $correctness => $material) {
293 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
295 foreach ($itemfeedbacks as $ident => $material) {
296 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
301 foreach ($this->object->getOrderingElementList() as $element) {
304 foreach ($feedbacksgeneric as $correctness => $material) {
305 $this->
object->feedbackOBJ->importGenericFeedback(
306 $this->object->getId(),
311 foreach ($itemfeedbacks as $ident => $material) {
314 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
315 $this->object->getId(),
321 $this->
object->saveToDb();
323 $this->
object->setObjId($tst_id);
324 $tstQid = $this->
object->getId();
325 $qplQid = $this->
object->duplicate(
true, null, null, null, $questionpool_id);
328 $tst_object->questions[$question_counter++] = $tstQid;
329 $import_mapping[$item->getIdent()] = array(
"pool" => $qplQid,
"test" => $tstQid);
331 $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)
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)
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')