4 |
ariadna |
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 |
* Define all the backup steps that will be used by the backup_block_task
|
|
|
19 |
* @package block_point_view
|
|
|
20 |
* @copyright 2022 Astor Bizard, 2015 Stephen Bourget, 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
defined('MOODLE_INTERNAL') || die();
|
|
|
25 |
require_once(__DIR__ . '/restore_point_view_stepslib.php');
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Specialised restore task for the point_view block (using execute_after_tasks for recoding of target activity)
|
|
|
29 |
*
|
|
|
30 |
* @copyright 2022 Astor Bizard, 2015 Stephen Bourget, 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
|
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
32 |
*/
|
|
|
33 |
class restore_point_view_block_task extends restore_block_task {
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Define (add) particular settings that this block can have
|
|
|
37 |
*/
|
|
|
38 |
protected function define_my_settings() {
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Define (add) particular steps that this block can have
|
|
|
43 |
*/
|
|
|
44 |
protected function define_my_steps() {
|
|
|
45 |
$this->add_step( new restore_point_view_block_structure_step('point_view_structure', 'point_view.xml') );
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Define one array of fileareas that this block controls
|
|
|
50 |
*/
|
|
|
51 |
public function get_fileareas() {
|
|
|
52 |
return [ 'point_views_pix' ];
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* Define one array of configdata attributes that need to be decoded
|
|
|
57 |
*/
|
|
|
58 |
public function get_configdata_encoded_attributes() {
|
|
|
59 |
return []; // No special handling of configdata.
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* This function, executed after all the tasks in the plan have been executed,
|
|
|
64 |
* will perform the recode of the target activities for the block.
|
|
|
65 |
* This must be done here and not in normal execution steps because the activities can be restored after the block.
|
|
|
66 |
*/
|
|
|
67 |
public function after_restore() {
|
|
|
68 |
global $DB;
|
|
|
69 |
|
|
|
70 |
// Get the blockid.
|
|
|
71 |
$blockid = $this->get_blockid();
|
|
|
72 |
|
|
|
73 |
if ($configdata = $DB->get_field('block_instances', 'configdata', [ 'id' => $blockid ])) {
|
|
|
74 |
$config = unserialize(base64_decode($configdata));
|
|
|
75 |
|
|
|
76 |
if (!empty($config)) {
|
|
|
77 |
// Get the mapping and replace cmids in config.
|
|
|
78 |
$newconfig = clone($config);
|
|
|
79 |
foreach ($config as $key => $value) {
|
|
|
80 |
$match = null;
|
|
|
81 |
if (preg_match('/^(moduleselectm|difficulty_)(\d+)/', $key, $match)) {
|
|
|
82 |
$field = $match[1];
|
|
|
83 |
$cmid = $match[2];
|
|
|
84 |
$cmidmapping = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'course_module', $cmid);
|
|
|
85 |
unset($newconfig->{$field . $cmid});
|
|
|
86 |
if ($cmidmapping) {
|
|
|
87 |
$newconfig->{$field . $cmidmapping->newitemid} = $value;
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
// Copy reaction votes if user data is included.
|
|
|
93 |
if ($this->get_setting_value('users')) {
|
|
|
94 |
// Find restore step where some processing is done.
|
|
|
95 |
foreach ($this->get_steps() as $step) {
|
|
|
96 |
if ($step->get_name() == 'point_view_structure') {
|
|
|
97 |
$step->process_reactions_after_restore();
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
// Encode and save the config.
|
|
|
103 |
$configdata = base64_encode(serialize($newconfig));
|
|
|
104 |
$DB->set_field('block_instances', 'configdata', $configdata, [ 'id' => $blockid ]);
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* Define the contents in the block that must be processed by the link decoder
|
|
|
112 |
*/
|
|
|
113 |
public static function define_decode_contents() {
|
|
|
114 |
return [];
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* Define the decoding rules for links belonging to the block to be executed by the link decoder
|
|
|
119 |
*/
|
|
|
120 |
public static function define_decode_rules() {
|
|
|
121 |
return [];
|
|
|
122 |
}
|
|
|
123 |
}
|