4 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
|
|
|
3 |
//
|
|
|
4 |
// VPL for 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 |
// VPL for 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Define restore structure for additional DB tables this block uses.
|
|
|
19 |
*
|
|
|
20 |
* @package block_point_view
|
|
|
21 |
* @copyright 2022 Astor Bizard
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Restore structure definition for point_view block.
|
|
|
27 |
*
|
|
|
28 |
* @copyright 2022 Astor Bizard
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class restore_point_view_block_structure_step extends restore_structure_step {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Reaction data to be added after restore, as it references modules that may not be restored yet.
|
|
|
35 |
* @var array
|
|
|
36 |
*/
|
|
|
37 |
protected $pendingdatainsertions = [];
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* {@inheritDoc}
|
|
|
41 |
* @see restore_structure_step::define_structure()
|
|
|
42 |
*/
|
|
|
43 |
protected function define_structure() {
|
|
|
44 |
$paths = [];
|
|
|
45 |
|
|
|
46 |
if ($this->get_setting_value('users')) {
|
|
|
47 |
$paths[] = new restore_path_element('reaction', '/block/point_view/reactions/reaction');
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
return $paths;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Process restore of a single reaction entry.
|
|
|
55 |
* @param mixed $data
|
|
|
56 |
*/
|
|
|
57 |
protected function process_reaction($data) {
|
|
|
58 |
// Postpone reaction votes process to be called in restore_point_view_block_task::after_restore()
|
|
|
59 |
// because modules may be restored after the block.
|
|
|
60 |
$this->pendingdatainsertions[] = (object) $data;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Actually process restore of all reactions entries that are pending.
|
|
|
65 |
* To be called only after restore of referenced modules.
|
|
|
66 |
*/
|
|
|
67 |
public function process_reactions_after_restore() {
|
|
|
68 |
global $DB;
|
|
|
69 |
foreach ($this->pendingdatainsertions as $data) {
|
|
|
70 |
$newcmid = $this->get_mappingid('course_module', $data->cmid);
|
|
|
71 |
$newcourseid = $this->get_mappingid('course', $data->courseid);
|
|
|
72 |
if ($newcmid && $newcourseid) {
|
|
|
73 |
$data->courseid = $newcourseid;
|
|
|
74 |
$data->cmid = $newcmid;
|
|
|
75 |
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
76 |
// Insert the reaction vote record.
|
|
|
77 |
$DB->insert_record('block_point_view', $data);
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
}
|