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 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
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
26
 
27
require_once($CFG->dirroot . '/mod/customcert/backup/moodle2/restore_customcert_stepslib.php');
28
 
29
/**
30
 * The class definition for assigning tasks that provide the settings and steps to perform a restore of the activity.
31
 *
32
 * @package    mod_customcert
33
 * @copyright  2013 Mark Nelson <markn@moodle.com>
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class restore_customcert_activity_task extends restore_activity_task {
37
 
38
    /**
39
     * Define  particular settings this activity can have.
40
     */
41
    protected function define_my_settings() {
42
        // No particular settings for this activity.
43
    }
44
 
45
    /**
46
     * Define particular steps this activity can have.
47
     */
48
    protected function define_my_steps() {
49
        // The customcert only has one structure step.
50
        $this->add_step(new restore_customcert_activity_structure_step('customcert_structure', 'customcert.xml'));
51
    }
52
 
53
    /**
54
     * Define the contents in the activity that must be processed by the link decoder.
55
     */
56
    public static function define_decode_contents() {
57
        $contents = [];
58
 
59
        $contents[] = new restore_decode_content('customcert', ['intro'], 'customcert');
60
 
61
        return $contents;
62
    }
63
 
64
    /**
65
     * Define the decoding rules for links belonging to the activity to be executed by the link decoder.
66
     */
67
    public static function define_decode_rules() {
68
        $rules = [];
69
 
70
        $rules[] = new restore_decode_rule('CUSTOMCERTVIEWBYID', '/mod/customcert/view.php?id=$1', 'course_module');
71
        $rules[] = new restore_decode_rule('CUSTOMCERTINDEX', '/mod/customcert/index.php?id=$1', 'course');
72
 
73
        return $rules;
74
 
75
    }
76
 
77
    /**
78
     * Define the restore log rules that will be applied by the {@see restore_logs_processor} when restoring
79
     * customcert logs. It must return one array of {@see restore_log_rule} objects.
80
     *
81
     * @return array the restore log rules
82
     */
83
    public static function define_restore_log_rules() {
84
        $rules = [];
85
 
86
        $rules[] = new restore_log_rule('customcert', 'add', 'view.php?id={course_module}', '{customcert}');
87
        $rules[] = new restore_log_rule('customcert', 'update', 'view.php?id={course_module}', '{customcert}');
88
        $rules[] = new restore_log_rule('customcert', 'view', 'view.php?id={course_module}', '{customcert}');
89
        $rules[] = new restore_log_rule('customcert', 'received', 'view.php?id={course_module}', '{customcert}');
90
        $rules[] = new restore_log_rule('customcert', 'view report', 'view.php?id={course_module}', '{customcert}');
91
 
92
        return $rules;
93
    }
94
 
95
    /**
96
     * This function is called after all the activities in the backup have been restored. This allows us to get
97
     * the new course module ids, as they may have been restored after the customcert module, meaning no id
98
     * was available at the time.
99
     */
100
    public function after_restore() {
101
        global $DB;
102
 
103
        // Get the customcert elements.
104
        $sql = "SELECT e.*
105
                  FROM {customcert_elements} e
106
            INNER JOIN {customcert_pages} p
107
                    ON e.pageid = p.id
108
            INNER JOIN {customcert} c
109
                    ON p.templateid = c.templateid
110
                 WHERE c.id = :customcertid";
111
        if ($elements = $DB->get_records_sql($sql, ['customcertid' => $this->get_activityid()])) {
112
            // Go through the elements for the certificate.
113
            foreach ($elements as $e) {
114
                // Get an instance of the element class.
115
                if ($e = \mod_customcert\element_factory::get_element_instance($e)) {
116
                    $e->after_restore($this);
117
                }
118
            }
119
        }
120
    }
121
}