ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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
 assQuestionImport (&$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
 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...
 
 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 245 of file class.assTextQuestionImport.php.

Referenced by fromXML().

246  {
247  $termScoringString = $item->getMetadataEntry('termscoring');
248 
249  if( !strlen($termScoringString) )
250  {
251  return array();
252  }
253 
254  $termScoring = unserialize($termScoringString);
255 
256  if( is_array($termScoring) )
257  {
258  return $termScoring;
259  }
260 
261  $termScoringString = base64_decode($termScoringString);
262  $termScoring = unserialize($termScoringString);
263 
264  if( is_array($termScoring) )
265  {
266  return $termScoring;
267  }
268 
269  return array();
270  }
+ 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, $GLOBALS, $ilUser, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), fetchTermScoring(), assQuestionImport\getQplImportArchivDirectory(), and assQuestionImport\getTstImportArchivDirectory().

31  {
32  global $ilUser;
33 
34  // empty session variable for imported xhtml mobs
35  unset($_SESSION["import_mob_xhtml"]);
36  $presentation = $item->getPresentation();
37  $duration = $item->getDuration();
38  $now = getdate();
39  $maxchars = 0;
40  $maxpoints = 0;
41  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
42  foreach ($presentation->order as $entry)
43  {
44  switch ($entry["type"])
45  {
46  case "response":
47  $response = $presentation->response[$entry["index"]];
48  $rendertype = $response->getRenderType();
49  switch (strtolower(get_class($rendertype)))
50  {
51  case "ilqtirenderfib":
52  $maxchars = $rendertype->getMaxchars();
53  break;
54  }
55  break;
56  }
57  }
58 
59  $feedbacksgeneric = array();
60  foreach ($item->resprocessing as $resprocessing)
61  {
62  $outcomes = $resprocessing->getOutcomes();
63  foreach ($outcomes->decvar as $decvar)
64  {
65  $maxpoints = $decvar->getMaxvalue();
66  }
67 
68  foreach ($resprocessing->respcondition as $respcondition)
69  {
70  foreach ($respcondition->displayfeedback as $feedbackpointer)
71  {
72  if (strlen($feedbackpointer->getLinkrefid()))
73  {
74  foreach ($item->itemfeedback as $ifb)
75  {
76  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
77  {
78  // found a feedback for the identifier
79  if (count($ifb->material))
80  {
81  foreach ($ifb->material as $material)
82  {
83  $feedbacksgeneric[1] = $material;
84  }
85  }
86  if ((count($ifb->flow_mat) > 0))
87  {
88  foreach ($ifb->flow_mat as $fmat)
89  {
90  if (count($fmat->material))
91  {
92  foreach ($fmat->material as $material)
93  {
94  $feedbacksgeneric[1] = $material;
95  }
96  }
97  }
98  }
99  }
100  else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
101  {
102  // found a feedback for the identifier
103  if (count($ifb->material))
104  {
105  foreach ($ifb->material as $material)
106  {
107  $feedbacksgeneric[0] = $material;
108  }
109  }
110  if ((count($ifb->flow_mat) > 0))
111  {
112  foreach ($ifb->flow_mat as $fmat)
113  {
114  if (count($fmat->material))
115  {
116  foreach ($fmat->material as $material)
117  {
118  $feedbacksgeneric[0] = $material;
119  }
120  }
121  }
122  }
123  }
124  }
125  }
126  }
127  }
128  }
129  $this->addGeneralMetadata($item);
130  $this->object->setTitle($item->getTitle());
131  $this->object->setNrOfTries($item->getMaxattempts());
132  $this->object->setComment($item->getComment());
133  $this->object->setAuthor($item->getAuthor());
134  $this->object->setOwner($ilUser->getId());
135  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
136  $this->object->setObjId($questionpool_id);
137  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
138  $this->object->setPoints($maxpoints);
139  $this->object->setMaxNumOfChars($maxchars);
140  $textrating = $item->getMetadataEntry("textrating");
141  if (strlen($textrating))
142  {
143  $this->object->setTextRating($textrating);
144  }
145  $this->object->matchcondition = (strlen($item->getMetadataEntry('matchcondition'))) ? $item->getMetadataEntry('matchcondition') : 0;
146 
147  require_once './Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php';
148  $no_keywords_found=true;
149 
150  $termscoring = $this->fetchTermScoring($item);
151  for ($i = 0; $i < count($termscoring); $i++ )
152  {
153  $this->object->addAnswer($termscoring[$i]->getAnswertext(), $termscoring[$i]->getPoints() );
154  $no_keywords_found=false;
155  }
156  if(count($termscoring))
157  {
158  $this->object->setKeywordRelation($item->getMetadataEntry('termrelation'));
159  }
160 
161  $keywords = $item->getMetadataEntry("keywords");
162  if (strlen($keywords))
163  {
164  #$this->object->setKeywords($keywords);
165  $answers = explode(' ', $keywords);
166  foreach ($answers as $answer)
167  {
168  $this->object->addAnswer($answer, 0);
169  }
170  $this->object->setKeywordRelation('one');
171  $no_keywords_found=false;
172  }
173  if($no_keywords_found)
174  {
175  $this->object->setKeywordRelation('non');
176  }
177 
178  // additional content editing mode information
179  $this->object->setAdditionalContentEditingMode(
181  );
182  $this->object->saveToDb();
183  if (count($item->suggested_solutions))
184  {
185  foreach ($item->suggested_solutions as $suggested_solution)
186  {
187  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
188  }
189  $this->object->saveToDb();
190  }
191  foreach ($feedbacksgeneric as $correctness => $material)
192  {
193  $m = $this->object->QTIMaterialToString($material);
194  $feedbacksgeneric[$correctness] = $m;
195  }
196  // handle the import of media objects in XHTML code
197  $questiontext = $this->object->getQuestion();
198  if (is_array($_SESSION["import_mob_xhtml"]))
199  {
200  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
201  include_once "./Services/RTE/classes/class.ilRTE.php";
202  foreach ($_SESSION["import_mob_xhtml"] as $mob)
203  {
204  if ($tst_id > 0)
205  {
206  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
207  }
208  else
209  {
210  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
211  }
212 
213  $GLOBALS['ilLog']->write(__METHOD__.': import mob from dir: '. $importfile);
214 
215  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
216  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
217  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
218  foreach ($feedbacksgeneric as $correctness => $material)
219  {
220  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
221  }
222  }
223  }
224  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
225  foreach ($feedbacksgeneric as $correctness => $material)
226  {
227  $this->object->feedbackOBJ->importGenericFeedback(
228  $this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)
229  );
230  }
231  $this->object->saveToDb();
232  if ($tst_id > 0)
233  {
234  $q_1_id = $this->object->getId();
235  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
236  $tst_object->questions[$question_counter++] = $question_id;
237  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
238  }
239  else
240  {
241  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
242  }
243  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
addGeneralMetadata(ilQTIItem $item)
& _saveTempFileAsMediaObject($name, $tmp_name, $upload=TRUE)
Create new media object and update page in db and return new media object.
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) ...
_saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
$GLOBALS['ct_recipient']
static _replaceMediaObjectImageSrc($a_text, $a_direction=0)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
global $ilUser
Definition: imgupload.php:15
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
+ Here is the call graph for this function:

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