Merge branch 'MDL-70160-function-cache-310' of https://github.com/Peterburnett/moodle...
[moodle.git] / question / type / calculatedmulti / backup / moodle2 / restore_qtype_calculatedmulti_plugin.class.php
CommitLineData
41941110 1<?php
41941110
EL
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 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
22 */
a17b297d
TH
23
24
41941110
EL
25defined('MOODLE_INTERNAL') || die();
26
a17b297d 27
29b68914
TH
28require_once($CFG->dirroot .
29 '/question/type/calculated/backup/moodle2/restore_qtype_calculated_plugin.class.php');
41941110
EL
30
31/**
32 * restore plugin class that provides the necessary information
f7970e3c
TH
33 * needed to restore one calculatedmulti qtype plugin.
34 *
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
41941110
EL
37 */
38class restore_qtype_calculatedmulti_plugin extends restore_qtype_calculated_plugin {
39
5b64e326 40 public function recode_response($questionid, $sequencenumber, array $response) {
98a3898e
TH
41 return $this->step->questions_recode_response_data('multichoice',
42 $questionid, $sequencenumber, $response);
5b64e326
TH
43 }
44
41941110
EL
45 /**
46 * Given one question_states record, return the answer
47 * recoded pointing to all the restored stuff for calculatedmulti questions
48 *
49 * answer format is datasetxx-yy:zz, where xx is the itemnumber in the dataset
50 * (doesn't need conversion), and both yy and zz are two (hypen speparated)
51 * lists of comma separated question_answers, the first to specify the order
52 * of the answers and the second to specify the responses.
53 *
54 * in fact, this qtype behaves exactly like the multichoice one, so we'll delegate
55 * recoding of those yy:zz to it
56 */
18ab06ba 57 public function recode_legacy_state_answer($state) {
41941110
EL
58 $answer = $state->answer;
59 $result = '';
3d9645ae 60 // Datasetxx-yy:zz format.
41941110
EL
61 if (preg_match('~^dataset([0-9]+)-(.*)$~', $answer, $matches)) {
62 $itemid = $matches[1];
63 $subanswer = $matches[2];
3d9645ae 64 // Delegate subanswer recode to multichoice qtype, faking one question_states record.
41941110
EL
65 $substate = new stdClass();
66 $substate->answer = $subanswer;
18ab06ba 67 $newanswer = $this->step->restore_recode_legacy_answer($substate, 'multichoice');
41941110
EL
68 $result = 'dataset' . $itemid . '-' . $newanswer;
69 }
70 return $result ? $result : $answer;
71 }
72}