1 |
efrain |
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 |
* Rate course block backup
|
|
|
19 |
*
|
|
|
20 |
* @package blocks
|
|
|
21 |
* @subpackage rate_course
|
|
|
22 |
* @copyright 2012 Open University
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Define the complete structure for the backup, with file and id annotations
|
|
|
28 |
*/
|
|
|
29 |
class restore_rate_course_block_structure_step extends restore_structure_step {
|
|
|
30 |
|
|
|
31 |
protected function define_structure() {
|
|
|
32 |
$paths = array();
|
|
|
33 |
|
|
|
34 |
$paths[] = new restore_path_element('block', '/block/rate_course/items');
|
|
|
35 |
$paths[] = new restore_path_element('item', '/block/rate_course/items/item');
|
|
|
36 |
|
|
|
37 |
return $paths;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public function process_block($data) {
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public function process_item($item) {
|
|
|
44 |
global $DB;
|
|
|
45 |
|
|
|
46 |
$item['course'] = $this->task->get_courseid();
|
|
|
47 |
$item['userid'] = $this->task->get_userid();
|
|
|
48 |
|
|
|
49 |
$params = $item;
|
|
|
50 |
unset($params['id']);
|
|
|
51 |
|
|
|
52 |
$sql = 'SELECT id FROM {block_rate_course}
|
|
|
53 |
WHERE course = :course
|
|
|
54 |
AND userid = :userid
|
|
|
55 |
';
|
|
|
56 |
|
|
|
57 |
if ($existing = $DB->get_record_sql($sql, $params)) {
|
|
|
58 |
$params['id'] = $existing->id;
|
|
|
59 |
$DB->update_record('block_rate_course', $params);
|
|
|
60 |
} else {
|
|
|
61 |
$DB->insert_record('block_rate_course', $params);
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
}
|