ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
assTextSubsetImport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for assTextSubsetImport:
+ Collaboration diagram for assTextSubsetImport:

Public Member Functions

 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
- Public Member Functions inherited from assQuestionImport
 getQuestionId ()
 
 getFeedbackGeneric ($item)
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 importSuggestedSolutions (int $question_id, array $solution_from_import)
 
 QTIMaterialToString (ilQTIMaterial $a_material)
 Reads an QTI material tag and creates a text or XHTML string. More...
 

Additional Inherited Members

- Data Fields inherited from assQuestionImport
 $object
 
- Protected Member Functions inherited from assQuestionImport
 fetchIndexFromFeedbackIdent ($feedbackIdent, $prefix='response_')
 
 getFeedbackAnswerSpecific (ilQTIItem $item, $prefix='response_')
 
 addGeneralMetadata (ilQTIItem $item)
 
 fetchLifecycle (ilQTIItem $item)
 
 processNonAbstractedImageReferences ($text, $sourceNic)
 
 fetchAdditionalContentEditingModeInformation ($qtiItem)
 fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_CONTENT_EDITING_MODE_RTE when no or invalid information is given More...
 
 findSolutionTypeByValue (string $value)
 
 getSuggestedSolutionsRepo ()
 
 deduceThumbSizeFromImportValue (?int $size)
 
 addQuestionToParentObjectAndBuildMappingEntry (int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
 
- Protected Attributes inherited from assQuestionImport
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class for text subset question imports

assTextSubsetImport is a class for text subset 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 28 of file class.assTextSubsetImport.php.

Member Function Documentation

◆ fromXML()

assTextSubsetImport::fromXML ( string  $importdirectory,
int  $user_id,
ilQTIItem  $item,
int  $questionpool_id,
?int  $tst_id,
?ilObject $tst_object,
int &  $question_counter,
array  $import_mapping 
)

Reimplemented from assQuestionImport.

Definition at line 30 of file class.assTextSubsetImport.php.

39 : array {
40 // empty session variable for imported xhtml mobs
41 ilSession::clear('import_mob_xhtml');
42 ;
43 $presentation = $item->getPresentation();
44 $shuffle = 0;
45 $idents = [];
46 $now = getdate();
47 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
48 $gaps = [];
49 foreach ($presentation->order as $entry) {
50 switch ($entry["type"]) {
51 case "response":
52 $response = $presentation->response[$entry["index"]];
53 if ($response->getResponseType() == ilQTIResponse::RT_RESPONSE_STR) {
54 array_push($idents, $response->getIdent());
55 }
56 break;
57 }
58 }
59 $responses = [];
60 $feedbacksgeneric = [];
61 foreach ($item->resprocessing as $resprocessing) {
62 foreach ($resprocessing->respcondition as $respcondition) {
63 $ident = "";
64 $correctness = 1;
65 $conditionvar = $respcondition->getConditionvar();
66 foreach ($conditionvar->order as $order) {
67 switch ($order["field"]) {
68 case "varsubset":
69 $respident = $conditionvar->varsubset[$order["index"]]->getRespident();
70 $content = $conditionvar->varsubset[$order["index"]]->getContent();
71 if (!isset($responses[$respident]) || !is_array($responses[$respident])) {
72 $responses[$respident] = [];
73 }
74 $vars = explode(",", $content);
75 foreach ($vars as $var) {
76 array_push($responses[$respident], ["solution" => $var, "points" => ""]);
77 }
78 break;
79 }
80 }
81 foreach ($respcondition->setvar as $setvar) {
82 if ((strcmp($setvar->getVarname(), "matches") == 0) && ($setvar->getAction() == ilQTISetvar::ACTION_ADD)) {
83 foreach ($responses[$respident] as $idx => $solutionarray) {
84 if (strlen($solutionarray["points"]) == 0) {
85 $responses[$respident][$idx]["points"] = $setvar->getContent();
86 }
87 }
88 }
89 }
90 foreach ($resprocessing->respcondition as $e_respcondition) {
91 foreach ($e_respcondition->displayfeedback as $feedbackpointer) {
92 if (strlen($feedbackpointer->getLinkrefid())) {
93 foreach ($item->itemfeedback as $ifb) {
94 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
95 // found a feedback for the identifier
96 if (count($ifb->material)) {
97 foreach ($ifb->material as $material) {
98 $feedbacksgeneric[1] = $material;
99 }
100 }
101 if ((count($ifb->flow_mat) > 0)) {
102 foreach ($ifb->flow_mat as $fmat) {
103 if (count($fmat->material)) {
104 foreach ($fmat->material as $material) {
105 $feedbacksgeneric[1] = $material;
106 }
107 }
108 }
109 }
110 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
111 // found a feedback for the identifier
112 if (count($ifb->material)) {
113 foreach ($ifb->material as $material) {
114 $feedbacksgeneric[0] = $material;
115 }
116 }
117 if ((count($ifb->flow_mat) > 0)) {
118 foreach ($ifb->flow_mat as $fmat) {
119 if (count($fmat->material)) {
120 foreach ($fmat->material as $material) {
121 $feedbacksgeneric[0] = $material;
122 }
123 }
124 }
125 }
126 }
127 }
128 }
129 }
130 }
131 }
132 }
133 $this->addGeneralMetadata($item);
134 $this->object->setTitle($item->getTitle());
135 $this->object->setNrOfTries((int) $item->getMaxattempts());
136 $this->object->setComment($item->getComment());
137 $this->object->setAuthor($item->getAuthor());
138 $this->object->setOwner($user_id);
139 $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
140 $this->object->setObjId($questionpool_id);
141 $textrating = $item->getMetadataEntry("textrating");
142 if (strlen($textrating) == 0) {
143 $textrating = "ci";
144 }
145 $this->object->setTextRating($textrating);
146 $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers"));
147 $response = current($responses);
148 $counter = 0;
149 if (is_array($response)) {
150 foreach ($response as $answer) {
151 $this->object->addAnswer($answer["solution"], $answer["points"], $counter);
152 $counter++;
153 }
154 }
155 // additional content editing mode information
156 $this->object->setAdditionalContentEditingMode(
158 );
159 $this->object->saveToDb();
160 $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
161 foreach ($feedbacksgeneric as $correctness => $material) {
162 $m = $this->QTIMaterialToString($material);
163 $feedbacksgeneric[$correctness] = $m;
164 }
165 // handle the import of media objects in XHTML code
166 $questiontext = $this->object->getQuestion();
167 if (is_array(ilSession::get("import_mob_xhtml"))) {
168 foreach (ilSession::get("import_mob_xhtml") as $mob) {
169 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
170
171 global $DIC; /* @var ILIAS\DI\Container $DIC */
172 $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
173
174 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
175 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
176 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
177 foreach ($feedbacksgeneric as $correctness => $material) {
178 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
179 }
180 }
181 }
182 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
183 foreach ($feedbacksgeneric as $correctness => $material) {
184 $this->object->feedbackOBJ->importGenericFeedback(
185 $this->object->getId(),
186 $correctness,
188 );
189 }
190 $this->object->saveToDb();
191 $import_mapping[$item->getIdent()] = $this->addQuestionToParentObjectAndBuildMappingEntry(
192 $questionpool_id,
193 $tst_id,
194 $question_counter,
195 $tst_object
196 );
197 return $import_mapping;
198 }
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
addGeneralMetadata(ilQTIItem $item)
importSuggestedSolutions(int $question_id, array $solution_from_import)
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
getMetadataEntry(string $a_label)
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static get(string $a_var)
static clear(string $a_var)
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: shib_login.php:26
$counter
$response
Definition: xapitoken.php:93

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