3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @subpackage backup-moodle2
21 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 defined('MOODLE_INTERNAL') || die();
27 * Provides the information to backup calculated questions
29 class backup_qtype_calculated_plugin extends backup_qtype_plugin {
31 protected function get_qtype_name() {
36 * Returns the qtype information to attach to question element
38 protected function define_question_plugin_structure() {
40 // Define the virtual plugin element with the condition to fulfill
41 $plugin = $this->get_plugin_element(null, '../../qtype', $this->get_qtype_name());
43 // Create one standard named plugin element (the visible container)
44 $pluginwrapper = new backup_nested_element($this->get_recommended_name());
46 // connect the visible container ASAP
47 $plugin->add_child($pluginwrapper);
49 // This qtype uses standard question_answers, add them here
50 // to the tree before any other information that will use them
51 $this->add_question_question_answers($pluginwrapper);
53 // This qtype uses standard numerical units, add them here
54 $this->add_question_numerical_units($pluginwrapper);
56 // This qtype uses standard numerical options, add them here
57 $this->add_question_numerical_options($pluginwrapper);
59 // This qtype uses standard datasets, add them here
60 $this->add_question_datasets($pluginwrapper);
62 // Now create the qtype own structures
63 $calculatedrecords = new backup_nested_element('calculated_records');
64 $calculatedrecord = new backup_nested_element('calculated_record', array('id'), array(
65 'answer', 'tolerance', 'tolerancetype', 'correctanswerlength',
66 'correctanswerformat'));
68 $calculatedoptions = new backup_nested_element('calculated_options');
69 $calculatedoption = new backup_nested_element('calculated_option', array('id'), array(
70 'synchronize', 'single', 'shuffleanswers', 'correctfeedback',
71 'correctfeedbackformat', 'partiallycorrectfeedback', 'partiallycorrectfeedbackformat', 'incorrectfeedback',
72 'incorrectfeedbackformat', 'answernumbering'));
74 // Now the own qtype tree
75 $pluginwrapper->add_child($calculatedrecords);
76 $calculatedrecords->add_child($calculatedrecord);
78 $pluginwrapper->add_child($calculatedoptions);
79 $calculatedoptions->add_child($calculatedoption);
81 // set source to populate the data
82 $calculatedrecord->set_source_table('question_calculated', array('question' => backup::VAR_PARENTID));
83 $calculatedoption->set_source_table('question_calculated_options', array('question' => backup::VAR_PARENTID));
85 // don't need to annotate ids nor files