ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.assQuestionExport.php
Go to the documentation of this file.
1 <?php
2 
20 
31 {
35  public $object;
36 
43  public function __construct($a_object)
44  {
45  $this->object = $a_object;
46  }
47 
51  protected function addAnswerSpecificFeedback(ilXmlWriter $a_xml_writer, $answers): void
52  {
53  foreach ($answers as $index => $answer) {
54  $linkrefid = "response_$index";
55  $attrs = [
56  "ident" => $linkrefid,
57  "view" => "All"
58  ];
59  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
60  // qti flow_mat
61  $a_xml_writer->xmlStartTag("flow_mat");
62  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
63  $this->object->getId(),
64  0,
65  $index
66  );
67  $this->addQTIMaterial($a_xml_writer, $fb);
68  $a_xml_writer->xmlEndTag("flow_mat");
69  $a_xml_writer->xmlEndTag("itemfeedback");
70  }
71  }
72 
76  protected function addGenericFeedback(ilXmlWriter $a_xml_writer): void
77  {
78  $this->exportFeedbackOnly($a_xml_writer);
79  }
80 
81  public function exportFeedbackOnly($a_xml_writer): void
82  {
83  $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
84  $this->object->getId(),
85  true
86  );
87  $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
88  $this->object->getId(),
89  false
90  );
91  if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
92  $a_xml_writer->xmlStartTag("resprocessing");
93  $a_xml_writer->xmlStartTag("outcomes");
94  $a_xml_writer->xmlStartTag("decvar");
95  $a_xml_writer->xmlEndTag("decvar");
96  $a_xml_writer->xmlEndTag("outcomes");
97 
98  if (strlen($feedback_allcorrect)) {
99  $attrs = [
100  "continue" => "Yes"
101  ];
102  $a_xml_writer->xmlStartTag("respcondition", $attrs);
103  // qti conditionvar
104  $a_xml_writer->xmlStartTag("conditionvar");
105  $attrs = [
106  "respident" => "points"
107  ];
108  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
109  $a_xml_writer->xmlEndTag("conditionvar");
110  // qti displayfeedback
111  $attrs = [
112  "feedbacktype" => "Response",
113  "linkrefid" => "response_allcorrect"
114  ];
115  $a_xml_writer->xmlElement("displayfeedback", $attrs);
116  $a_xml_writer->xmlEndTag("respcondition");
117  }
118 
119  if (strlen($feedback_onenotcorrect)) {
120  $attrs = [
121  "continue" => "Yes"
122  ];
123  $a_xml_writer->xmlStartTag("respcondition", $attrs);
124  // qti conditionvar
125  $a_xml_writer->xmlStartTag("conditionvar");
126  $a_xml_writer->xmlStartTag("not");
127  $attrs = [
128  "respident" => "points"
129  ];
130  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
131  $a_xml_writer->xmlEndTag("not");
132  $a_xml_writer->xmlEndTag("conditionvar");
133  // qti displayfeedback
134  $attrs = [
135  "feedbacktype" => "Response",
136  "linkrefid" => "response_onenotcorrect"
137  ];
138  $a_xml_writer->xmlElement("displayfeedback", $attrs);
139  $a_xml_writer->xmlEndTag("respcondition");
140  }
141  $a_xml_writer->xmlEndTag("resprocessing");
142  }
143 
144  if (strlen($feedback_allcorrect)) {
145  $attrs = [
146  "ident" => "response_allcorrect",
147  "view" => "All"
148  ];
149  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
150  // qti flow_mat
151  $a_xml_writer->xmlStartTag("flow_mat");
152  $this->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
153  $a_xml_writer->xmlEndTag("flow_mat");
154  $a_xml_writer->xmlEndTag("itemfeedback");
155  }
156  if (strlen($feedback_onenotcorrect)) {
157  $attrs = [
158  "ident" => "response_onenotcorrect",
159  "view" => "All"
160  ];
161  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
162  // qti flow_mat
163  $a_xml_writer->xmlStartTag("flow_mat");
164  $this->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
165  $a_xml_writer->xmlEndTag("flow_mat");
166  $a_xml_writer->xmlEndTag("itemfeedback");
167  }
168  }
169 
175  public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
176  {
177  return '';
178  }
179 
190  final protected function addQtiMetaDataField(ilXmlWriter $a_xml_writer, $fieldLabel, $fieldValue): void
191  {
192  $a_xml_writer->xmlStartTag("qtimetadatafield");
193  $a_xml_writer->xmlElement("fieldlabel", null, $fieldLabel);
194  $a_xml_writer->xmlElement("fieldentry", null, $fieldValue);
195  $a_xml_writer->xmlEndTag("qtimetadatafield");
196  }
197 
206  final protected function addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer): void
207  {
208  $this->addQtiMetaDataField(
209  $a_xml_writer,
210  'additional_cont_edit_mode',
211  $this->object->getAdditionalContentEditingMode()
212  );
213  }
214 
218  protected function addGeneralMetadata(ilXmlWriter $xmlwriter): void
219  {
220  $this->addQtiMetaDataField($xmlwriter, 'externalId', $this->object->getExternalId());
221 
222  $this->addQtiMetaDataField(
223  $xmlwriter,
224  'ilias_lifecycle',
225  $this->object->getLifecycle()->getIdentifier()
226  );
227 
228  $this->addQtiMetaDataField(
229  $xmlwriter,
230  'lifecycle',
231  $this->object->getLifecycle()->getMappedLomLifecycle()
232  );
233  }
234 
235  public const ITEM_SOLUTIONHINT = 'solutionhint';
236 
237  protected function addSolutionHints(ilXmlWriter $writer): ilXmlWriter
238  {
239  $question_id = (int) $this->object->getId();
240  $list = ilAssQuestionHintList::getListByQuestionId($question_id);
241 
242  foreach ($list as $hint) {
243  $attrs = [
244  'index' => $hint->getIndex(),
245  'points' => $hint->getPoints()
246  ];
247  if ($this->object->isAdditionalContentEditingModePageObject()) {
248  try {
249  $data = (new ilAssHintPage($hint->getId()))->getXMLContent();
250  } catch (Exception $e) {
251  continue;
252  }
253  } else {
254  $data = $hint->getText();
255  }
256 
257  $writer->xmlElement(self::ITEM_SOLUTIONHINT, $attrs, $data);
258  }
259  return $writer;
260  }
261 
262  protected function addSuggestedSolution(ilXmlWriter $writer): ilXmlWriter
263  {
264  $solution = $this->object->getSuggestedSolution();
265  if ($solution === null) {
266  return $writer;
267  }
268 
269  $mattext = ['type' => $solution->getType()];
270  $attrs = [
271  'label' => 'suggested_solution',
272  'texttype' => 'application/json'
273  ];
274 
275  if ($solution instanceof SuggestedSolutionFile) {
276  $mattext['title'] = $solution->getTitle();
277  $mattext['filename'] = $solution->getFilename();
278  $mattext['value'] = base64_encode(file_get_contents(
279  $this->object->getSuggestedSolutionPath() . $solution->getFilename()
280  ));
281  } else {
282  if (!preg_match('/il_(\d*?)_(\w+)_(\d+)/', $solution->getInternalLink(), $matches)) {
283  return $writer;
284  }
285  $mattext['value'] = 'il_' . IL_INST_ID . '_' . $matches[2] . '_' . $matches[3];
286  if ($matches[1] !== '') {
287  $mattext['value'] = $solution->getInternalLink();
288  }
289 
290  }
291 
292  $writer->xmlStartTag('material');
293  $writer->xmlElement('mattext', $attrs, json_encode($mattext));
294  $writer->xmlEndTag('material');
295  return $writer;
296  }
297 
298  public function addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag = true, bool $add_mobs = true): void
299  {
300  $a_xml_writer->xmlStartTag("material");
301  $attrs = [
302  "texttype" => "text/plain"
303  ];
304  if (ilUtil::isHTML($a_material)) {
305  $attrs["texttype"] = "text/xhtml";
306  }
307  $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
308  if ($add_mobs) {
309  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->object->getId());
310  foreach ($mobs as $mob) {
311  $moblabel = "il_" . IL_INST_ID . "_mob_" . $mob;
312  if (str_contains($a_material, "mm_$mob")) {
313  if (ilObjMediaObject::_exists($mob)) {
314  $mob_obj = new ilObjMediaObject($mob);
315  $imgattrs = [
316  "label" => $moblabel,
317  "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
318  ];
319  }
320  $a_xml_writer->xmlElement("matimage", $imgattrs, null);
321  }
322  }
323  }
324  if ($close_material_tag) {
325  $a_xml_writer->xmlEndTag("material");
326  }
327  }
328 }
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...
__construct($a_object)
assQuestionExport constructor
static getListByQuestionId($questionId)
instantiates a question hint list for the passed question id
const IL_INST_ID
Definition: constants.php:40
static isHTML(string $a_text)
Checks if a given string contains HTML or not.
exportFeedbackOnly($a_xml_writer)
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
Class for question exports.
addAnswerSpecificFeedback(ilXmlWriter $a_xml_writer, $answers)
addGeneralMetadata(ilXmlWriter $xmlwriter)
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 ...
xmlEndTag(string $tag)
Writes an endtag.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _exists(int $id, bool $reference=false, ?string $type=null)
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
addSuggestedSolution(ilXmlWriter $writer)
addSolutionHints(ilXmlWriter $writer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addGenericFeedback(ilXmlWriter $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...
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)