1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of the customcert module for 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 |
* Define all the restore steps that will be used by the restore_customcert_activity_task.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_customcert
|
|
|
21 |
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Define the complete customcert structure for restore, with file and id annotations.
|
|
|
27 |
*
|
|
|
28 |
* @package mod_customcert
|
|
|
29 |
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class restore_customcert_activity_structure_step extends restore_activity_structure_step {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Define the different items to restore.
|
|
|
36 |
*
|
|
|
37 |
* @return array the restore paths
|
|
|
38 |
*/
|
|
|
39 |
protected function define_structure() {
|
|
|
40 |
// The array used to store the path to the items we want to restore.
|
|
|
41 |
$paths = [];
|
|
|
42 |
|
|
|
43 |
// The customcert instance.
|
|
|
44 |
$paths[] = new restore_path_element('customcert', '/activity/customcert');
|
|
|
45 |
|
|
|
46 |
// The templates.
|
|
|
47 |
$paths[] = new restore_path_element('customcert_template', '/activity/customcert/template');
|
|
|
48 |
|
|
|
49 |
// The pages.
|
|
|
50 |
$paths[] = new restore_path_element('customcert_page', '/activity/customcert/template/pages/page');
|
|
|
51 |
|
|
|
52 |
// The elements.
|
|
|
53 |
$paths[] = new restore_path_element('customcert_element', '/activity/customcert/template/pages/page/element');
|
|
|
54 |
|
|
|
55 |
// Check if we want the issues as well.
|
|
|
56 |
if ($this->get_setting_value('userinfo')) {
|
|
|
57 |
$paths[] = new restore_path_element('customcert_issue', '/activity/customcert/issues/issue');
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
// Return the paths wrapped into standard activity structure.
|
|
|
61 |
return $this->prepare_activity_structure($paths);
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Handles restoring the customcert activity.
|
|
|
66 |
*
|
|
|
67 |
* @param stdClass $data the customcert data
|
|
|
68 |
*/
|
|
|
69 |
protected function process_customcert($data) {
|
|
|
70 |
global $DB;
|
|
|
71 |
|
|
|
72 |
$data = (object) $data;
|
|
|
73 |
$data->course = $this->get_courseid();
|
|
|
74 |
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
|
75 |
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
|
76 |
|
|
|
77 |
// Insert the customcert record.
|
|
|
78 |
$newitemid = $DB->insert_record('customcert', $data);
|
|
|
79 |
|
|
|
80 |
// Immediately after inserting record call this.
|
|
|
81 |
$this->apply_activity_instance($newitemid);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Handles restoring a customcert page.
|
|
|
86 |
*
|
|
|
87 |
* @param stdClass $data the customcert data
|
|
|
88 |
*/
|
|
|
89 |
protected function process_customcert_template($data) {
|
|
|
90 |
global $DB;
|
|
|
91 |
|
|
|
92 |
$data = (object) $data;
|
|
|
93 |
$oldid = $data->id;
|
|
|
94 |
|
|
|
95 |
$data->contextid = $this->task->get_contextid();
|
|
|
96 |
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
|
97 |
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
|
98 |
|
|
|
99 |
$newitemid = $DB->insert_record('customcert_templates', $data);
|
|
|
100 |
$this->set_mapping('customcert_template', $oldid, $newitemid);
|
|
|
101 |
|
|
|
102 |
// Update the template id for the customcert.
|
|
|
103 |
$customcert = new stdClass();
|
|
|
104 |
$customcert->id = $this->get_new_parentid('customcert');
|
|
|
105 |
$customcert->templateid = $newitemid;
|
|
|
106 |
$DB->update_record('customcert', $customcert);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Handles restoring a customcert template.
|
|
|
111 |
*
|
|
|
112 |
* @param stdClass $data the customcert data
|
|
|
113 |
*/
|
|
|
114 |
protected function process_customcert_page($data) {
|
|
|
115 |
global $DB;
|
|
|
116 |
|
|
|
117 |
$data = (object) $data;
|
|
|
118 |
$oldid = $data->id;
|
|
|
119 |
|
|
|
120 |
$data->templateid = $this->get_new_parentid('customcert_template');
|
|
|
121 |
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
|
122 |
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
|
123 |
|
|
|
124 |
$newitemid = $DB->insert_record('customcert_pages', $data);
|
|
|
125 |
$this->set_mapping('customcert_page', $oldid, $newitemid);
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* Handles restoring a customcert element.
|
|
|
130 |
*
|
|
|
131 |
* @param stdclass $data the customcert data
|
|
|
132 |
*/
|
|
|
133 |
protected function process_customcert_element($data) {
|
|
|
134 |
global $DB;
|
|
|
135 |
|
|
|
136 |
$data = (object) $data;
|
|
|
137 |
$oldid = $data->id;
|
|
|
138 |
|
|
|
139 |
$data->pageid = $this->get_new_parentid('customcert_page');
|
|
|
140 |
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
|
141 |
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
|
142 |
|
|
|
143 |
$newitemid = $DB->insert_record('customcert_elements', $data);
|
|
|
144 |
$this->set_mapping('customcert_element', $oldid, $newitemid);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
/**
|
|
|
148 |
* Handles restoring a customcert issue.
|
|
|
149 |
*
|
|
|
150 |
* @param stdClass $data the customcert data
|
|
|
151 |
*/
|
|
|
152 |
protected function process_customcert_issue($data) {
|
|
|
153 |
global $DB;
|
|
|
154 |
|
|
|
155 |
$data = (object) $data;
|
|
|
156 |
$oldid = $data->id;
|
|
|
157 |
|
|
|
158 |
$data->customcertid = $this->get_new_parentid('customcert');
|
|
|
159 |
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
|
160 |
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
161 |
|
|
|
162 |
$newitemid = $DB->insert_record('customcert_issues', $data);
|
|
|
163 |
$this->set_mapping('customcert_issue', $oldid, $newitemid);
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
/**
|
|
|
167 |
* Called immediately after all the other restore functions.
|
|
|
168 |
*/
|
|
|
169 |
protected function after_execute() {
|
|
|
170 |
parent::after_execute();
|
|
|
171 |
|
|
|
172 |
// Add the files.
|
|
|
173 |
$this->add_related_files('mod_customcert', 'intro', null);
|
|
|
174 |
|
|
|
175 |
// Note - we can't use get_old_contextid() as it refers to the module context.
|
|
|
176 |
$this->add_related_files('mod_customcert', 'image', null, $this->get_task()->get_info()->original_course_contextid);
|
|
|
177 |
}
|
|
|
178 |
}
|