ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.assFormulaQuestionImport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
5 
16 {
30  function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
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  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
40 
41  $feedbacksgeneric = array();
42 
43  $this->object->setTitle($item->getTitle());
44  $this->object->setComment($item->getComment());
45  $this->object->setAuthor($item->getAuthor());
46  $this->object->setOwner($ilUser->getId());
47  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
48  $this->object->setObjId($questionpool_id);
49  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
50  if (preg_match_all("/(\\\$v\\d+)/ims", $this->object->getQuestion(), $matches))
51  {
52  foreach ($matches[1] as $variable)
53  {
54  $data = unserialize($item->getMetadataEntry($variable));
55  $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]);
56  require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php';
57  $varObj = new assFormulaQuestionVariable($variable, $data["rangemin"], $data["rangemax"], $unit, $data["precision"], $data["intprecision"]);
58  $this->object->addVariable($varObj);
59  }
60  }
61  if (preg_match_all("/(\\\$r\\d+)/ims", $this->object->getQuestion(), $rmatches))
62  {
63  foreach ($rmatches[1] as $result)
64  {
65  $data = unserialize($item->getMetadataEntry($result));
66  $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]);
67  require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionResult.php';
68  if (!is_array($data["rating"]))
69  {
70  $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], TRUE);
71  }
72  else
73  {
74  $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], FALSE, $data["rating"]["sign"], $data["rating"]["value"], $data["rating"]["unit"]);
75  }
76  $this->object->addResult($resObj);
77  if (is_array($data["resultunits"]))
78  {
79  foreach ($data["resultunits"] as $resu)
80  {
81  $ru = $this->object->getUnitRepository()->getUnit($resu["unitvalue"]);
82  if (is_object($ru))
83  {
84  $this->object->addResultUnit($resObj, $ru);
85  }
86  }
87  }
88  }
89  }
90  $this->object->setPoints($item->getMetadataEntry("points"));
91  $this->addGeneralMetadata($item);
92  // additional content editing mode information
93  $this->object->setAdditionalContentEditingMode(
95  );
96  $this->object->saveToDb();
97  // handle the import of media objects in XHTML code
98  $questiontext = $this->object->getQuestion();
99  $feedbacksgeneric = $this->getFeedbackGeneric($item);
100 
101  if (is_array($_SESSION["import_mob_xhtml"]))
102  {
103  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
104  include_once "./Services/RTE/classes/class.ilRTE.php";
105  foreach ($_SESSION["import_mob_xhtml"] as $mob)
106  {
107  if ($tst_id > 0)
108  {
109  include_once "./Modules/Test/classes/class.ilObjTest.php";
110  $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"];
111  }
112  else
113  {
114  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
115  $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
116  }
117  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
118  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
119  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
120 
121  foreach ($feedbacksgeneric as $correctness => $material)
122  {
123  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
124  }
125  }
126  }
127  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
128 
129  foreach ($feedbacksgeneric as $correctness => $material)
130  {
131  $this->object->feedbackOBJ->importGenericFeedback(
132  $this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)
133  );
134  }
135 
136  // additional content editing mode information
137  $this->object->setAdditionalContentEditingMode(
139  );
140 
141  $this->object->saveToDb();
142  if (count($item->suggested_solutions))
143  {
144  foreach ($item->suggested_solutions as $suggested_solution)
145  {
146  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
147  }
148  $this->object->saveToDb();
149  }
150  if ($tst_id > 0)
151  {
152  $q_1_id = $this->object->getId();
153  $question_id = $this->object->duplicate(true);
154  $tst_object->questions[$question_counter++] = $question_id;
155  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
156  }
157  else
158  {
159  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
160  }
161  }
162 }
163 
164 ?>
addGeneralMetadata(ilQTIItem $item)
$_SESSION["AccountId"]
$result
Class for formula question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
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...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=TRUE)
Create new media object and update page in db and return new media object.
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
static _getImportDirectory()
get import directory of lm
Class for question imports.
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 _getImportDirectory()
Get the import directory location of the test.