MDL-27639 restore of attempt data from 2.0 - first attempt.
[moodle.git] / question / type / calculatedmulti / backup / moodle2 / restore_qtype_calculatedmulti_plugin.class.php
blob226863fc6b5a850ea450c8d9dbe09d214abf4a09
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.
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/>.
17 /**
18 * @package moodlecore
19 * @subpackage backup-moodle2
20 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->dirroot .
29 '/question/type/calculated/backup/moodle2/restore_qtype_calculated_plugin.class.php');
31 /**
32 * restore plugin class that provides the necessary information
33 * needed to restore one calculatedmulti qtype plugin.
35 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class restore_qtype_calculatedmulti_plugin extends restore_qtype_calculated_plugin {
40 /**
41 * Given one question_states record, return the answer
42 * recoded pointing to all the restored stuff for calculatedmulti questions
44 * answer format is datasetxx-yy:zz, where xx is the itemnumber in the dataset
45 * (doesn't need conversion), and both yy and zz are two (hypen speparated)
46 * lists of comma separated question_answers, the first to specify the order
47 * of the answers and the second to specify the responses.
49 * in fact, this qtype behaves exactly like the multichoice one, so we'll delegate
50 * recoding of those yy:zz to it
52 public function recode_legacy_state_answer($state) {
53 $answer = $state->answer;
54 $result = '';
55 // datasetxx-yy:zz format
56 if (preg_match('~^dataset([0-9]+)-(.*)$~', $answer, $matches)) {
57 $itemid = $matches[1];
58 $subanswer = $matches[2];
59 // Delegate subanswer recode to multichoice qtype, faking one question_states record
60 $substate = new stdClass();
61 $substate->answer = $subanswer;
62 $newanswer = $this->step->restore_recode_legacy_answer($substate, 'multichoice');
63 $result = 'dataset' . $itemid . '-' . $newanswer;
65 return $result ? $result : $answer;