Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * unilabel module.
19
 *
20
 * @package     mod_unilabel
21
 * @author      Andreas Grabs <info@grabs-edv.de>
22
 * @copyright   2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
defined('MOODLE_INTERNAL') || die;
26
 
27
require_once($CFG->dirroot . '/mod/unilabel/backup/moodle2/restore_unilabel_stepslib.php'); // Because it exists (must).
28
 
29
/**
30
 * Unilabel restore task class.
31
 *
32
 * This class provides all the settings and steps to perform one complete restore of the activity
33
 * @package     mod_unilabel
34
 * @author      Andreas Grabs <info@grabs-edv.de>
35
 * @copyright   2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
36
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class restore_unilabel_activity_task extends restore_activity_task {
39
    /**
40
     * Define (add) particular settings this activity can have.
41
     */
42
    protected function define_my_settings() {
43
        // No particular settings for this activity.
44
    }
45
 
46
    /**
47
     * Define (add) particular steps this activity can have.
48
     */
49
    protected function define_my_steps() {
50
        // Unilabel only has one structure step.
51
        $this->add_step(new restore_unilabel_activity_structure_step('unilabel_structure', 'unilabel.xml'));
52
    }
53
 
54
    /**
55
     * Define the contents in the activity that must be
56
     * processed by the link decoder.
57
     */
58
    public static function define_decode_contents() {
59
        $contents = [];
60
 
61
        $contents[] = new restore_decode_content('unilabel', ['intro'], 'unilabel');
62
 
63
        // Go through all subplugins and add their settings pages.
64
        $plugins = \core_component::get_plugin_list_with_file('unilabeltype', 'settings.php', false);
65
        foreach ($plugins as $plugin => $settingspath) {
66
            $restorescript = dirname($settingspath) . '/backup/moodle2/restore_unilabeltype_' . $plugin . '_subplugin.class.php';
67
            if (is_file($restorescript)) {
68
                require_once($restorescript);
69
            }
70
            $classname = 'restore_unilabeltype_' . $plugin . '_subplugin';
71
            if (method_exists($classname, 'define_decode_contents')) {
72
                $contents = array_merge($contents, $classname::define_decode_contents());
73
            }
74
        }
75
 
76
        return $contents;
77
    }
78
 
79
    /**
80
     * Define the decoding rules for links belonging
81
     * to the activity to be executed by the link decoder.
82
     */
83
    public static function define_decode_rules() {
84
        return [];
85
    }
86
 
87
    /**
88
     * Define the restore log rules that will be applied
89
     * by the {@see restore_logs_processor} when restoring
90
     * unilabel logs. It must return one array
91
     * of {@see restore_log_rule} objects.
92
     */
93
    public static function define_restore_log_rules() {
94
        $rules = [];
95
 
96
        $rules[] = new restore_log_rule('unilabel', 'add', 'view.php?id={course_module}', '{unilabel}');
97
        $rules[] = new restore_log_rule('unilabel', 'update', 'view.php?id={course_module}', '{unilabel}');
98
        $rules[] = new restore_log_rule('unilabel', 'view', 'view.php?id={course_module}', '{unilabel}');
99
 
100
        return $rules;
101
    }
102
 
103
    /**
104
     * Define the restore log rules that will be applied
105
     * by the {@see restore_logs_processor} when restoring
106
     * course logs. It must return one array
107
     * of {@see restore_log_rule} objects.
108
     *
109
     * Note this rules are applied when restoring course logs
110
     * by the restore final task, but are defined here at
111
     * activity level. All them are rules not linked to any module instance (cmid = 0)
112
     */
113
    public static function define_restore_log_rules_for_course() {
114
        $rules = [];
115
 
116
        $rules[] = new restore_log_rule('unilabel', 'view all', 'index.php?id={course}', null);
117
 
118
        return $rules;
119
    }
120
 
121
    /**
122
     * After restore is done, rebuild the course cache.
123
     *
124
     * @return void
125
     */
126
    public function after_restore() {
127
        $course = get_course($this->get_courseid());
128
        \course_modinfo::build_course_cache($course);
129
    }
130
}