4 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
35 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
42 $presentation = $item->getPresentation();
43 $duration = $item->getDuration();
47 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
48 foreach ($presentation->order as $entry) {
49 switch ($entry[
"type"]) {
51 $response = $presentation->response[$entry[
"index"]];
53 switch (strtolower(get_class($rendertype))) {
54 case "ilqtirenderfib":
55 $maxchars = $rendertype->getMaxchars();
62 $feedbacksgeneric = array();
63 foreach ($item->resprocessing as $resprocessing) {
64 $outcomes = $resprocessing->getOutcomes();
65 foreach ($outcomes->decvar as $decvar) {
66 $maxpoints = $decvar->getMaxvalue();
69 foreach ($resprocessing->respcondition as $respcondition) {
70 foreach ($respcondition->displayfeedback as $feedbackpointer) {
71 if (strlen($feedbackpointer->getLinkrefid())) {
72 foreach ($item->itemfeedback as $ifb) {
73 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
75 if (count($ifb->material)) {
76 foreach ($ifb->material as $material) {
77 $feedbacksgeneric[1] = $material;
80 if ((count($ifb->flow_mat) > 0)) {
81 foreach ($ifb->flow_mat as $fmat) {
82 if (count($fmat->material)) {
83 foreach ($fmat->material as $material) {
84 $feedbacksgeneric[1] = $material;
89 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
91 if (count($ifb->material)) {
92 foreach ($ifb->material as $material) {
93 $feedbacksgeneric[0] = $material;
96 if ((count($ifb->flow_mat) > 0)) {
97 foreach ($ifb->flow_mat as $fmat) {
98 if (count($fmat->material)) {
99 foreach ($fmat->material as $material) {
100 $feedbacksgeneric[0] = $material;
112 $this->
object->setTitle($item->getTitle());
113 $this->
object->setNrOfTries($item->getMaxattempts());
114 $this->
object->setComment($item->getComment());
115 $this->
object->setAuthor($item->getAuthor());
116 $this->
object->setOwner(
$ilUser->getId());
117 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
118 $this->
object->setObjId($questionpool_id);
119 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
120 $this->
object->setPoints($maxpoints);
121 $this->
object->setMaxNumOfChars($maxchars);
122 $this->
object->setWordCounterEnabled((
bool) $item->getMetadataEntry(
'wordcounter'));
123 $textrating = $item->getMetadataEntry(
"textrating");
124 if (strlen($textrating)) {
125 $this->
object->setTextRating($textrating);
127 $this->
object->matchcondition = (strlen($item->getMetadataEntry(
'matchcondition'))) ? $item->getMetadataEntry(
'matchcondition') : 0;
129 require_once
'./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php';
130 $no_keywords_found =
true;
133 for (
$i = 0;
$i < count($termscoring);
$i++) {
134 $this->
object->addAnswer($termscoring[
$i]->getAnswertext(), $termscoring[
$i]->getPoints());
135 $no_keywords_found =
false;
137 if (count($termscoring)) {
138 $this->
object->setKeywordRelation($item->getMetadataEntry(
'termrelation'));
141 $keywords = $item->getMetadataEntry(
"keywords");
142 if (strlen($keywords)) {
143 #$this->object->setKeywords($keywords); 144 $answers = explode(
' ', $keywords);
145 foreach ($answers as $answer) {
146 $this->
object->addAnswer($answer, 0);
148 $this->
object->setKeywordRelation(
'one');
149 $no_keywords_found =
false;
151 if ($no_keywords_found) {
152 $this->
object->setKeywordRelation(
'non');
156 $this->
object->setAdditionalContentEditingMode(
159 $this->
object->saveToDb();
160 if (count($item->suggested_solutions)) {
161 foreach ($item->suggested_solutions as $suggested_solution) {
162 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
164 $this->
object->saveToDb();
166 foreach ($feedbacksgeneric as $correctness => $material) {
167 $m = $this->
object->QTIMaterialToString($material);
168 $feedbacksgeneric[$correctness] = $m;
171 $questiontext = $this->
object->getQuestion();
175 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
176 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
177 include_once
"./Services/RTE/classes/class.ilRTE.php";
178 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
186 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
190 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
191 foreach ($feedbacks as $ident => $material) {
192 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
194 foreach ($feedbacksgeneric as $correctness => $material) {
195 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
200 foreach ($feedbacks as $ident => $material) {
203 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
204 $this->object->getId(),
210 foreach ($feedbacksgeneric as $correctness => $material) {
211 $this->
object->feedbackOBJ->importGenericFeedback(
212 $this->object->getId(),
217 $this->
object->saveToDb();
219 $q_1_id = $this->
object->getId();
220 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
221 $tst_object->questions[$question_counter++] = $question_id;
222 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
224 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
230 $termScoringString = $item->getMetadataEntry(
'termscoring');
232 if (!strlen($termScoringString)) {
236 $termScoring = unserialize($termScoringString);
238 if (is_array($termScoring)) {
242 $termScoringString = base64_decode($termScoringString);
243 $termScoring = unserialize($termScoringString);
245 if (is_array($termScoring)) {
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
addGeneralMetadata(ilQTIItem $item)
Class for essay question imports.
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) ...
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.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')