ILIAS  trunk Revision v5.2.0beta1-34132-g2d4d73d4a0
assKprimChoiceExport Class Reference
+ Inheritance diagram for assKprimChoiceExport:
+ Collaboration diagram for assKprimChoiceExport:

Public Member Functions

 toXML ($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false)
 
- 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)
 

Data Fields

 $object
 
- Data Fields inherited from assQuestionExport
 $object
 
const ITEM_SOLUTIONHINT = 'solutionhint'
 

Private Member Functions

 getMinPoints ()
 
 getMaxPoints ()
 

Additional Inherited Members

- 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)
 
 addSolutionHints (ilXmlWriter $writer)
 
 addSuggestedSolutionLink (ilXmlWriter $writer, assQuestionSuggestedSolution $suggested_solution)
 

Detailed Description

Definition at line 26 of file class.assKprimChoiceExport.php.

Member Function Documentation

◆ getMaxPoints()

assKprimChoiceExport::getMaxPoints ( )
private

Definition at line 311 of file class.assKprimChoiceExport.php.

Referenced by toXML().

311  : float
312  {
313  return $this->object->getPoints();
314  }
+ Here is the caller graph for this function:

◆ getMinPoints()

assKprimChoiceExport::getMinPoints ( )
private

Definition at line 302 of file class.assKprimChoiceExport.php.

References ILIAS\Repository\object().

Referenced by toXML().

303  {
304  if ($this->object->isScorePartialSolutionEnabled()) {
305  return ($this->object->getPoints() / 2);
306  }
307 
308  return 0;
309  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

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

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

References $DIC, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), assQuestionExport\addQTIMaterial(), assQuestionExport\addSolutionHints(), assQuestionExport\addSuggestedSolutionLink(), getMaxPoints(), getMinPoints(), IL_INST_ID, and ILIAS\Repository\object().

33  : string
34  {
35  global $DIC;
36  $ilias = $DIC['ilias'];
37 
38  $a_xml_writer = new ilXmlWriter();
39  // set xml header
40  $a_xml_writer->xmlHeader();
41  $a_xml_writer->xmlStartTag("questestinterop");
42  $attrs = array(
43  "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
44  "title" => $this->object->getTitle(),
45  "maxattempts" => $this->object->getNrOfTries()
46  );
47  $a_xml_writer->xmlStartTag("item", $attrs);
48  // add question description
49  $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
50  $a_xml_writer->xmlStartTag("itemmetadata");
51  $a_xml_writer->xmlStartTag("qtimetadata");
52  $a_xml_writer->xmlStartTag("qtimetadatafield");
53  $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
54  $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
55  $a_xml_writer->xmlEndTag("qtimetadatafield");
56  $a_xml_writer->xmlStartTag("qtimetadatafield");
57  $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
58  $a_xml_writer->xmlElement("fieldentry", null, QuestionIdentifiers::KPRIM_CHOICE_QUESTION_IDENTIFIER);
59  $a_xml_writer->xmlEndTag("qtimetadatafield");
60  $a_xml_writer->xmlStartTag("qtimetadatafield");
61  $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
62  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
63  $a_xml_writer->xmlEndTag("qtimetadatafield");
64 
65  // additional content editing information
66  $this->addAdditionalContentEditingModeInformation($a_xml_writer);
67  $this->addGeneralMetadata($a_xml_writer);
68 
69  $a_xml_writer->xmlStartTag("qtimetadatafield");
70  $a_xml_writer->xmlElement("fieldlabel", null, "answer_type");
71  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAnswerType());
72  $a_xml_writer->xmlEndTag("qtimetadatafield");
73 
74  $a_xml_writer->xmlStartTag("qtimetadatafield");
75  $a_xml_writer->xmlElement("fieldlabel", null, "thumb_size");
76  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getThumbSize());
77  $a_xml_writer->xmlEndTag("qtimetadatafield");
78 
79  $a_xml_writer->xmlStartTag("qtimetadatafield");
80  $a_xml_writer->xmlElement("fieldlabel", null, "option_label_setting");
81  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getOptionLabel());
82  $a_xml_writer->xmlEndTag("qtimetadatafield");
83  $a_xml_writer->xmlStartTag("qtimetadatafield");
84  $a_xml_writer->xmlElement("fieldlabel", null, "custom_true_option_label");
85  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getCustomTrueOptionLabel());
86  $a_xml_writer->xmlEndTag("qtimetadatafield");
87  $a_xml_writer->xmlStartTag("qtimetadatafield");
88  $a_xml_writer->xmlElement("fieldlabel", null, "custom_false_option_label");
89  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getCustomFalseOptionLabel());
90  $a_xml_writer->xmlEndTag("qtimetadatafield");
91 
92  $a_xml_writer->xmlStartTag("qtimetadatafield");
93  $a_xml_writer->xmlElement("fieldlabel", null, "feedback_setting");
94  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getSpecificFeedbackSetting());
95  $a_xml_writer->xmlEndTag("qtimetadatafield");
96 
97  $a_xml_writer->xmlEndTag("qtimetadata");
98  $a_xml_writer->xmlEndTag("itemmetadata");
99 
100  // PART I: qti presentation
101  $attrs = array(
102  "label" => $this->object->getTitle()
103  );
104  $a_xml_writer->xmlStartTag("presentation", $attrs);
105  // add flow to presentation
106  $a_xml_writer->xmlStartTag("flow");
107  // add material with question text to presentation
108  $this->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
109  // add answers to presentation
110  $attrs = array(
111  "ident" => "MCMR",
112  "rcardinality" => "Multiple"
113  );
114  $a_xml_writer->xmlStartTag("response_lid", $attrs);
115  $solution = $this->object->getSuggestedSolution(0);
116 
117  if ($solution !== null) {
118  $a_xml_writer = $this->addSuggestedSolutionLink($a_xml_writer, $solution);
119  }
120  // shuffle output
121  $attrs = array();
122  if ($this->object->isShuffleAnswersEnabled()) {
123  $attrs = array(
124  "shuffle" => "Yes"
125  );
126  } else {
127  $attrs = array(
128  "shuffle" => "No"
129  );
130  }
131  $a_xml_writer->xmlStartTag("render_choice", $attrs);
132 
133  // add answers
134  $answers = $this->object->getAnswers();
135  $akeys = array_keys($answers);
136  foreach ($akeys as $index) {
137  $answer = $this->object->getAnswer($index);
138 
139  $a_xml_writer->xmlStartTag('response_label', array('ident' => $answer->getPosition()));
140 
141  $image_file = $answer->getImageFile() ?? '';
142  if ($image_file !== '') {
143  $this->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), false, false);
144  $imagetype = "image/jpeg";
145  if (preg_match("/.*\.(png|gif)$/", $image_file, $matches)) {
146  $imagetype = "image/" . $matches[1];
147  }
148  if ($force_image_references) {
149  $attrs = array(
150  "imagtype" => $imagetype,
151  "label" => $image_file,
152  "uri" => $answer->getImageWebPath()
153  );
154  $a_xml_writer->xmlElement("matimage", $attrs);
155  } else {
156  $imagepath = $answer->getImageFsPath();
157  $fh = @fopen($imagepath, "rb");
158  if ($fh != false) {
159  $imagefile = fread($fh, filesize($imagepath));
160  fclose($fh);
161  $base64 = base64_encode($imagefile);
162  $attrs = array(
163  "imagtype" => $imagetype,
164  "label" => $image_file,
165  "embedded" => "base64"
166  );
167  $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
168  }
169  }
170  $a_xml_writer->xmlEndTag("material");
171  } else {
172  $this->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
173  }
174  $a_xml_writer->xmlEndTag("response_label");
175  }
176  $a_xml_writer->xmlEndTag("render_choice");
177  $a_xml_writer->xmlEndTag("response_lid");
178  $a_xml_writer->xmlEndTag("flow");
179  $a_xml_writer->xmlEndTag("presentation");
180 
181  // PART II: qti resprocessing
182 
183  $a_xml_writer->xmlStartTag('resprocessing');
184 
185  $a_xml_writer->xmlStartTag('outcomes');
186  $a_xml_writer->xmlElement('decvar', array(
187  'varname' => 'SCORE', 'vartype' => 'Decimal', 'defaultval' => '0',
188  'minvalue' => $this->getMinPoints(), 'maxvalue' => $this->getMaxPoints()
189  ));
190  $a_xml_writer->xmlEndTag('outcomes');
191 
192 
193  foreach ($answers as $answer) {
194  $a_xml_writer->xmlStartTag('respcondition', array('continue' => 'Yes'));
195 
196  $a_xml_writer->xmlStartTag('conditionvar');
197  $a_xml_writer->xmlElement('varequal', array('respident' => $answer->getPosition()), $answer->getCorrectness());
198  $a_xml_writer->xmlEndTag('conditionvar');
199 
200  $a_xml_writer->xmlElement('displayfeedback', array(
201  'feedbacktype' => 'Response', 'linkrefid' => "response_{$answer->getPosition()}"
202  ));
203 
204  $a_xml_writer->xmlEndTag('respcondition');
205  }
206 
207  $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
208  $this->object->getId(),
209  true
210  );
211 
212  $a_xml_writer->xmlStartTag('respcondition', array('continue' => 'Yes'));
213 
214  $a_xml_writer->xmlStartTag('conditionvar');
215  $a_xml_writer->xmlStartTag('and');
216  foreach ($answers as $answer) {
217  $a_xml_writer->xmlElement('varequal', array('respident' => $answer->getPosition()), $answer->getCorrectness());
218  }
219  $a_xml_writer->xmlEndTag('and');
220  $a_xml_writer->xmlEndTag('conditionvar');
221 
222  $a_xml_writer->xmlElement('setvar', array('action' => 'Add'), $this->object->getPoints());
223 
224  if (strlen($feedback_allcorrect)) {
225  $a_xml_writer->xmlElement('displayfeedback', array('feedbacktype' => 'Response', 'linkrefid' => 'response_allcorrect'));
226  }
227 
228  $a_xml_writer->xmlEndTag('respcondition');
229 
230  $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
231  $this->object->getId(),
232  false
233  );
234 
235  $a_xml_writer->xmlStartTag('respcondition', array('continue' => 'Yes'));
236 
237  $a_xml_writer->xmlStartTag('conditionvar');
238  $a_xml_writer->xmlStartTag('or');
239  foreach ($answers as $answer) {
240  $a_xml_writer->xmlStartTag('not');
241  $a_xml_writer->xmlElement('varequal', array('respident' => $answer->getPosition()), $answer->getCorrectness());
242  $a_xml_writer->xmlEndTag('not');
243  }
244  $a_xml_writer->xmlEndTag('or');
245  $a_xml_writer->xmlEndTag('conditionvar');
246 
247  $a_xml_writer->xmlElement('setvar', array('action' => 'Add'), 0);
248 
249  if (strlen($feedback_onenotcorrect)) {
250  $a_xml_writer->xmlElement('displayfeedback', array('feedbacktype' => 'Response', 'linkrefid' => 'response_onenotcorrect'));
251  }
252 
253  $a_xml_writer->xmlEndTag('respcondition');
254 
255  $a_xml_writer->xmlEndTag('resprocessing');
256 
257  foreach ($answers as $answer) {
258  $a_xml_writer->xmlStartTag('itemfeedback', array('ident' => "response_{$answer->getPosition()}", 'view' => 'All'));
259  $a_xml_writer->xmlStartTag('flow_mat');
260 
261  $this->addQTIMaterial($a_xml_writer, $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
262  $this->object->getId(),
263  0,
264  $answer->getPosition()
265  ));
266 
267  $a_xml_writer->xmlEndTag('flow_mat');
268  $a_xml_writer->xmlEndTag('itemfeedback');
269  }
270  if (strlen($feedback_allcorrect)) {
271  $a_xml_writer->xmlStartTag('itemfeedback', array('ident' => 'response_allcorrect', 'view' => 'All'));
272  $a_xml_writer->xmlStartTag('flow_mat');
273 
274  $this->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
275 
276  $a_xml_writer->xmlEndTag('flow_mat');
277  $a_xml_writer->xmlEndTag('itemfeedback');
278  }
279  if (strlen($feedback_onenotcorrect)) {
280  $a_xml_writer->xmlStartTag('itemfeedback', array('ident' => 'response_onenotcorrect', 'view' => 'All'));
281  $a_xml_writer->xmlStartTag('flow_mat');
282 
283  $this->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
284 
285  $a_xml_writer->xmlEndTag('flow_mat');
286  $a_xml_writer->xmlEndTag('itemfeedback');
287  }
288 
289  $a_xml_writer = $this->addSolutionHints($a_xml_writer);
290 
291  $a_xml_writer->xmlEndTag("item");
292  $a_xml_writer->xmlEndTag("questestinterop");
293 
294  $a_xml_writer = $a_xml_writer->xmlDumpMem(false);
295  if (!$a_include_header) {
296  $pos = strpos($a_xml_writer, "?>");
297  $a_xml_writer = substr($a_xml_writer, $pos + 2);
298  }
299  return $a_xml_writer;
300  }
const IL_INST_ID
Definition: constants.php:40
addSuggestedSolutionLink(ilXmlWriter $writer, assQuestionSuggestedSolution $suggested_solution)
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addGeneralMetadata(ilXmlWriter $xmlwriter)
$DIC
Definition: xapitoken.php:62
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
addSolutionHints(ilXmlWriter $writer)
+ Here is the call graph for this function:

Field Documentation

◆ $object

assKprimChoiceExport::$object

Definition at line 31 of file class.assKprimChoiceExport.php.


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