Skip to content

Commit da1eeea

Browse files
timhuntJenkins
authored andcommitted
MDL-62880 qtype_ddwtos: drop support for legacy import format
It was more than 8 years since we wrote in that format.
1 parent 1b87b66 commit da1eeea

File tree

2 files changed

+11
-219
lines changed

2 files changed

+11
-219
lines changed

question/type/ddwtos/questiontype.php

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,17 @@ public function import_from_xml($data, $question, qformat_xml $format, $extra=nu
7171
$question->shuffleanswers = $format->trans_single(
7272
$format->getpath($data, array('#', 'shuffleanswers', 0, '#'), 1));
7373

74-
if (!empty($data['#']['dragbox'])) {
75-
// Modern XML format.
76-
$dragboxes = $data['#']['dragbox'];
77-
$question->answer = array();
78-
$question->draggroup = array();
79-
$question->infinite = array();
80-
81-
foreach ($data['#']['dragbox'] as $dragboxxml) {
82-
$question->choices[] = array(
83-
'answer' => $format->getpath($dragboxxml, array('#', 'text', 0, '#'), '', true),
84-
'choicegroup' => $format->getpath($dragboxxml, array('#', 'group', 0, '#'), 1),
85-
'infinite' => array_key_exists('infinite', $dragboxxml['#']),
86-
);
87-
}
88-
89-
} else {
90-
// Legacy format containing PHP serialisation.
91-
foreach ($data['#']['answer'] as $answerxml) {
92-
$ans = $format->import_answer($answerxml);
93-
$options = unserialize(stripslashes($ans->feedback['text']));
94-
$question->choices[] = array(
95-
'answer' => $ans->answer,
96-
'choicegroup' => $options->draggroup,
97-
'infinite' => $options->infinite,
98-
);
99-
}
74+
// Import the choices.
75+
$question->answer = array();
76+
$question->draggroup = array();
77+
$question->infinite = array();
78+
79+
foreach ($data['#']['dragbox'] as $dragboxxml) {
80+
$question->choices[] = array(
81+
'answer' => $format->getpath($dragboxxml, array('#', 'text', 0, '#'), '', true),
82+
'choicegroup' => $format->getpath($dragboxxml, array('#', 'group', 0, '#'), 1),
83+
'infinite' => array_key_exists('infinite', $dragboxxml['#']),
84+
);
10085
}
10186

10287
$format->import_combined_feedback($question, $data, true);

question/type/ddwtos/tests/questiontype_test.php

Lines changed: 0 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -243,199 +243,6 @@ public function test_xml_import() {
243243
$this->assertEquals($expectedq->hint, $q->hint);
244244
}
245245

246-
public function test_xml_import_legacy() {
247-
$xml = ' <question type="ddwtos">
248-
<name>
249-
<text>QDandD1 Base definition</text>
250-
</name>
251-
<questiontext format="html">
252-
<text>&lt;p&gt;Drag and drop the words from the list below to fill the blank spaces ' .
253-
'and correctly complete the sentence.&lt;/p&gt; &lt;p&gt;At 25°C all aqueous basic ' .
254-
'solutions have [[1]]&#160;ion concentrations less than [[8]]&lt;br /&gt;mol ' .
255-
'litre&lt;sup&gt;-1&lt;/sup&gt; and pH values [[9]] than [[6]].&lt;/p&gt; ' .
256-
'&lt;!--DONOTCLEAN--&gt;</text>
257-
</questiontext>
258-
<image></image>
259-
<generalfeedback>
260-
<text>&lt;p&gt;At 25 &amp;#xB0;C all aqueous basic solutions have hydrogen ion ' .
261-
'concentrations less than 10&lt;sup&gt;&amp;#x2212;7&lt;/sup&gt; mol ' .
262-
'litre&lt;sup&gt;&amp;#x2212;1&lt;/sup&gt; and pH values greater than 7.&lt;/p&gt; ' .
263-
'&lt;p&gt;See Section 9 of S103 &lt;em class="italic"&gt;Discovering ' .
264-
'Science&lt;/em&gt; Block 8.&lt;/p&gt;</text>
265-
</generalfeedback>
266-
<defaultgrade>1</defaultgrade>
267-
<penalty>0.33</penalty>
268-
<hidden>0</hidden>
269-
<shuffleanswers>0</shuffleanswers>
270-
<shuffleanswers>false</shuffleanswers>
271-
<answer>
272-
<correctanswer>1</correctanswer>
273-
<text>hydrogen</text>
274-
<feedback>
275-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}</text>
276-
</feedback>
277-
</answer>
278-
<answer>
279-
<correctanswer>0</correctanswer>
280-
<text>positive</text>
281-
<feedback>
282-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}</text>
283-
</feedback>
284-
</answer>
285-
<answer>
286-
<correctanswer>0</correctanswer>
287-
<text>hydroxide</text>
288-
<feedback>
289-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}</text>
290-
</feedback>
291-
</answer>
292-
<answer>
293-
<correctanswer>0</correctanswer>
294-
<text>negative</text>
295-
<feedback>
296-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}</text>
297-
</feedback>
298-
</answer>
299-
<answer>
300-
<correctanswer>0</correctanswer>
301-
<text>10&lt;sup&gt;7&lt;/sup&gt;</text>
302-
<feedback>
303-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}</text>
304-
</feedback>
305-
</answer>
306-
<answer>
307-
<correctanswer>1</correctanswer>
308-
<text>7</text>
309-
<feedback>
310-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}</text>
311-
</feedback>
312-
</answer>
313-
<answer>
314-
<correctanswer>0</correctanswer>
315-
<text>1</text>
316-
<feedback>
317-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}</text>
318-
</feedback>
319-
</answer>
320-
<answer>
321-
<correctanswer>1</correctanswer>
322-
<text>10&lt;sup&gt;-7&lt;/sup&gt;</text>
323-
<feedback>
324-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}</text>
325-
</feedback>
326-
</answer>
327-
<answer>
328-
<correctanswer>1</correctanswer>
329-
<text>greater</text>
330-
<feedback>
331-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}</text>
332-
</feedback>
333-
</answer>
334-
<answer>
335-
<correctanswer>0</correctanswer>
336-
<text>less</text>
337-
<feedback>
338-
<text>O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}</text>
339-
</feedback>
340-
</answer>
341-
<correctfeedback>
342-
<text>Your answer is correct.</text>
343-
</correctfeedback>
344-
<correctresponsesfeedback>1</correctresponsesfeedback>
345-
<partiallycorrectfeedback>
346-
<text>Your answer is partially correct.</text>
347-
</partiallycorrectfeedback>
348-
<incorrectfeedback>
349-
<text>Your answer is incorrect.</text>
350-
</incorrectfeedback>
351-
<unlimited>0</unlimited>
352-
<penalty>0.33</penalty>
353-
<hint>
354-
<statenumberofcorrectresponses>1</statenumberofcorrectresponses>
355-
<clearincorrectresponses>0</clearincorrectresponses>
356-
<hintcontent>
357-
<text>You may wish to read&#160;Section 9 of&#160;&lt;em ' .
358-
'class="italic"&gt;Discovering Science&lt;/em&gt; Block 8.</text>
359-
</hintcontent>
360-
</hint>
361-
<hint>
362-
<statenumberofcorrectresponses>1</statenumberofcorrectresponses>
363-
<clearincorrectresponses>1</clearincorrectresponses>
364-
<hintcontent>
365-
<text>Any incorrect choices&#160;will be removed before your final try.</text>
366-
</hintcontent>
367-
</hint>
368-
</question>';
369-
$xmldata = xmlize($xml);
370-
371-
$importer = new qformat_xml();
372-
$q = $importer->try_importing_using_qtypes(
373-
$xmldata['question'], null, null, 'ddwtos');
374-
375-
$expectedq = new stdClass();
376-
$expectedq->qtype = 'ddwtos';
377-
$expectedq->name = 'QDandD1 Base definition';
378-
$expectedq->questiontext = '<p>Drag and drop the words from the list below ' .
379-
'to fill the blank spaces and correctly complete the sentence.</p>' .
380-
'<p>At 25°C all aqueous basic solutions have [[1]] ion concentrations ' .
381-
'less than [[8]]<br />mol litre<sup>-1</sup> and pH values [[9]] than [[6]].</p>' .
382-
'<!--DONOTCLEAN-->';
383-
$expectedq->questiontextformat = FORMAT_HTML;
384-
$expectedq->generalfeedback = '<p>At 25 &#xB0;C all aqueous basic solutions ' .
385-
'have hydrogen ion concentrations less than 10<sup>&#x2212;7</sup> ' .
386-
'mol litre<sup>&#x2212;1</sup> and pH values greater than 7.</p><p>See ' .
387-
'Section 9 of S103 <em class="italic">Discovering Science</em> Block 8.</p>';
388-
$expectedq->defaultmark = 1;
389-
$expectedq->length = 1;
390-
$expectedq->penalty = 0.3333333;
391-
392-
$expectedq->shuffleanswers = 0;
393-
$expectedq->correctfeedback = array('text' => 'Your answer is correct.',
394-
'format' => FORMAT_HTML);
395-
$expectedq->partiallycorrectfeedback = array(
396-
'text' => 'Your answer is partially correct.',
397-
'format' => FORMAT_HTML);
398-
$expectedq->shownumcorrect = true;
399-
$expectedq->incorrectfeedback = array('text' => 'Your answer is incorrect.',
400-
'format' => FORMAT_HTML);
401-
402-
$expectedq->choices = array(
403-
array('answer' => array('text' => 'hydrogen', 'format' => FORMAT_PLAIN),
404-
'choicegroup' => 1, 'infinite' => false),
405-
array('answer' => array('text' => 'positive', 'format' => FORMAT_PLAIN),
406-
'choicegroup' => 1, 'infinite' => false),
407-
array('answer' => array('text' => 'hydroxide', 'format' => FORMAT_PLAIN),
408-
'choicegroup' => 1, 'infinite' => false),
409-
array('answer' => array('text' => 'negative', 'format' => FORMAT_PLAIN),
410-
'choicegroup' => 1, 'infinite' => false),
411-
array('answer' => array('text' => '10<sup>7</sup>', 'format' => FORMAT_PLAIN),
412-
'choicegroup' => 2, 'infinite' => false),
413-
array('answer' => array('text' => '7', 'format' => FORMAT_PLAIN),
414-
'choicegroup' => 2, 'infinite' => false),
415-
array('answer' => array('text' => '1', 'format' => FORMAT_PLAIN),
416-
'choicegroup' => 2, 'infinite' => false),
417-
array('answer' => array('text' => '10<sup>-7</sup>', 'format' => FORMAT_PLAIN),
418-
'choicegroup' => 2, 'infinite' => false),
419-
array('answer' => array('text' => 'greater', 'format' => FORMAT_PLAIN),
420-
'choicegroup' => 3, 'infinite' => false),
421-
array('answer' => array('text' => 'less', 'format' => FORMAT_PLAIN),
422-
'choicegroup' => 3, 'infinite' => false),
423-
);
424-
425-
$expectedq->hint = array(array('text' => 'You may wish to read Section 9 of ' .
426-
'<em class="italic">Discovering Science</em> Block 8.',
427-
'format' => FORMAT_HTML),
428-
array('text' => 'Any incorrect choices will be removed before your final try.',
429-
'format' => FORMAT_HTML),
430-
);
431-
$expectedq->hintshownumcorrect = array(true, true);
432-
$expectedq->hintclearwrong = array(false, true);
433-
434-
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
435-
$this->assertEquals($expectedq->choices, $q->choices);
436-
$this->assertEquals($expectedq->hint, $q->hint);
437-
}
438-
439246
public function test_xml_export() {
440247
$qdata = new stdClass();
441248
$qdata->id = 123;

0 commit comments

Comments
 (0)