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 |
* @package qtype_match
|
|
|
19 |
* @copyright 2011 David Mudrak <david@moodle.com>
|
|
|
20 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
defined('MOODLE_INTERNAL') || die();
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Matching question type conversion handler.
|
|
|
27 |
*/
|
|
|
28 |
class moodle1_qtype_match_handler extends moodle1_qtype_handler {
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* @return array
|
|
|
32 |
*/
|
|
|
33 |
public function get_question_subpaths() {
|
|
|
34 |
return array(
|
|
|
35 |
'MATCHOPTIONS',
|
|
|
36 |
'MATCHS/MATCH',
|
|
|
37 |
);
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Appends the match specific information to the question.
|
|
|
42 |
*/
|
|
|
43 |
public function process_question(array $data, array $raw) {
|
|
|
44 |
global $CFG;
|
|
|
45 |
|
|
|
46 |
// Populate the list of matches first to get their ids.
|
|
|
47 |
// Note that the field is re-populated on restore anyway but let us
|
|
|
48 |
// do our best to produce valid backup files.
|
|
|
49 |
$matchids = array();
|
|
|
50 |
if (isset($data['matchs']['match'])) {
|
|
|
51 |
foreach ($data['matchs']['match'] as $match) {
|
|
|
52 |
$matchids[] = $match['id'];
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
// Convert match options.
|
|
|
57 |
if (isset($data['matchoptions'])) {
|
|
|
58 |
$matchoptions = $data['matchoptions'][0];
|
|
|
59 |
} else {
|
|
|
60 |
$matchoptions = array('shuffleanswers' => 1);
|
|
|
61 |
}
|
|
|
62 |
$matchoptions['id'] = $this->converter->get_nextid();
|
|
|
63 |
$matchoptions['subquestions'] = implode(',', $matchids);
|
|
|
64 |
$this->write_xml('matchoptions', $matchoptions, array('/matchoptions/id'));
|
|
|
65 |
|
|
|
66 |
// Convert matches.
|
|
|
67 |
$this->xmlwriter->begin_tag('matches');
|
|
|
68 |
if (isset($data['matchs']['match'])) {
|
|
|
69 |
foreach ($data['matchs']['match'] as $match) {
|
|
|
70 |
// Replay the upgrade step 2009072100.
|
|
|
71 |
$match['questiontextformat'] = 0;
|
|
|
72 |
if ($CFG->texteditors !== 'textarea' and $data['oldquestiontextformat'] == FORMAT_MOODLE) {
|
|
|
73 |
$match['questiontext'] = text_to_html($match['questiontext'], false, false, true);
|
|
|
74 |
$match['questiontextformat'] = FORMAT_HTML;
|
|
|
75 |
} else {
|
|
|
76 |
$match['questiontextformat'] = $data['oldquestiontextformat'];
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
$match['questiontext'] = $this->migrate_files(
|
|
|
80 |
$match['questiontext'], 'qtype_match', 'subquestion', $match['id']);
|
|
|
81 |
$this->write_xml('match', $match, array('/match/id'));
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
$this->xmlwriter->end_tag('matches');
|
|
|
85 |
}
|
|
|
86 |
}
|