ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
assClozeTestExport Class Reference

Class for cloze question exports. More...

+ Inheritance diagram for assClozeTestExport:
+ Collaboration diagram for assClozeTestExport:

Public Member Functions

 __construct ($object)
 assQuestionExport constructor More...
 
 toXML ($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false)
 Returns a QTI xml representation of the question Returns a QTI xml representation of the question and sets the internal domxml variable with the DOM XML representation of the QTI xml representation. More...
 
 buildQtiExportIdent (ilAssSpecificFeedbackIdentifier $fbIdentifier)
 
- Public Member Functions inherited from assQuestionExport
 __construct ($a_object)
 assQuestionExport constructor More...
 
 exportFeedbackOnly ($a_xml_writer)
 
 toXML ($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false)
 Returns a QTI xml representation of the question Returns a QTI xml representation of the question and sets the internal domxml variable with the DOM XML representation of the QTI xml representation. More...
 
 addQTIMaterial (ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
 

Protected Member Functions

 exportAnswerSpecificFeedbacks (ilXmlWriter $xmlWriter)
 
- Protected Member Functions inherited from assQuestionExport
 addAnswerSpecificFeedback (ilXmlWriter $a_xml_writer, $answers)
 
 addGenericFeedback (ilXmlWriter $a_xml_writer)
 
 addQtiMetaDataField (ilXmlWriter $a_xml_writer, $fieldLabel, $fieldValue)
 adds a qti meta data field with given name and value to the passed xml writer (xml writer must be in context of opened "qtimetadata" tag) More...
 
 addAdditionalContentEditingModeInformation (ilXmlWriter $a_xml_writer)
 adds a qti meta data field for ilias specific information of "additional content editing mode" (xml writer must be in context of opened "qtimetadata" tag) More...
 
 addGeneralMetadata (ilXmlWriter $xmlwriter)
 
 addSuggestedSolution (ilXmlWriter $writer)
 

Private Attributes

RandomGroup $randomGroup
 

Additional Inherited Members

- Data Fields inherited from assQuestionExport
 $object
 

Detailed Description

Class for cloze question exports.

assClozeTestExport is a class for cloze question exports

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$ \
Deprecated:
Use normalized question export instead

Definition at line 33 of file class.assClozeTestExport.php.

Constructor & Destructor Documentation

◆ __construct()

assClozeTestExport::__construct (   $a_object)

assQuestionExport constructor

Parameters
object$a_objectThe question object @access public

Reimplemented from assQuestionExport.

Definition at line 37 of file class.assClozeTestExport.php.

38 {
39 global $DIC;
40
42
43 $this->randomGroup = $DIC->refinery()->random();
44 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References $DIC, assQuestionExport\$object, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildQtiExportIdent()

assClozeTestExport::buildQtiExportIdent ( ilAssSpecificFeedbackIdentifier  $fbIdentifier)
Parameters
ilAssSpecificFeedbackIdentifier$fbIdentifier
Returns
string

Definition at line 483 of file class.assClozeTestExport.php.

483 : string
484 {
485 return "{$fbIdentifier->getQuestionIndex()}_{$fbIdentifier->getAnswerIndex()}";
486 }

Referenced by exportAnswerSpecificFeedbacks().

+ Here is the caller graph for this function:

◆ exportAnswerSpecificFeedbacks()

assClozeTestExport::exportAnswerSpecificFeedbacks ( ilXmlWriter  $xmlWriter)
protected
Parameters
ilXmlWriter$xmlWriter

Definition at line 455 of file class.assClozeTestExport.php.

455 : void
456 {
457 $feedbackIdentifierList = new ilAssSpecificFeedbackIdentifierList();
458 $feedbackIdentifierList->load($this->object->getId());
459
460 foreach ($feedbackIdentifierList as $fbIdentifier) {
461 $feedback = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
462 $this->object->getId(),
463 $fbIdentifier->getQuestionIndex(),
464 $fbIdentifier->getAnswerIndex()
465 );
466
467 $xmlWriter->xmlStartTag("itemfeedback", [
468 "ident" => $this->buildQtiExportIdent($fbIdentifier), "view" => "All"
469 ]);
470
471 $xmlWriter->xmlStartTag("flow_mat");
472 $this->addQTIMaterial($xmlWriter, $feedback);
473 $xmlWriter->xmlEndTag("flow_mat");
474
475 $xmlWriter->xmlEndTag("itemfeedback");
476 }
477 }
buildQtiExportIdent(ilAssSpecificFeedbackIdentifier $fbIdentifier)
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.

References assQuestionExport\addQTIMaterial(), buildQtiExportIdent(), ILIAS\Repository\object(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by toXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

assClozeTestExport::toXML (   $a_include_header = true,
  $a_include_binary = true,
  $a_shuffle = false,
  $test_output = false,
  $force_image_references = false 
)

Returns a QTI xml representation of the question Returns a QTI xml representation of the question and sets the internal domxml variable with the DOM XML representation of the QTI xml representation.

Reimplemented from assQuestionExport.

Definition at line 51 of file class.assClozeTestExport.php.

51 : string
52 {
53 global $DIC;
54 $ilias = $DIC['ilias'];
55
56 $eval = new EvalMath();
57 $eval->suppress_errors = true;
58
59 $a_xml_writer = new ilXmlWriter();
60 // set xml header
61 $a_xml_writer->xmlHeader();
62 $a_xml_writer->xmlStartTag("questestinterop");
63 $attrs = [
64 "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
65 "title" => $this->object->getTitle(),
66 "maxattempts" => $this->object->getNrOfTries()
67 ];
68 $a_xml_writer->xmlStartTag("item", $attrs);
69 // add question description
70 $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
71 $a_xml_writer->xmlStartTag("itemmetadata");
72 $a_xml_writer->xmlStartTag("qtimetadata");
73 $a_xml_writer->xmlStartTag("qtimetadatafield");
74 $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
75 $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
76 $a_xml_writer->xmlEndTag("qtimetadatafield");
77 $a_xml_writer->xmlStartTag("qtimetadatafield");
78 $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
79 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getQuestionType());
80 $a_xml_writer->xmlEndTag("qtimetadatafield");
81 $a_xml_writer->xmlStartTag("qtimetadatafield");
82 $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
83 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
84 $a_xml_writer->xmlEndTag("qtimetadatafield");
85
86 // additional content editing information
88 $this->addGeneralMetadata($a_xml_writer);
89
90 $a_xml_writer->xmlStartTag("qtimetadatafield");
91 $a_xml_writer->xmlElement("fieldlabel", null, "textgaprating");
92 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getTextgapRating());
93 $a_xml_writer->xmlEndTag("qtimetadatafield");
94
95 $a_xml_writer->xmlStartTag("qtimetadatafield");
96 $a_xml_writer->xmlElement("fieldlabel", null, "fixedTextLength");
97 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getFixedTextLength());
98 $a_xml_writer->xmlEndTag("qtimetadatafield");
99
100 $a_xml_writer->xmlStartTag("qtimetadatafield");
101 $a_xml_writer->xmlElement("fieldlabel", null, "identicalScoring");
102 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getIdenticalScoring());
103 $a_xml_writer->xmlEndTag("qtimetadatafield");
104
105 $a_xml_writer->xmlStartTag("qtimetadatafield");
106 $a_xml_writer->xmlElement("fieldlabel", null, "feedback_mode");
107 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getFeedbackMode());
108 $a_xml_writer->xmlEndTag("qtimetadatafield");
109
110 $a_xml_writer->xmlStartTag("qtimetadatafield");
111 $a_xml_writer->xmlElement("fieldlabel", null, "combinations");
112 $a_xml_writer->xmlElement("fieldentry", null, base64_encode(json_encode($this->object->getGapCombinations())));
113 $a_xml_writer->xmlEndTag("qtimetadatafield");
114
115 $a_xml_writer->xmlEndTag("qtimetadata");
116 $a_xml_writer->xmlEndTag("itemmetadata");
117
118 // PART I: qti presentation
119 $attrs = [
120 "label" => $this->object->getTitle()
121 ];
122 $a_xml_writer->xmlStartTag("presentation", $attrs);
123 // add flow to presentation
124 $a_xml_writer->xmlStartTag("flow");
125
126 $questionText = $this->object->getQuestion() ? $this->object->getQuestion() : ' ';
127 $this->addQTIMaterial($a_xml_writer, $questionText);
128
129 $text_parts = preg_split("/\[gap.*?\[\/gap\]/", $this->object->getClozeText());
130
131 // add material with question text to presentation
132 for ($i = 0; $i <= $this->object->getGapCount(); $i++) {
133 $this->addQTIMaterial($a_xml_writer, $text_parts[$i]);
134
135 if ($i < $this->object->getGapCount()) {
136 // add gap
137 $gap = $this->object->getGap($i);
138 switch ($gap->getType()) {
140 // comboboxes
141 $attrs = [
142 "ident" => "gap_$i",
143 "rcardinality" => "Single"
144 ];
145 $a_xml_writer->xmlStartTag("response_str", $attrs);
146 if ($i === 0) {
147 $a_xml_writer = $this->addSuggestedSolution($a_xml_writer);
148 }
149
150 $attrs = ["shuffle" => ($gap->getShuffle() ? "Yes" : "No")];
151 $a_xml_writer->xmlStartTag("render_choice", $attrs);
152
153 // add answers
154 foreach ($gap->getItems($this->randomGroup->dontShuffle()) as $answeritem) {
155 $attrs = [
156 "ident" => $answeritem->getOrder()
157 ];
158 $a_xml_writer->xmlStartTag("response_label", $attrs);
159 $a_xml_writer->xmlStartTag("material");
160 $a_xml_writer->xmlElement("mattext", null, $answeritem->getAnswertext());
161 $a_xml_writer->xmlEndTag("material");
162 $a_xml_writer->xmlEndTag("response_label");
163 }
164 $a_xml_writer->xmlEndTag("render_choice");
165 $a_xml_writer->xmlEndTag("response_str");
166 break;
168 // text fields
169 $attrs = [
170 "ident" => "gap_$i",
171 "rcardinality" => "Single"
172 ];
173 $a_xml_writer->xmlStartTag("response_str", $attrs);
174 if ($i === 0) {
175 $a_xml_writer = $this->addSuggestedSolution($a_xml_writer);
176 }
177 $attrs = [
178 "fibtype" => "String",
179 "prompt" => "Box",
180 "columns" => $gap->getMaxWidth(),
181 "maxchars" => $gap->getGapSize()
182 ];
183 $a_xml_writer->xmlStartTag("render_fib", $attrs);
184 $a_xml_writer->xmlEndTag("render_fib");
185 $a_xml_writer->xmlEndTag("response_str");
186 break;
188 // numeric fields
189 $attrs = [
190 "ident" => "gap_$i",
191 "numtype" => "Decimal",
192 "rcardinality" => "Single"
193 ];
194 $a_xml_writer->xmlStartTag("response_num", $attrs);
195 if ($i === 0) {
196 $a_xml_writer = $this->addSuggestedSolution($a_xml_writer);
197 }
198 $answeritem = $gap->getItem(0);
199 $attrs = [
200 "fibtype" => "Decimal",
201 "prompt" => "Box",
202 "columns" => $gap->getMaxWidth(),
203 "maxchars" => $gap->getGapSize()
204 ];
205 if (is_object($answeritem)) {
206 if ($eval->e($answeritem->getLowerBound()) !== false) {
207 $attrs["minnumber"] = $answeritem->getLowerBound();
208 }
209 if ($eval->e($answeritem->getUpperBound()) !== false) {
210 $attrs["maxnumber"] = $answeritem->getUpperBound();
211 }
212 }
213 $a_xml_writer->xmlStartTag("render_fib", $attrs);
214 $a_xml_writer->xmlEndTag("render_fib");
215 $a_xml_writer->xmlEndTag("response_num");
216 break;
217 }
218 }
219 }
220 $a_xml_writer->xmlEndTag("flow");
221 $a_xml_writer->xmlEndTag("presentation");
222
223 // PART II: qti resprocessing
224 $a_xml_writer->xmlStartTag("resprocessing");
225 $a_xml_writer->xmlStartTag("outcomes");
226 $a_xml_writer->xmlStartTag("decvar");
227 $a_xml_writer->xmlEndTag("decvar");
228 $a_xml_writer->xmlEndTag("outcomes");
229
230 // add response conditions
231 for ($i = 0; $i < $this->object->getGapCount(); $i++) {
232 $gap = $this->object->getGap($i);
233 switch ($gap->getType()) {
235 foreach ($gap->getItems($this->randomGroup->dontShuffle()) as $answer) {
236 $attrs = [
237 "continue" => "Yes"
238 ];
239 $a_xml_writer->xmlStartTag("respcondition", $attrs);
240 // qti conditionvar
241 $a_xml_writer->xmlStartTag("conditionvar");
242
243 $attrs = [
244 "respident" => "gap_$i"
245 ];
246 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
247 $a_xml_writer->xmlEndTag("conditionvar");
248 // qti setvar
249 $attrs = [
250 "action" => "Add"
251 ];
252 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
253 // qti displayfeedback
254 $linkrefid = "$i" . "_Response_" . $answer->getOrder();
255 $attrs = [
256 "feedbacktype" => "Response",
257 "linkrefid" => $linkrefid
258 ];
259 $a_xml_writer->xmlElement("displayfeedback", $attrs);
260 $a_xml_writer->xmlEndTag("respcondition");
261 }
262 break;
265 foreach ($gap->getItems($this->randomGroup->dontShuffle()) as $answer) {
266 $attrs = [
267 "continue" => "Yes"
268 ];
269 $a_xml_writer->xmlStartTag("respcondition", $attrs);
270 // qti conditionvar
271 $a_xml_writer->xmlStartTag("conditionvar");
272 $attrs = [
273 "respident" => "gap_$i"
274 ];
275 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
276 $a_xml_writer->xmlEndTag("conditionvar");
277 // qti setvar
278 $attrs = [
279 "action" => "Add"
280 ];
281 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
282 // qti displayfeedback
283 $linkrefid = "$i" . "_Response_" . $answer->getOrder();
284 $attrs = [
285 "feedbacktype" => "Response",
286 "linkrefid" => $linkrefid
287 ];
288 $a_xml_writer->xmlElement("displayfeedback", $attrs);
289 $a_xml_writer->xmlEndTag("respcondition");
290 }
291 break;
292 }
293 }
294
295 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
296 $this->object->getId(),
297 true
298 );
299 if (strlen($feedback_allcorrect)) {
300 $attrs = [
301 "continue" => "Yes"
302 ];
303 $a_xml_writer->xmlStartTag("respcondition", $attrs);
304 // qti conditionvar
305 $a_xml_writer->xmlStartTag("conditionvar");
306
307 for ($i = 0; $i < $this->object->getGapCount(); $i++) {
308 $gap = $this->object->getGap($i);
309 $indexes = $gap->getBestSolutionIndexes();
310 if ($i > 0) {
311 $a_xml_writer->xmlStartTag("and");
312 }
313 switch ($gap->getType()) {
317 $k = 0;
318 foreach ($indexes as $key) {
319 if ($k > 0) {
320 $a_xml_writer->xmlStartTag("or");
321 }
322 $attrs = [
323 "respident" => "gap_$i"
324 ];
325 $answer = $gap->getItem($key);
326 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
327 if ($k > 0) {
328 $a_xml_writer->xmlEndTag("or");
329 }
330 $k++;
331 }
332 break;
333 }
334 if ($i > 0) {
335 $a_xml_writer->xmlEndTag("and");
336 }
337 }
338 $a_xml_writer->xmlEndTag("conditionvar");
339 // qti displayfeedback
340 $attrs = [
341 "feedbacktype" => "Response",
342 "linkrefid" => "response_allcorrect"
343 ];
344 $a_xml_writer->xmlElement("displayfeedback", $attrs);
345 $a_xml_writer->xmlEndTag("respcondition");
346 }
347 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
348 $this->object->getId(),
349 false
350 );
351 if (strlen($feedback_onenotcorrect)) {
352 $attrs = [
353 "continue" => "Yes"
354 ];
355 $a_xml_writer->xmlStartTag("respcondition", $attrs);
356 // qti conditionvar
357 $a_xml_writer->xmlStartTag("conditionvar");
358
359 $a_xml_writer->xmlStartTag("not");
360 for ($i = 0; $i < $this->object->getGapCount(); $i++) {
361 $gap = $this->object->getGap($i);
362 $indexes = $gap->getBestSolutionIndexes();
363 if ($i > 0) {
364 $a_xml_writer->xmlStartTag("and");
365 }
366 switch ($gap->getType()) {
370 $k = 0;
371 foreach ($indexes as $key) {
372 if ($k > 0) {
373 $a_xml_writer->xmlStartTag("or");
374 }
375 $attrs = [
376 "respident" => "gap_$i"
377 ];
378 $answer = $gap->getItem($key);
379 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
380 if ($k > 0) {
381 $a_xml_writer->xmlEndTag("or");
382 }
383 $k++;
384 }
385 break;
386 }
387 if ($i > 0) {
388 $a_xml_writer->xmlEndTag("and");
389 }
390 }
391 $a_xml_writer->xmlEndTag("not");
392 $a_xml_writer->xmlEndTag("conditionvar");
393 // qti displayfeedback
394 $attrs = [
395 "feedbacktype" => "Response",
396 "linkrefid" => "response_onenotcorrect"
397 ];
398 $a_xml_writer->xmlElement("displayfeedback", $attrs);
399 $a_xml_writer->xmlEndTag("respcondition");
400 }
401
402 $a_xml_writer->xmlEndTag("resprocessing");
403
404 // PART III: qti itemfeedback
405 for ($i = 0; $i < $this->object->getGapCount(); $i++) {
406 $gap = $this->object->getGap($i);
407 switch ($gap->getType()) {
411 break;
412 }
413 }
414 $this->exportAnswerSpecificFeedbacks($a_xml_writer);
415
416 if (strlen($feedback_allcorrect)) {
417 $attrs = [
418 "ident" => "response_allcorrect",
419 "view" => "All"
420 ];
421 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
422 // qti flow_mat
423 $a_xml_writer->xmlStartTag("flow_mat");
424 $this->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
425 $a_xml_writer->xmlEndTag("flow_mat");
426 $a_xml_writer->xmlEndTag("itemfeedback");
427 }
428 if (strlen($feedback_onenotcorrect)) {
429 $attrs = [
430 "ident" => "response_onenotcorrect",
431 "view" => "All"
432 ];
433 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
434 // qti flow_mat
435 $a_xml_writer->xmlStartTag("flow_mat");
436 $this->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
437 $a_xml_writer->xmlEndTag("flow_mat");
438 $a_xml_writer->xmlEndTag("itemfeedback");
439 }
440
441 $a_xml_writer->xmlEndTag("item");
442 $a_xml_writer->xmlEndTag("questestinterop");
443
444 $xml = $a_xml_writer->xmlDumpMem(false);
445 if (!$a_include_header) {
446 $pos = strpos($xml, "?>");
447 $xml = substr($xml, $pos + 2);
448 }
449 return $xml;
450 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exportAnswerSpecificFeedbacks(ilXmlWriter $xmlWriter)
addGeneralMetadata(ilXmlWriter $xmlwriter)
addSuggestedSolution(ilXmlWriter $writer)
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_INST_ID
Definition: constants.php:40

References $DIC, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), assQuestionExport\addQTIMaterial(), assQuestionExport\addSuggestedSolution(), exportAnswerSpecificFeedbacks(), IL_INST_ID, ILIAS\Repository\object(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

+ Here is the call graph for this function:

Field Documentation

◆ $randomGroup

RandomGroup assClozeTestExport::$randomGroup
private

Definition at line 35 of file class.assClozeTestExport.php.


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