MDL-53700 competency: Migrating settings to core
[moodle.git] / admin / tool / lp / backup / moodle2 / backup_tool_lp_plugin.class.php
CommitLineData
bb50f08d
FM
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.
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 * Backup file.
19 *
20 * @package tool_lp
21 * @copyright 2015 Frédéric Massart - FMCorz.net
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27require_once($CFG->dirroot . '/backup/moodle2/backup_tool_plugin.class.php');
28
29/**
30 * Backup class.
31 *
32 * @package tool_lp
33 * @copyright 2015 Frédéric Massart - FMCorz.net
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 */
36class backup_tool_lp_plugin extends backup_tool_plugin {
37
38 /**
39 * Define the plugin structure.
40 *
41 * @return backup_plugin_element
42 */
43 protected function define_course_plugin_structure() {
44 $plugin = $this->get_plugin_element(null, $this->get_include_condition(), 'include');
45
46 $pluginwrapper = new backup_nested_element($this->get_recommended_name());
47 $plugin->add_child($pluginwrapper);
48
49 $coursecompetencies = new backup_nested_element('course_competencies');
50 $pluginwrapper->add_child($coursecompetencies);
51
c2f55d29
DW
52 $coursecompetencysettings = new backup_nested_element('course_competency_settings',
53 array('id'), array('pushratingstouserplans'));
54
55 $pluginwrapper->add_child($coursecompetencysettings);
56
57 $sql = 'SELECT s.pushratingstouserplans
67bc0eaf 58 FROM {' . \core_competency\course_competency_settings::TABLE . '} s
c2f55d29
DW
59 WHERE s.courseid = :courseid';
60 $coursecompetencysettings->set_source_sql($sql, array('courseid' => backup::VAR_COURSEID));
61
62
bb50f08d
FM
63 $competency = new backup_nested_element('competency', null, array('idnumber', 'ruleoutcome',
64 'sortorder', 'frameworkidnumber'));
65 $coursecompetencies->add_child($competency);
66
67 $sql = 'SELECT c.idnumber, cc.ruleoutcome, cc.sortorder, f.idnumber AS frameworkidnumber
67bc0eaf
FM
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
bb50f08d
FM
71 WHERE cc.courseid = :courseid
72 ORDER BY cc.sortorder';
73 $competency->set_source_sql($sql, array('courseid' => backup::VAR_COURSEID));
74
75 return $plugin;
76 }
77
db650737
DW
78 /**
79 * Define the module plugin structure.
80 *
81 * @return backup_plugin_element
82 */
83 protected function define_module_plugin_structure() {
84 $plugin = $this->get_plugin_element(null, $this->get_include_condition(), 'include');
85
86 $pluginwrapper = new backup_nested_element($this->get_recommended_name());
87 $plugin->add_child($pluginwrapper);
88
89 $coursecompetencies = new backup_nested_element('course_module_competencies');
90 $pluginwrapper->add_child($coursecompetencies);
91
92 $competency = new backup_nested_element('competency', null, array('idnumber', 'ruleoutcome',
93 'sortorder', 'frameworkidnumber'));
94 $coursecompetencies->add_child($competency);
95
96 $sql = 'SELECT c.idnumber, cmc.ruleoutcome, cmc.sortorder, f.idnumber AS frameworkidnumber
67bc0eaf
FM
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
db650737
DW
100 WHERE cmc.cmid = :coursemoduleid
101 ORDER BY cmc.sortorder';
102 $competency->set_source_sql($sql, array('coursemoduleid' => backup::VAR_MODID));
103
104 return $plugin;
105 }
106
bb50f08d 107 /**
c2f55d29 108 * Returns a condition for whether we include this plugin in the backup or not.
bb50f08d
FM
109 *
110 * @return array
111 */
112 protected function get_include_condition() {
113 $result = '';
67bc0eaf 114 if (\core_competency\course_competency::record_exists_select('courseid = ?', array($this->task->get_courseid()))) {
bb50f08d
FM
115 $result = 'include';
116 };
117 return array('sqlparam' => $result);
118 }
119
120}