Creates a question from a QTI file.
54 $presentation = $item->getPresentation();
55 $duration = $item->getDuration();
58 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
59 $definitions = array();
62 foreach ($presentation->order as $entry) {
63 switch ($entry[
"type"]) {
65 $response = $presentation->response[$entry[
"index"]];
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 $answerimage = array();
75 foreach ($response_label->material as $mat) {
76 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
77 $foundmat = $mat->getMaterial(
$m);
78 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
79 $answertext .= $foundmat[
"material"]->getContent();
81 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
84 "imagetype" => $foundmat[
"material"]->getImageType(),
85 "label" => $foundmat[
"material"]->getLabel(),
86 "content" => $foundmat[
"material"]->getContent()
91 if (($response_label->getMatchMax() == 1) && (strlen($response_label->getMatchGroup()))) {
92 $definitions[$ident] = array(
93 "answertext" => $answertext,
94 "answerimage" => $answerimage,
96 "answerorder" => $ident,
100 $terms[$ident] = array(
101 "term" => $answertext,
102 "answerimage" => $answerimage,
114 $responses = array();
115 $feedbacksgeneric = array();
116 foreach ($item->resprocessing as $resprocessing) {
117 foreach ($resprocessing->respcondition as $respcondition) {
120 $conditionvar = $respcondition->getConditionvar();
121 foreach ($conditionvar->order as $order) {
122 switch ($order[
"field"]) {
124 $subset = explode(
",", $conditionvar->varsubset[$order[
"index"]]->getContent());
128 foreach ($respcondition->setvar as $setvar) {
129 array_push($responses, array(
"subset" => $subset,
"action" => $setvar->getAction(),
"points" => $setvar->getContent()));
132 if (count($respcondition->displayfeedback)) {
133 foreach ($respcondition->displayfeedback as $feedbackpointer) {
134 if (strlen($feedbackpointer->getLinkrefid())) {
135 foreach ($item->itemfeedback as $ifb) {
136 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
138 if (count($ifb->material)) {
139 foreach ($ifb->material as $material) {
140 $feedbacksgeneric[1] = $material;
143 if ((count($ifb->flow_mat) > 0)) {
144 foreach ($ifb->flow_mat as $fmat) {
145 if (count($fmat->material)) {
146 foreach ($fmat->material as $material) {
147 $feedbacksgeneric[1] = $material;
152 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
154 if (count($ifb->material)) {
155 foreach ($ifb->material as $material) {
156 $feedbacksgeneric[0] = $material;
159 if ((count($ifb->flow_mat) > 0)) {
160 foreach ($ifb->flow_mat as $fmat) {
161 if (count($fmat->material)) {
162 foreach ($fmat->material as $material) {
163 $feedbacksgeneric[0] = $material;
176 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
177 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
178 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
179 $this->
object->createNewQuestion();
181 $this->
object->setTitle($item->getTitle());
182 $this->
object->setNrOfTries($item->getMaxattempts());
183 $this->
object->setComment($item->getComment());
184 $this->
object->setAuthor($item->getAuthor());
185 $this->
object->setOwner(
$ilUser->getId());
186 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
187 $this->
object->setObjId($questionpool_id);
188 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
189 $extended_shuffle = $item->getMetadataEntry(
"shuffle");
190 $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
192 if (strlen($item->getMetadataEntry(
'matching_mode'))) {
193 $this->
object->setMatchingMode($item->getMetadataEntry(
'matching_mode'));
199 foreach ($terms as $term) {
200 if (count($term[
'answerimage'])) {
201 $this->
saveImage($term[
'answerimage'][
'content'], $term[
'answerimage'][
'label']);
204 foreach ($definitions as $definition) {
205 if (count($definition[
'answerimage'])) {
206 $this->
saveImage($definition[
'answerimage'][
'content'], $definition[
'answerimage'][
'label']);
210 foreach ($terms as $termindex => $term) {
211 $this->
object->addTerm(
new assAnswerMatchingTerm($term[
"term"], $term[
'answerimage'][
'label'], $term[
"ident"]));
213 foreach ($definitions as $definitionindex => $definition) {
214 $this->
object->addDefinition(
new assAnswerMatchingDefinition($definition[
"answertext"], $definition[
'answerimage'][
'label'], $definition[
"answerorder"]));
217 if (strlen($extended_shuffle) > 0) {
218 $shuffle = $extended_shuffle;
220 $this->
object->setShuffle($shuffle);
223 $subset = $response[
"subset"];
224 foreach ($subset as $ident) {
225 if (array_key_exists($ident, $definitions)) {
226 $definition = $definitions[$ident];
228 if (array_key_exists($ident, $terms)) {
229 $term = $terms[$ident];
235 $this->
object->setAdditionalContentEditingMode(
238 $this->
object->saveToDb();
239 if (count($item->suggested_solutions)) {
240 foreach ($item->suggested_solutions as $suggested_solution) {
241 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
243 $this->
object->saveToDb();
245 foreach ($responses as $response) {
246 $subset = $response[
"subset"];
247 foreach ($subset as $ident) {
248 if (array_key_exists($ident, $definitions)) {
249 $definition = $definitions[$ident];
251 if (array_key_exists($ident, $terms)) {
252 $term = $terms[$ident];
257 foreach ($feedbacksgeneric as $correctness => $material) {
258 $m = $this->
object->QTIMaterialToString($material);
259 $feedbacksgeneric[$correctness] =
$m;
265 $questiontext = $this->
object->getQuestion();
266 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
267 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
268 include_once
"./Services/RTE/classes/class.ilRTE.php";
269 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
277 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
281 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
282 foreach ($feedbacks as $ident => $material) {
283 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
285 foreach ($feedbacksgeneric as $correctness => $material) {
286 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
291 foreach ($feedbacks as $ident => $material) {
294 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
295 $this->object->getId(),
301 foreach ($feedbacksgeneric as $correctness => $material) {
302 $this->
object->feedbackOBJ->importGenericFeedback(
303 $this->object->getId(),
308 $this->
object->saveToDb();
310 $q_1_id = $this->
object->getId();
311 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
312 $tst_object->questions[$question_counter++] = $question_id;
313 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
315 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
Class for matching question terms.
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
addGeneralMetadata(ilQTIItem $item)
const MATCHING_MODE_1_ON_1
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...
saveImage($data, $filename)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
Class for matching question definitions.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...