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/restore_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 restore_tool_lp_plugin extends restore_tool_plugin {
41 * @return restore_path_element[]
43 protected function define_course_plugin_structure() {
45 new restore_path_element('course_competency', $this->get_pathfor('/course_competencies/competency')),
46 new restore_path_element('course_competency_settings', $this->get_pathfor('/course_competency_settings'))
54 * @return restore_path_element[]
56 protected function define_module_plugin_structure() {
58 new restore_path_element('course_module_competency', $this->get_pathfor('/course_module_competencies/competency'))
64 * Process a course competency settings.
66 * @param array $data The data.
68 public function process_course_competency_settings($data) {
71 $data = (object) $data;
72 $courseid = $this->task->get_courseid();
73 $exists = \core_competency\course_competency_settings::get_record(array('courseid' => $courseid));
75 // Now update or insert.
78 $settings->set_pushratingstouserplans($data->pushratingstouserplans);
79 return $settings->update();
81 $data = (object) array('courseid' => $courseid, 'pushratingstouserplans' => $data->pushratingstouserplans);
82 $settings = new \core_competency\course_competency_settings(0, $data);
83 return !empty($settings->create());
88 * Process a course competency.
90 * @param array $data The data.
92 public function process_course_competency($data) {
93 $data = (object) $data;
95 // Mapping the competency by ID numbers.
96 $framework = \core_competency\competency_framework::get_record(array('idnumber' => $data->frameworkidnumber));
100 $competency = \core_competency\competency::get_record(array('idnumber' => $data->idnumber,
101 'competencyframeworkid' => $framework->get_id()));
107 'competencyid' => $competency->get_id(),
108 'courseid' => $this->task->get_courseid()
110 $query = 'competencyid = :competencyid AND courseid = :courseid';
111 $existing = \core_competency\course_competency::record_exists_select($query, $params);
114 // Sortorder is ignored by precaution, anyway we should walk through the records in the right order.
115 $record = (object) $params;
116 $record->ruleoutcome = $data->ruleoutcome;
117 $coursecompetency = new \core_competency\course_competency(0, $record);
118 $coursecompetency->create();
124 * Process a course module competency.
126 * @param array $data The data.
128 public function process_course_module_competency($data) {
129 $data = (object) $data;
131 // Mapping the competency by ID numbers.
132 $framework = \core_competency\competency_framework::get_record(array('idnumber' => $data->frameworkidnumber));
136 $competency = \core_competency\competency::get_record(array('idnumber' => $data->idnumber,
137 'competencyframeworkid' => $framework->get_id()));
143 'competencyid' => $competency->get_id(),
144 'cmid' => $this->task->get_moduleid()
146 $query = 'competencyid = :competencyid AND cmid = :cmid';
147 $existing = \core_competency\course_module_competency::record_exists_select($query, $params);
150 // Sortorder is ignored by precaution, anyway we should walk through the records in the right order.
151 $record = (object) $params;
152 $record->ruleoutcome = $data->ruleoutcome;
153 $coursemodulecompetency = new \core_competency\course_module_competency(0, $record);
154 $coursemodulecompetency->create();