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

Class for essay question imports. More...

+ Inheritance diagram for assTextQuestionImport:
+ Collaboration diagram for assTextQuestionImport:

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

Protected Member Functions

 fetchTermScoring ($item)
 
- 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...
 

Additional Inherited Members

- Data Fields inherited from assQuestionImport
 $object
 

Detailed Description

Class for essay question imports.

assTextQuestionImport is a class for essay 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.assTextQuestionImport.php.

Member Function Documentation

◆ fetchTermScoring()

assTextQuestionImport::fetchTermScoring (   $item)
protected

Definition at line 222 of file class.assTextQuestionImport.php.

Referenced by fromXML().

223  {
224  $termScoringString = $item->getMetadataEntry('termscoring');
225 
226  if (!strlen($termScoringString)) {
227  return array();
228  }
229 
230  $termScoring = unserialize($termScoringString);
231 
232  if (is_array($termScoring)) {
233  return $termScoring;
234  }
235 
236  $termScoringString = base64_decode($termScoringString);
237  $termScoring = unserialize($termScoringString);
238 
239  if (is_array($termScoring)) {
240  return $termScoring;
241  }
242 
243  return array();
244  }
+ Here is the caller graph for this function:

◆ fromXML()

assTextQuestionImport::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.assTextQuestionImport.php.

References $_SESSION, $DIC, $i, $ilUser, $index, $m, $response, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), assQuestionImport\fetchIndexFromFeedbackIdent(), fetchTermScoring(), assQuestionImport\getFeedbackAnswerSpecific(), assQuestionImport\getQplImportArchivDirectory(), and assQuestionImport\getTstImportArchivDirectory().

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  $now = getdate();
40  $maxchars = 0;
41  $maxpoints = 0;
42  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
43  foreach ($presentation->order as $entry) {
44  switch ($entry["type"]) {
45  case "response":
46  $response = $presentation->response[$entry["index"]];
47  $rendertype = $response->getRenderType();
48  switch (strtolower(get_class($rendertype))) {
49  case "ilqtirenderfib":
50  $maxchars = $rendertype->getMaxchars();
51  break;
52  }
53  break;
54  }
55  }
56 
57  $feedbacksgeneric = array();
58  foreach ($item->resprocessing as $resprocessing) {
59  $outcomes = $resprocessing->getOutcomes();
60  foreach ($outcomes->decvar as $decvar) {
61  $maxpoints = $decvar->getMaxvalue();
62  }
63 
64  foreach ($resprocessing->respcondition as $respcondition) {
65  foreach ($respcondition->displayfeedback as $feedbackpointer) {
66  if (strlen($feedbackpointer->getLinkrefid())) {
67  foreach ($item->itemfeedback as $ifb) {
68  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
69  // found a feedback for the identifier
70  if (count($ifb->material)) {
71  foreach ($ifb->material as $material) {
72  $feedbacksgeneric[1] = $material;
73  }
74  }
75  if ((count($ifb->flow_mat) > 0)) {
76  foreach ($ifb->flow_mat as $fmat) {
77  if (count($fmat->material)) {
78  foreach ($fmat->material as $material) {
79  $feedbacksgeneric[1] = $material;
80  }
81  }
82  }
83  }
84  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
85  // found a feedback for the identifier
86  if (count($ifb->material)) {
87  foreach ($ifb->material as $material) {
88  $feedbacksgeneric[0] = $material;
89  }
90  }
91  if ((count($ifb->flow_mat) > 0)) {
92  foreach ($ifb->flow_mat as $fmat) {
93  if (count($fmat->material)) {
94  foreach ($fmat->material as $material) {
95  $feedbacksgeneric[0] = $material;
96  }
97  }
98  }
99  }
100  }
101  }
102  }
103  }
104  }
105  }
106  $this->addGeneralMetadata($item);
107  $this->object->setTitle($item->getTitle());
108  $this->object->setNrOfTries($item->getMaxattempts());
109  $this->object->setComment($item->getComment());
110  $this->object->setAuthor($item->getAuthor());
111  $this->object->setOwner($ilUser->getId());
112  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
113  $this->object->setObjId($questionpool_id);
114  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
115  $this->object->setPoints($maxpoints);
116  $this->object->setMaxNumOfChars($maxchars);
117  $textrating = $item->getMetadataEntry("textrating");
118  if (strlen($textrating)) {
119  $this->object->setTextRating($textrating);
120  }
121  $this->object->matchcondition = (strlen($item->getMetadataEntry('matchcondition'))) ? $item->getMetadataEntry('matchcondition') : 0;
122 
123  require_once './Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php';
124  $no_keywords_found = true;
125 
126  $termscoring = $this->fetchTermScoring($item);
127  for ($i = 0; $i < count($termscoring); $i++) {
128  $this->object->addAnswer($termscoring[$i]->getAnswertext(), $termscoring[$i]->getPoints());
129  $no_keywords_found = false;
130  }
131  if (count($termscoring)) {
132  $this->object->setKeywordRelation($item->getMetadataEntry('termrelation'));
133  }
134 
135  $keywords = $item->getMetadataEntry("keywords");
136  if (strlen($keywords)) {
137  #$this->object->setKeywords($keywords);
138  $answers = explode(' ', $keywords);
139  foreach ($answers as $answer) {
140  $this->object->addAnswer($answer, 0);
141  }
142  $this->object->setKeywordRelation('one');
143  $no_keywords_found = false;
144  }
145  if ($no_keywords_found) {
146  $this->object->setKeywordRelation('non');
147  }
148 
149  // additional content editing mode information
150  $this->object->setAdditionalContentEditingMode(
152  );
153  $this->object->saveToDb();
154  if (count($item->suggested_solutions)) {
155  foreach ($item->suggested_solutions as $suggested_solution) {
156  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
157  }
158  $this->object->saveToDb();
159  }
160  foreach ($feedbacksgeneric as $correctness => $material) {
161  $m = $this->object->QTIMaterialToString($material);
162  $feedbacksgeneric[$correctness] = $m;
163  }
164  // handle the import of media objects in XHTML code
165  $questiontext = $this->object->getQuestion();
166 
167  $feedbacks = $this->getFeedbackAnswerSpecific($item);
168 
169  if (is_array($_SESSION["import_mob_xhtml"])) {
170  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
171  include_once "./Services/RTE/classes/class.ilRTE.php";
172  foreach ($_SESSION["import_mob_xhtml"] as $mob) {
173  if ($tst_id > 0) {
174  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
175  } else {
176  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
177  }
178 
179  global $DIC; /* @var ILIAS\DI\Container $DIC */
180  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
181 
182  $media_object = &ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
183  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
184  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
185  foreach ($feedbacks as $ident => $material) {
186  $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
187  }
188  foreach ($feedbacksgeneric as $correctness => $material) {
189  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
190  }
191  }
192  }
193  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
194  foreach ($feedbacks as $ident => $material) {
195  $index = $this->fetchIndexFromFeedbackIdent($ident);
196 
197  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
198  $this->object->getId(),
199  0,
200  $index,
202  );
203  }
204  foreach ($feedbacksgeneric as $correctness => $material) {
205  $this->object->feedbackOBJ->importGenericFeedback(
206  $this->object->getId(),
207  $correctness,
209  );
210  }
211  $this->object->saveToDb();
212  if ($tst_id > 0) {
213  $q_1_id = $this->object->getId();
214  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
215  $tst_object->questions[$question_counter++] = $question_id;
216  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
217  } else {
218  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
219  }
220  }
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
addGeneralMetadata(ilQTIItem $item)
$_SESSION["AccountId"]
global $DIC
Definition: saml.php:7
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) ...
$index
Definition: metadata.php:60
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...
$ilUser
Definition: imgupload.php:18
$i
Definition: disco.tpl.php:19
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.
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
+ Here is the call graph for this function:

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