1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Ordering question type conversion handler
|
|
|
19 |
*
|
|
|
20 |
* @package qtype_ordering
|
|
|
21 |
* @copyright 2013 Gordon Bateson (gordon.bateson@gmail.com)
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Ordering question type conversion handler class
|
|
|
27 |
*
|
|
|
28 |
* @copyright 2013 Gordon Bateson (gordon.bateson@gmail.com)
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
* @codeCoverageIgnore For old Moodle sites in which upgrades are always risky.
|
|
|
31 |
*/
|
|
|
32 |
class moodle1_qtype_ordering_handler extends moodle1_qtype_handler {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Returns the list of paths within one <QUESTION> that this qtype needs to have included
|
|
|
36 |
* in the grouped question structure
|
|
|
37 |
*
|
|
|
38 |
* @return string[]
|
|
|
39 |
*/
|
|
|
40 |
public function get_question_subpaths(): array {
|
|
|
41 |
return [
|
|
|
42 |
'ANSWERS/ANSWER',
|
|
|
43 |
'ORDERING',
|
|
|
44 |
];
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Gives the qtype handler a chance to write converted data into questions.xml
|
|
|
49 |
*
|
|
|
50 |
* @param array $data grouped question data
|
|
|
51 |
* @param array $raw grouped raw QUESTION data
|
|
|
52 |
*/
|
|
|
53 |
public function process_question(array $data, array $raw): void {
|
|
|
54 |
|
|
|
55 |
// Convert and write the answers first.
|
|
|
56 |
if (isset($data['answers'])) {
|
|
|
57 |
$this->write_answers($data['answers'], $this->pluginname);
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
// Convert and write the ordering extra fields.
|
|
|
61 |
foreach ($data['ordering'] as $ordering) {
|
|
|
62 |
$ordering['id'] = $this->converter->get_nextid();
|
|
|
63 |
$this->write_xml('ordering', $ordering, ['/ordering/id']);
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
}
|