ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
assTextSubsetImport Class Reference

Class for text subset question imports. More...

+ Inheritance diagram for assTextSubsetImport:
+ Collaboration diagram for assTextSubsetImport:

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...
 

Additional Inherited Members

- Data Fields inherited from assQuestionImport
 $object
 
- 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 text subset question imports.

assTextSubsetImport is a class for text subset 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.assTextSubsetImport.php.

Member Function Documentation

◆ fromXML()

assTextSubsetImport::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 public

Definition at line 30 of file class.assTextSubsetImport.php.

References $_SESSION, $DIC, $ilUser, $m, $response, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), ACTION_ADD, assQuestionImport\addGeneralMetadata(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), and RT_RESPONSE_STR.

31  {
32  global $DIC;
33  $ilUser = $DIC['ilUser'];
34 
35  // empty session variable for imported xhtml mobs
36  unset($_SESSION["import_mob_xhtml"]);
37  $presentation = $item->getPresentation();
38  $duration = $item->getDuration();
39  $shuffle = 0;
40  $idents = array();
41  $now = getdate();
42  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
43  $gaps = array();
44  foreach ($presentation->order as $entry) {
45  switch ($entry["type"]) {
46  case "response":
47  $response = $presentation->response[$entry["index"]];
48  if ($response->getResponseType() == RT_RESPONSE_STR) {
49  array_push($idents, $response->getIdent());
50  }
51  break;
52  }
53  }
54  $responses = array();
55  $feedbacksgeneric = array();
56  foreach ($item->resprocessing as $resprocessing) {
57  foreach ($resprocessing->respcondition as $respcondition) {
58  $ident = "";
59  $correctness = 1;
60  $conditionvar = $respcondition->getConditionvar();
61  foreach ($conditionvar->order as $order) {
62  switch ($order["field"]) {
63  case "varsubset":
64  $respident = $conditionvar->varsubset[$order["index"]]->getRespident();
65  $content = $conditionvar->varsubset[$order["index"]]->getContent();
66  if (!is_array($responses[$respident])) {
67  $responses[$respident] = array();
68  }
69  $vars = explode(",", $content);
70  foreach ($vars as $var) {
71  array_push($responses[$respident], array("solution" => $var, "points" => ""));
72  }
73  break;
74  }
75  }
76  foreach ($respcondition->setvar as $setvar) {
77  if ((strcmp($setvar->getVarname(), "matches") == 0) && ($setvar->getAction() == ACTION_ADD)) {
78  foreach ($responses[$respident] as $idx => $solutionarray) {
79  if (strlen($solutionarray["points"] == 0)) {
80  $responses[$respident][$idx]["points"] = $setvar->getContent();
81  }
82  }
83  }
84  }
85  foreach ($resprocessing->respcondition as $respcondition) {
86  foreach ($respcondition->displayfeedback as $feedbackpointer) {
87  if (strlen($feedbackpointer->getLinkrefid())) {
88  foreach ($item->itemfeedback as $ifb) {
89  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
90  // found a feedback for the identifier
91  if (count($ifb->material)) {
92  foreach ($ifb->material as $material) {
93  $feedbacksgeneric[1] = $material;
94  }
95  }
96  if ((count($ifb->flow_mat) > 0)) {
97  foreach ($ifb->flow_mat as $fmat) {
98  if (count($fmat->material)) {
99  foreach ($fmat->material as $material) {
100  $feedbacksgeneric[1] = $material;
101  }
102  }
103  }
104  }
105  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
106  // found a feedback for the identifier
107  if (count($ifb->material)) {
108  foreach ($ifb->material as $material) {
109  $feedbacksgeneric[0] = $material;
110  }
111  }
112  if ((count($ifb->flow_mat) > 0)) {
113  foreach ($ifb->flow_mat as $fmat) {
114  if (count($fmat->material)) {
115  foreach ($fmat->material as $material) {
116  $feedbacksgeneric[0] = $material;
117  }
118  }
119  }
120  }
121  }
122  }
123  }
124  }
125  }
126  }
127  }
128  $this->addGeneralMetadata($item);
129  $this->object->setTitle($item->getTitle());
130  $this->object->setNrOfTries($item->getMaxattempts());
131  $this->object->setComment($item->getComment());
132  $this->object->setAuthor($item->getAuthor());
133  $this->object->setOwner($ilUser->getId());
134  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
135  $this->object->setObjId($questionpool_id);
136  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
137  $textrating = $item->getMetadataEntry("textrating");
138  if (strlen($textrating) == 0) {
139  $textrating = "ci";
140  }
141  $this->object->setTextRating($textrating);
142  $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers"));
143  $response = current($responses);
144  $counter = 0;
145  if (is_array($response)) {
146  foreach ($response as $answer) {
147  $this->object->addAnswer($answer["solution"], $answer["points"], $counter);
148  $counter++;
149  }
150  }
151  // additional content editing mode information
152  $this->object->setAdditionalContentEditingMode(
154  );
155  $this->object->saveToDb();
156  if (count($item->suggested_solutions)) {
157  foreach ($item->suggested_solutions as $suggested_solution) {
158  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
159  }
160  $this->object->saveToDb();
161  }
162  foreach ($feedbacksgeneric as $correctness => $material) {
163  $m = $this->object->QTIMaterialToString($material);
164  $feedbacksgeneric[$correctness] = $m;
165  }
166  // handle the import of media objects in XHTML code
167  $questiontext = $this->object->getQuestion();
168  if (is_array($_SESSION["import_mob_xhtml"])) {
169  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
170  include_once "./Services/RTE/classes/class.ilRTE.php";
171  foreach ($_SESSION["import_mob_xhtml"] as $mob) {
172  if ($tst_id > 0) {
173  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
174  } else {
175  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
176  }
177 
178  global $DIC; /* @var ILIAS\DI\Container $DIC */
179  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
180 
181  $media_object = &ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
182  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
183  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
184  foreach ($feedbacksgeneric as $correctness => $material) {
185  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
186  }
187  }
188  }
189  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
190  foreach ($feedbacksgeneric as $correctness => $material) {
191  $this->object->feedbackOBJ->importGenericFeedback(
192  $this->object->getId(),
193  $correctness,
195  );
196  }
197  $this->object->saveToDb();
198  if ($tst_id > 0) {
199  $q_1_id = $this->object->getId();
200  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
201  $tst_object->questions[$question_counter++] = $question_id;
202  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
203  } else {
204  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
205  }
206  }
addGeneralMetadata(ilQTIItem $item)
$_SESSION["AccountId"]
global $DIC
Definition: saml.php:7
const RT_RESPONSE_STR
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 _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...
const ACTION_ADD
$ilUser
Definition: imgupload.php:18
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
$response
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.
+ Here is the call graph for this function:

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