From 0a562bafd1a85edd132efeff959d2d624e9690a8 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Fri, 3 Jun 2011 18:03:17 +0200 Subject: [PATCH] MDL-27626 matching question type conversion handler --- question/type/match/backup/moodle1/lib.php | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 question/type/match/backup/moodle1/lib.php diff --git a/question/type/match/backup/moodle1/lib.php b/question/type/match/backup/moodle1/lib.php new file mode 100644 index 00000000000..08afe9a6b75 --- /dev/null +++ b/question/type/match/backup/moodle1/lib.php @@ -0,0 +1,82 @@ +. + +/** + * @package qtype + * @subpackage match + * @copyright 2011 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Matching question type conversion handler + */ +class moodle1_qtype_match_handler extends moodle1_qtype_handler { + + /** + * @return array + */ + public function get_question_subpaths() { + return array( + 'MATCHOPTIONS', + 'MATCHS/MATCH' + ); + } + + /** + * Appends the match specific information to the question + */ + public function process_question(array $data, array $raw) { + global $CFG; + + // populate the list of matches first to get their ids + // note that the field is re-populated on restore anyway but let us + // do our best to produce valid backup files + $matchids = array(); + if (isset($data['matchs']['match'])) { + foreach ($data['matchs']['match'] as $match) { + $matchids[] = $match['id']; + } + } + + // convert match options + $matchoptions = $data['matchoptions'][0]; + $matchoptions['id'] = $this->converter->get_nextid(); + $matchoptions['subquestions'] = implode(',', $matchids); + $this->write_xml('matchoptions', $matchoptions, array('/matchoptions/id')); + + // convert matches + $this->xmlwriter->begin_tag('matches'); + if (isset($data['matchs']['match'])) { + foreach ($data['matchs']['match'] as $match) { + // replay the upgrade step 2009072100 + $match['questiontextformat'] = 0; + if ($CFG->texteditors !== 'textarea' and $data['oldquestiontextformat'] == FORMAT_MOODLE) { + $match['questiontext'] = text_to_html($match['questiontext'], false, false, true); + $match['questiontextformat'] = FORMAT_HTML; + } else { + $match['questiontextformat'] = $data['oldquestiontextformat']; + } + + $this->write_xml('match', $match, array('/match/id')); + } + } + $this->xmlwriter->end_tag('matches'); + } +}