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 - https://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 <https://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Define all the backup steps that will be used by the backup_stickynotes_activity_task.
19
 *
20
 * @package     mod_stickynotes
21
 * @copyright   2021 Olivier VALENTIN
22
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
/**
28
 * Define the complete stickynotes structure for backup, with file and id annotations
29
 *
30
 * @package     mod_stickynotes
31
 * @copyright   2021 Olivier VALENTIN
32
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class backup_stickynotes_activity_structure_step extends backup_activity_structure_step {
35
 
36
    /**
37
     * Defines the backup structure of the module
38
     *
39
     * @return backup_nested_element
40
     */
41
    protected function define_structure() {
42
 
43
        // To know if we are including userinfo.
44
        $userinfo = $this->get_setting_value('userinfo');
45
 
46
        // Define the root element describing the stickynotes instance.
47
        $stickynotes = new backup_nested_element('stickynotes', array('id'),
48
                                              array('course',
49
                                                    'name',
50
                                                    'intro',
51
                                                    'introformat',
52
                                                    'colors',
53
                                                    'votes',
54
                                                    'limitvotes',
55
                                                    'maxlimitvotes',
56
                                                    'limitstickynotes',
57
                                                    'maxstickynotes',
58
                                                    'orderstickynotes',
59
                                                    'viewauthor',
60
                                                    'rotate',
61
                                                    'color1',
62
                                                    'color1_meaning',
63
                                                    'color2',
64
                                                    'color2_meaning',
65
                                                    'color3',
66
                                                    'color3_meaning',
67
                                                    'color4',
68
                                                    'color4_meaning',
69
                                                    'color5',
70
                                                    'color5_meaning',
71
                                                    'color6',
72
                                                    'color6_meaning',
73
                                                    'timecreated',
74
                                                    'timemodified',
75
                                                    'displaystickycaption',
76
                                                    'moveallnotes',
77
                                                    'seeallnotes',
78
                                                    'completionstickynotes'));
79
 
80
        // Define each element separated.
81
        $stickynotescolumns = new backup_nested_element('stickynotescolumns');
82
        $stickynotescolumn = new backup_nested_element('stickynotescolumn', array('id'),
83
                                                            array('title',
84
                                                            'column_order'));
85
 
86
        $stickynotesnotes = new backup_nested_element('stickynotesnotes');
87
        $stickynotesnote = new backup_nested_element('stickynotesnote', array('id'),
88
                                                        array('userid',
89
                                                            'stickycolid',
90
                                                            'message',
91
                                                            'color',
92
                                                            'timecreated',
93
                                                            'timemodified'));
94
        $stickynotesvotes = new backup_nested_element('stickynotesvotes');
95
        $stickynotesvote = new backup_nested_element('stickynotesvote', array('id'),
96
                                                        array('userid',
97
                                                            'stickynoteid',
98
                                                            'vote',
99
                                                            'timecreated'));
100
        // Build the tree.
101
        $stickynotes->add_child($stickynotescolumns);
102
        $stickynotescolumns->add_child($stickynotescolumn);
103
 
104
        $stickynotescolumn->add_child($stickynotesnotes);
105
        $stickynotesnotes->add_child($stickynotesnote);
106
 
107
        $stickynotesnote->add_child($stickynotesvotes);
108
        $stickynotesvotes->add_child($stickynotesvote);
109
 
110
        $stickynotes->set_source_table('stickynotes', array('id' => backup::VAR_ACTIVITYID));
111
 
112
        $stickynotescolumn->set_source_sql('
113
                SELECT *
114
                FROM {stickynotes_column}
115
                WHERE stickyid = ?',
116
            array(backup::VAR_PARENTID));
117
        $stickynotesnote->set_source_sql('
118
                SELECT *
119
                FROM {stickynotes_note}
120
                WHERE stickyid = ?',
121
            array(backup::VAR_PARENTID));
122
        $stickynotescolumn->set_source_table('stickynotes_column', array('stickyid' => backup::VAR_ACTIVITYID));
123
 
124
        // All the rest of elements only happen if we are including user info.
125
        if ($this->get_task()->get_setting_value('userinfo')) {
126
            // All the rest of elements only happen if we are including user info.
127
            $stickynotesnote->set_source_table('stickynotes_note', array('stickycolid' => backup::VAR_PARENTID));
128
            $stickynotesvote->set_source_table('stickynotes_vote', array('stickynoteid' => backup::VAR_PARENTID));
129
        }
130
 
131
        // Define id annotations.
132
        $stickynotesnote->annotate_ids('user', 'userid');
133
        $stickynotesvote->annotate_ids('user', 'userid');
134
 
135
        // Define file annotations.
136
        $stickynotes->annotate_files('mod_stickynotes', 'intro', null); // This file areas haven't itemid.
137
 
138
        // Return the root element (stickynotes), wrapped into standard activity structure.
139
        return $this->prepare_activity_structure($stickynotes);
140
    }
141
}