2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
21 * @copyright 2015 Frédéric Massart - FMCorz.net
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->dirroot . '/backup/moodle2/backup_tool_plugin.class.php');
33 * @copyright 2015 Frédéric Massart - FMCorz.net
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class backup_tool_lp_plugin extends backup_tool_plugin {
39 * Define the plugin structure.
41 * @return backup_plugin_element
43 protected function define_course_plugin_structure() {
44 $plugin = $this->get_plugin_element(null, $this->get_include_condition(), 'include');
46 $pluginwrapper = new backup_nested_element($this->get_recommended_name());
47 $plugin->add_child($pluginwrapper);
49 $coursecompetencies = new backup_nested_element('course_competencies');
50 $pluginwrapper->add_child($coursecompetencies);
52 $coursecompetencysettings = new backup_nested_element('course_competency_settings',
53 array('id'), array('pushratingstouserplans'));
55 $pluginwrapper->add_child($coursecompetencysettings);
57 $sql = 'SELECT s.pushratingstouserplans
58 FROM {' . \core_competency\course_competency_settings::TABLE . '} s
59 WHERE s.courseid = :courseid';
60 $coursecompetencysettings->set_source_sql($sql, array('courseid' => backup::VAR_COURSEID));
63 $competency = new backup_nested_element('competency', null, array('idnumber', 'ruleoutcome',
64 'sortorder', 'frameworkidnumber'));
65 $coursecompetencies->add_child($competency);
67 $sql = 'SELECT c.idnumber, cc.ruleoutcome, cc.sortorder, f.idnumber AS frameworkidnumber
68 FROM {' . \core_competency\course_competency::TABLE . '} cc
69 JOIN {' . \core_competency\competency::TABLE . '} c ON c.id = cc.competencyid
70 JOIN {' . \core_competency\competency_framework::TABLE . '} f ON f.id = c.competencyframeworkid
71 WHERE cc.courseid = :courseid
72 ORDER BY cc.sortorder';
73 $competency->set_source_sql($sql, array('courseid' => backup::VAR_COURSEID));
79 * Define the module plugin structure.
81 * @return backup_plugin_element
83 protected function define_module_plugin_structure() {
84 $plugin = $this->get_plugin_element(null, $this->get_include_condition(), 'include');
86 $pluginwrapper = new backup_nested_element($this->get_recommended_name());
87 $plugin->add_child($pluginwrapper);
89 $coursecompetencies = new backup_nested_element('course_module_competencies');
90 $pluginwrapper->add_child($coursecompetencies);
92 $competency = new backup_nested_element('competency', null, array('idnumber', 'ruleoutcome',
93 'sortorder', 'frameworkidnumber'));
94 $coursecompetencies->add_child($competency);
96 $sql = 'SELECT c.idnumber, cmc.ruleoutcome, cmc.sortorder, f.idnumber AS frameworkidnumber
97 FROM {' . \core_competency\course_module_competency::TABLE . '} cmc
98 JOIN {' . \core_competency\competency::TABLE . '} c ON c.id = cmc.competencyid
99 JOIN {' . \core_competency\competency_framework::TABLE . '} f ON f.id = c.competencyframeworkid
100 WHERE cmc.cmid = :coursemoduleid
101 ORDER BY cmc.sortorder';
102 $competency->set_source_sql($sql, array('coursemoduleid' => backup::VAR_MODID));
108 * Returns a condition for whether we include this plugin in the backup or not.
112 protected function get_include_condition() {
114 if (\core_competency\course_competency::record_exists_select('courseid = ?', array($this->task->get_courseid()))) {
117 return array('sqlparam' => $result);