ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
assOrderingQuestionImport Class Reference

Class for ordering question imports. More...

+ Inheritance diagram for assOrderingQuestionImport:
+ Collaboration diagram for assOrderingQuestionImport:

Public Member Functions

 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Creates a question from a QTI file. More...
 
- Public Member Functions inherited from assQuestionImport
 __construct ($a_object)
 assQuestionImport constructor More...
 
 getFeedbackGeneric ($item)
 
 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Creates a question from a QTI file. More...
 

Data Fields

 $object
 
- Data Fields inherited from assQuestionImport
 $object
 

Additional Inherited Members

- Protected Member Functions inherited from assQuestionImport
 fetchIndexFromFeedbackIdent ($feedbackIdent, $prefix='response_')
 
 getFeedbackAnswerSpecific (ilQTIItem $item, $prefix='response_')
 
 addGeneralMetadata (ilQTIItem $item)
 
 getQplImportArchivDirectory ()
 returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) More...
 
 getTstImportArchivDirectory ()
 returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) More...
 
 processNonAbstractedImageReferences ($text, $sourceNic)
 
 fetchAdditionalContentEditingModeInformation ($qtiItem)
 fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT when no or invalid information is given More...
 

Detailed Description

Class for ordering question imports.

assOrderingQuestionImport is a class for ordering question imports

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 15 of file class.assOrderingQuestionImport.php.

Member Function Documentation

◆ fromXML()

assOrderingQuestionImport::fromXML ( $item,
  $questionpool_id,
$tst_id,
$tst_object,
$question_counter,
$import_mapping 
)

Creates a question from a QTI file.

Receives parameters from a QTI parser and creates a valid ILIAS question object

Parameters
object$itemThe QTI item object
integer$questionpool_idThe id of the parent questionpool
integer$tst_idThe id of the parent test if the question is part of a test
object$tst_objectA reference to the parent test object
integer$question_counterA reference to a question counter to count the questions of an imported question pool
array$import_mappingAn array containing references to included ILIAS objects @access public

Reimplemented from assQuestionImport.

Definition at line 35 of file class.assOrderingQuestionImport.php.

36 {
37 global $ilUser;
38
39 // empty session variable for imported xhtml mobs
40 unset($_SESSION["import_mob_xhtml"]);
41 $presentation = $item->getPresentation();
42 $duration = $item->getDuration();
43 $shuffle = 0;
44 $now = getdate();
45 $foundimage = false;
46 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
47 $answers = array();
49
50 foreach ($presentation->order as $entry) {
51 switch ($entry["type"]) {
52 case "response":
53 $response = $presentation->response[$entry["index"]];
54 $type = $response->getIdent();
55 if ($response->getIdent() == 'OQP') {
57 } elseif ($response->getIdent() == 'OQNP') {
59 } elseif ($response->getIdent() == 'OQNT') {
61 } elseif ($response->getIdent() == 'OQT') {
63 }
64
65 $rendertype = $response->getRenderType();
66 switch (strtolower(get_class($rendertype))) {
67 case "ilqtirenderchoice":
68 $shuffle = $rendertype->getShuffle();
69 $answerorder = 0;
70 foreach ($rendertype->response_labels as $response_label) {
71 $ident = $response_label->getIdent();
72 $answertext = "";
73 foreach ($response_label->material as $mat) {
74 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
75 $foundmat = $mat->getMaterial($m);
76
77 if (strcmp($foundmat["material"]->getLabel(), "answerdepth") == 0) {
78 $answerdepth = $foundmat["material"]->getContent();
79 }
80 if (strcmp($foundmat["type"], "mattext") == 0
81 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
82 $answertext .= $foundmat["material"]->getContent();
83 }
84 if (strcmp($foundmat["type"], "matimage") == 0
85 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
86 $foundimage = true;
87 $answerimage = array(
88 "imagetype" => $foundmat["material"]->getImageType(),
89 "label" => $foundmat["material"]->getLabel(),
90 "content" => $foundmat["material"]->getContent()
91 );
92 }
93 }
94 }
95 $answers[$answerorder] = array(
96 'ident' => $ident,
97 "answertext" => $answertext,
98 "answerimage" => $answerimage,
99 "points" => 0,
100 "answerorder" => $answerorder,
101 "answerdepth" => $answerdepth,
102 "correctness" => "",
103 "action" => ""
104 );
105 $answerorder++;
106 }
107 break;
108 }
109 break;
110 }
111 }
112 $responses = array();
113 $feedbacksgeneric = array();
114 foreach ($item->resprocessing as $resprocessing) {
115 foreach ($resprocessing->respcondition as $respcondition) {
116 $ident = "";
117 $correctness = 1;
118 $conditionvar = $respcondition->getConditionvar();
119 foreach ($conditionvar->order as $order) {
120 switch ($order["field"]) {
121 case "arr_not":
122 $correctness = 0;
123 break;
124 case "varequal":
125 $ident = $conditionvar->varequal[$order["index"]]->getContent();
126 $orderindex = $conditionvar->varequal[$order["index"]]->getIndex();
127 break;
128 }
129 }
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();
135 }
136 }
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) {
142 // found a feedback for the identifier
143 if (count($ifb->material)) {
144 foreach ($ifb->material as $material) {
145 $feedbacksgeneric[1] = $material;
146 }
147 }
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;
153 }
154 }
155 }
156 }
157 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
158 // found a feedback for the identifier
159 if (count($ifb->material)) {
160 foreach ($ifb->material as $material) {
161 $feedbacksgeneric[0] = $material;
162 }
163 }
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;
169 }
170 }
171 }
172 }
173 }
174 }
175 }
176 }
177 }
178 }
179 }
180
181 $itemfeedbacks = $this->getFeedbackAnswerSpecific($item, 'link_');
182
183 $this->addGeneralMetadata($item);
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);
196 $points = 0;
197 $solanswers = array();
198
199 foreach ($answers as $answer) {
200 $solanswers[$answer["solutionorder"]] = $answer;
201 }
202 ksort($solanswers);
203 $position = 0;
204 foreach ($solanswers as $answer) {
205 $points += $answer["points"];
206
207 $element = new ilAssOrderingElement();
208
209 if ($element->isExportIdent($answer['ident'])) {
210 $element->setExportIdent($answer['ident']);
211 } else {
212 $element->setPosition($position++);
213 if (isset($answer['answerdepth'])) {
214 $element->setIndentation($answer['answerdepth']);
215 }
216 }
217
218 if ($this->object->isImageOrderingType()) {
219 $element->setContent($answer["answerimage"]["label"]);
220 } else {
221 $element->setContent($answer["answertext"]);
222 }
223
224 $this->object->getOrderingElementList()->addElement($element);
225 }
226 $points = ($item->getMetadataEntry("points") > 0) ? $item->getMetadataEntry("points") : $points;
227 $this->object->setPoints($points);
228 // additional content editing mode information
229 $this->object->setAdditionalContentEditingMode(
231 );
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);
236 }
237 $this->object->saveToDb();
238 }
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)) {
246 ilUtil::makeDirParents($imagepath);
247 }
248 $imagepath .= $answer["answerimage"]["label"];
249 $fh = fopen($imagepath, "wb");
250 if ($fh == false) {
251 // global $ilErr;
252// $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
253// return;
254 } else {
255 $imagefile = fwrite($fh, $image);
256 fclose($fh);
257 }
258 // create thumbnail file
259 $thumbpath = $imagepath . "." . "thumb.jpg";
260 ilUtil::convertImage($imagepath, $thumbpath, "JPEG", $this->object->getThumbGeometry());
261 }
262 }
263 }
264 foreach ($feedbacksgeneric as $correctness => $material) {
265 $m = $this->object->QTIMaterialToString($material);
266 $feedbacksgeneric[$correctness] = $m;
267 }
268 $questiontext = $this->object->getQuestion();
269
270 // handle the import of media objects in XHTML code
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) {
275 if ($tst_id > 0) {
276 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
277 } else {
278 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
279 }
280
281 $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
282
283 $media_object =&ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
284 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
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()));
288 }
289 foreach ($feedbacksgeneric as $correctness => $material) {
290 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
291 }
292 foreach ($itemfeedbacks as $ident => $material) {
293 $itemfeedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
294 }
295 }
296 }
297 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
298 foreach ($this->object->getOrderingElementList() as $element) {
299 $element->setContent(ilRTE::_replaceMediaObjectImageSrc($element->getContent(), 1));
300 }
301 foreach ($feedbacksgeneric as $correctness => $material) {
302 $this->object->feedbackOBJ->importGenericFeedback(
303 $this->object->getId(),
304 $correctness,
306 );
307 }
308 foreach ($itemfeedbacks as $ident => $material) {
309 $index = $this->fetchIndexFromFeedbackIdent($ident, 'link_');
310
311 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
312 $this->object->getId(),
313 $index,
315 );
316 }
317 $this->object->saveToDb();
318 if ($tst_id > 0) {
319 $this->object->setObjId($tst_id);
320 $tstQid = $this->object->getId();
321 $qplQid = $this->object->duplicate(true, null, null, null, $questionpool_id);
323 assQuestion::saveOriginalId($tstQid, $qplQid);
324 $tst_object->questions[$question_counter++] = $tstQid;
325 $import_mapping[$item->getIdent()] = array("pool" => $qplQid, "test" => $tstQid);
326 } else {
327 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
328 }
329 }
sprintf('%.4f', $callTime)
$_SESSION["AccountId"]
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 resetOriginalId($questionId)
static saveOriginalId($questionId, $originalId)
static _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...
static convertImage( $a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const OQ_NESTED_PICTURES
const OQ_TERMS
const OQ_NESTED_TERMS
const OQ_PICTURES
Ordering question constants.
$index
Definition: metadata.php:60
$type
$response
$ilUser
Definition: imgupload.php:18

References $_SESSION, $fh, $GLOBALS, $ilUser, $index, $m, $response, $type, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), ilUtil\convertImage(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), assQuestionImport\fetchIndexFromFeedbackIdent(), assQuestionImport\getFeedbackAnswerSpecific(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), ilUtil\makeDirParents(), OQ_NESTED_PICTURES, OQ_NESTED_TERMS, OQ_PICTURES, OQ_TERMS, assQuestion\resetOriginalId(), assQuestion\saveOriginalId(), and sprintf.

+ Here is the call graph for this function:

Field Documentation

◆ $object

assOrderingQuestionImport::$object

Definition at line 20 of file class.assOrderingQuestionImport.php.


The documentation for this class was generated from the following file: