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