ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.assQuestionImport.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/Test/classes/inc.AssessmentConstants.php";
5 
16 {
20  public $object;
21 
28  public function __construct($a_object)
29  {
30  $this->object = $a_object;
31  }
32 
33  public function getQuestionId() : int
34  {
35  return (int) $this->object->getId();
36  }
37 
38  public function getFeedbackGeneric($item)
39  {
40  $feedbacksgeneric = array();
41  foreach ($item->resprocessing as $resprocessing) {
42  foreach ($resprocessing->respcondition as $respcondition) {
43  foreach ($respcondition->displayfeedback as $feedbackpointer) {
44  if (strlen($feedbackpointer->getLinkrefid())) {
45  foreach ($item->itemfeedback as $ifb) {
46  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
47  // found a feedback for the identifier
48  if (count($ifb->material)) {
49  foreach ($ifb->material as $material) {
50  $feedbacksgeneric[1] = $material;
51  }
52  }
53  if ((count($ifb->flow_mat) > 0)) {
54  foreach ($ifb->flow_mat as $fmat) {
55  if (count($fmat->material)) {
56  foreach ($fmat->material as $material) {
57  $feedbacksgeneric[1] = $material;
58  }
59  }
60  }
61  }
62  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
63  // found a feedback for the identifier
64  if (count($ifb->material)) {
65  foreach ($ifb->material as $material) {
66  $feedbacksgeneric[0] = $material;
67  }
68  }
69  if ((count($ifb->flow_mat) > 0)) {
70  foreach ($ifb->flow_mat as $fmat) {
71  if (count($fmat->material)) {
72  foreach ($fmat->material as $material) {
73  $feedbacksgeneric[0] = $material;
74  }
75  }
76  }
77  }
78  }
79  }
80  }
81  }
82  }
83  }
84  // handle the import of media objects in XHTML code
85  foreach ($feedbacksgeneric as $correctness => $material) {
86  $m = $this->object->QTIMaterialToString($material);
87  $feedbacksgeneric[$correctness] = $m;
88  }
89  return $feedbacksgeneric;
90  }
91 
97  protected function fetchIndexFromFeedbackIdent($feedbackIdent, $prefix = 'response_')
98  {
99  return (int) str_replace($prefix, '', $feedbackIdent);
100  }
101 
107  protected function getFeedbackAnswerSpecific(ilQTIItem $item, $prefix = 'response_')
108  {
109  $feedbacks = array();
110 
111  foreach ($item->itemfeedback as $ifb) {
112  if ($ifb->getIdent() == 'response_allcorrect' || $ifb->getIdent() == 'response_onenotcorrect') {
113  continue;
114  }
115 
116  if ($ifb->getIdent() == $prefix . 'allcorrect' || $ifb->getIdent() == $prefix . 'onenotcorrect') {
117  continue;
118  }
119 
120  if (substr($ifb->getIdent(), 0, strlen($prefix)) != $prefix) {
121  continue;
122  }
123 
124  $ident = $ifb->getIdent();
125 
126  // found a feedback for the identifier
127 
128  if (count($ifb->material)) {
129  foreach ($ifb->material as $material) {
130  $feedbacks[$ident] = $material;
131  }
132  }
133 
134  if ((count($ifb->flow_mat) > 0)) {
135  foreach ($ifb->flow_mat as $fmat) {
136  if (count($fmat->material)) {
137  foreach ($fmat->material as $material) {
138  $feedbacks[$ident] = $material;
139  }
140  }
141  }
142  }
143  }
144 
145  foreach ($feedbacks as $ident => $material) {
146  $m = $this->object->QTIMaterialToString($material);
147  $feedbacks[$ident] = $m;
148  }
149 
150  return $feedbacks;
151  }
152 
166  public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
167  {
168  }
169 
173  protected function addGeneralMetadata(ilQTIItem $item)
174  {
175  if ($item->getMetadataEntry('externalID')) {
176  $this->object->setExternalId($item->getMetadataEntry('externalID'));
177  } else {
178  $this->object->setExternalId($item->getMetadataEntry('externalId'));
179  }
180 
181  $this->object->setLifecycle($this->fetchLifecycle($item));
182  }
183 
188  protected function fetchLifecycle(ilQTIItem $item)
189  {
190  try {
192  $item->getMetadataEntry('ilias_lifecycle')
193  );
195  try {
196  $lomLifecycle = new ilAssQuestionLomLifecycle(
197  $item->getMetadataEntry('lifecycle')
198  );
199 
201  $lomLifecycle->getMappedIliasLifecycleIdentifer()
202  );
205  }
206  }
207 
208  return $lifecycle;
209  }
210 
214  protected function getQplImportArchivDirectory()
215  {
216  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
217  return ilObjQuestionPool::_getImportDirectory() . '/' . $_SESSION["qpl_import_subdir"];
218  }
219 
223  protected function getTstImportArchivDirectory()
224  {
225  include_once "./Modules/Test/classes/class.ilObjTest.php";
226  return ilObjTest::_getImportDirectory() . '/' . $_SESSION["tst_import_subdir"];
227  }
228 
229  protected function processNonAbstractedImageReferences($text, $sourceNic)
230  {
231  $reg = '/<img.*src=".*\\/mm_(\\d+)\\/(.*?)".*>/m';
232  $matches = null;
233 
234  if (preg_match_all($reg, $text, $matches)) {
235  for ($i = 0, $max = count($matches[1]); $i < $max; $i++) {
236  $mobSrcId = $matches[1][$i];
237  $mobSrcName = $matches[2][$i];
238  $mobSrcLabel = 'il_' . $sourceNic . '_mob_' . $mobSrcId;
239 
240  if (!is_array($_SESSION["import_mob_xhtml"])) {
241  $_SESSION["import_mob_xhtml"] = array();
242  }
243 
244  $_SESSION["import_mob_xhtml"][] = array(
245  "mob" => $mobSrcLabel, "uri" => 'objects/' . $mobSrcLabel . '/' . $mobSrcName
246  );
247  }
248  }
249 
250  include_once "./Services/RTE/classes/class.ilRTE.php";
251  return ilRTE::_replaceMediaObjectImageSrc($text, 0, $sourceNic);
252  }
253 
263  final protected function fetchAdditionalContentEditingModeInformation($qtiItem)
264  {
265  $additionalContentEditingMode = $qtiItem->getMetadataEntry('additional_cont_edit_mode');
266 
267  if (!$this->object->isValidAdditionalContentEditingMode($additionalContentEditingMode)) {
268  $additionalContentEditingMode = assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_RTE;
269  }
270 
271  return $additionalContentEditingMode;
272  }
273 }
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
addGeneralMetadata(ilQTIItem $item)
$_SESSION["AccountId"]
processNonAbstractedImageReferences($text, $sourceNic)
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) ...
getMetadataEntry($a_label)
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
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...
fetchLifecycle(ilQTIItem $item)
const ADDITIONAL_CONTENT_EDITING_MODE_RTE
constant for additional content editing mode "default"
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
static _getImportDirectory()
get import directory of lm
__construct($a_object)
assQuestionImport constructor
Class for question imports.
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
static _getImportDirectory()
Get the import directory location of the test.
$i
Definition: metadata.php:24