ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
4include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
5
16{
25
32 public function __construct($a_object)
33 {
34 $this->object = $a_object;
35 }
36
37 function getFeedbackGeneric($item)
38 {
39 $feedbacksgeneric = array();
40 foreach ($item->resprocessing as $resprocessing)
41 {
42 foreach ($resprocessing->respcondition as $respcondition)
43 {
44 foreach ($respcondition->displayfeedback as $feedbackpointer)
45 {
46 if (strlen($feedbackpointer->getLinkrefid()))
47 {
48 foreach ($item->itemfeedback as $ifb)
49 {
50 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
51 {
52 // found a feedback for the identifier
53 if (count($ifb->material))
54 {
55 foreach ($ifb->material as $material)
56 {
57 $feedbacksgeneric[1] = $material;
58 }
59 }
60 if ((count($ifb->flow_mat) > 0))
61 {
62 foreach ($ifb->flow_mat as $fmat)
63 {
64 if (count($fmat->material))
65 {
66 foreach ($fmat->material as $material)
67 {
68 $feedbacksgeneric[1] = $material;
69 }
70 }
71 }
72 }
73 }
74 else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
75 {
76 // found a feedback for the identifier
77 if (count($ifb->material))
78 {
79 foreach ($ifb->material as $material)
80 {
81 $feedbacksgeneric[0] = $material;
82 }
83 }
84 if ((count($ifb->flow_mat) > 0))
85 {
86 foreach ($ifb->flow_mat as $fmat)
87 {
88 if (count($fmat->material))
89 {
90 foreach ($fmat->material as $material)
91 {
92 $feedbacksgeneric[0] = $material;
93 }
94 }
95 }
96 }
97 }
98 }
99 }
100 }
101 }
102 }
103 // handle the import of media objects in XHTML code
104 foreach ($feedbacksgeneric as $correctness => $material)
105 {
106 $m = $this->object->QTIMaterialToString($material);
107 $feedbacksgeneric[$correctness] = $m;
108 }
109 return $feedbacksgeneric;
110 }
111
117 protected function fetchIndexFromFeedbackIdent($feedbackIdent, $prefix = 'response_')
118 {
119 return (int)str_replace($prefix, '', $feedbackIdent);
120 }
121
127 protected function getFeedbackAnswerSpecific(ilQTIItem $item, $prefix = 'response_')
128 {
129 $feedbacks = array();
130
131 foreach ($item->itemfeedback as $ifb)
132 {
133 if( $ifb->getIdent() == 'response_allcorrect' || $ifb->getIdent() == 'response_onenotcorrect' )
134 {
135 continue;
136 }
137
138 if( $ifb->getIdent() == $prefix.'allcorrect' || $ifb->getIdent() == $prefix.'onenotcorrect' )
139 {
140 continue;
141 }
142
143 if( substr($ifb->getIdent(), 0, strlen($prefix)) != $prefix )
144 {
145 continue;
146 }
147
148 $ident = $ifb->getIdent();
149
150 // found a feedback for the identifier
151
152 if (count($ifb->material))
153 {
154 foreach ($ifb->material as $material)
155 {
156 $feedbacks[$ident] = $material;
157 }
158 }
159
160 if ((count($ifb->flow_mat) > 0))
161 {
162 foreach ($ifb->flow_mat as $fmat)
163 {
164 if (count($fmat->material))
165 {
166 foreach ($fmat->material as $material)
167 {
168 $feedbacks[$ident] = $material;
169 }
170 }
171 }
172 }
173 }
174
175 foreach($feedbacks as $ident => $material)
176 {
177 $m = $this->object->QTIMaterialToString($material);
178 $feedbacks[$ident] = $m;
179 }
180
181 return $feedbacks;
182 }
183
197 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
198 {
199 }
200
204 protected function addGeneralMetadata(ilQTIItem $item)
205 {
206 $this->object->setExternalId($item->getMetadataEntry('externalID'));
207 }
208
212 protected function getQplImportArchivDirectory()
213 {
214 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
215 return ilObjQuestionPool::_getImportDirectory() . '/' . $_SESSION["qpl_import_subdir"];
216 }
217
221 protected function getTstImportArchivDirectory()
222 {
223 include_once "./Modules/Test/classes/class.ilObjTest.php";
224 return ilObjTest::_getImportDirectory() . '/' . $_SESSION["tst_import_subdir"];
225 }
226
227 protected function processNonAbstractedImageReferences($text, $sourceNic)
228 {
229 $reg = '/<img.*src=".*\\/mm_(\\d+)\\/(.*?)".*>/m';
230 $matches = null;
231
232 if( preg_match_all($reg, $text, $matches) )
233 {
234 for($i = 0, $max = count($matches[1]); $i < $max; $i++)
235 {
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 {
242 $_SESSION["import_mob_xhtml"] = array();
243 }
244
245 $_SESSION["import_mob_xhtml"][] = array(
246 "mob" => $mobSrcLabel, "uri" => 'objects/'.$mobSrcLabel.'/'.$mobSrcName
247 );
248 }
249 }
250
251 include_once "./Services/RTE/classes/class.ilRTE.php";
252 return ilRTE::_replaceMediaObjectImageSrc($text, 0, $sourceNic);
253 }
254
264 final protected function fetchAdditionalContentEditingModeInformation($qtiItem)
265 {
266 $additionalContentEditingMode = $qtiItem->getMetadataEntry('additional_cont_edit_mode');
267
268 if( !$this->object->isValidAdditionalContentEditingMode($additionalContentEditingMode) )
269 {
270 $additionalContentEditingMode = assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT;
271 }
272
273 return $additionalContentEditingMode;
274 }
275}
276
277?>
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Class for question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
__construct($a_object)
assQuestionImport constructor
processNonAbstractedImageReferences($text, $sourceNic)
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
addGeneralMetadata(ilQTIItem $item)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
const ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT
constant for additional content editing mode "default"
static _getImportDirectory()
get import directory of lm
static _getImportDirectory()
Get the import directory location of the test.
getMetadataEntry($a_label)
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...
$text