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
 * @package    mod_feedback
19
 * @subpackage backup-moodle2
20
 * @copyright 2010 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
/**
25
 * Define all the restore steps that will be used by the restore_feedback_activity_task
26
 */
27
 
28
/**
29
 * Structure step to restore one feedback activity
30
 */
31
class restore_feedback_activity_structure_step extends restore_activity_structure_step {
32
 
33
    protected function define_structure() {
34
 
35
        $paths = array();
36
        $userinfo = $this->get_setting_value('userinfo');
37
 
38
        $paths[] = new restore_path_element('feedback', '/activity/feedback');
39
        $paths[] = new restore_path_element('feedback_item', '/activity/feedback/items/item');
40
        if ($userinfo) {
41
            $paths[] = new restore_path_element('feedback_completed', '/activity/feedback/completeds/completed');
42
            $paths[] = new restore_path_element('feedback_value', '/activity/feedback/completeds/completed/values/value');
43
        }
44
 
45
        // Return the paths wrapped into standard activity structure
46
        return $this->prepare_activity_structure($paths);
47
    }
48
 
49
    protected function process_feedback($data) {
50
        global $DB;
51
 
52
        $data = (object)$data;
53
        $oldid = $data->id;
54
        $data->course = $this->get_courseid();
55
 
56
        // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
57
        // See MDL-9367.
58
        $data->timeopen = $this->apply_date_offset($data->timeopen);
59
        $data->timeclose = $this->apply_date_offset($data->timeclose);
60
 
61
        // insert the feedback record
62
        $newitemid = $DB->insert_record('feedback', $data);
63
        // immediately after inserting "activity" record, call this
64
        $this->apply_activity_instance($newitemid);
65
    }
66
 
67
    protected function process_feedback_item($data) {
68
        global $DB;
69
 
70
        $data = (object)$data;
71
        $oldid = $data->id;
72
        $data->feedback = $this->get_new_parentid('feedback');
73
        $data->typ = clean_param($data->typ, PARAM_ALPHA);
74
 
75
        $newitemid = $DB->insert_record('feedback_item', $data);
76
        $this->set_mapping('feedback_item', $oldid, $newitemid, true); // Can have files
77
    }
78
 
79
    protected function process_feedback_completed($data) {
80
        global $DB;
81
 
82
        $data = (object)$data;
83
        $oldid = $data->id;
84
        $data->feedback = $this->get_new_parentid('feedback');
85
        $data->userid = $this->get_mappingid('user', $data->userid);
86
        if ($this->task->is_samesite() && !empty($data->courseid)) {
87
            $data->courseid = $data->courseid;
88
        } else if ($this->get_courseid() == SITEID) {
89
            $data->courseid = SITEID;
90
        } else {
91
            $data->courseid = 0;
92
        }
93
 
94
        $newitemid = $DB->insert_record('feedback_completed', $data);
95
        $this->set_mapping('feedback_completed', $oldid, $newitemid);
96
    }
97
 
98
    protected function process_feedback_value($data) {
99
        global $DB;
100
 
101
        $data = (object)$data;
102
        $oldid = $data->id;
103
        $data->completed = $this->get_new_parentid('feedback_completed');
104
        $data->item = $this->get_mappingid('feedback_item', $data->item);
105
        if ($this->task->is_samesite() && !empty($data->course_id)) {
106
            $data->course_id = $data->course_id;
107
        } else if ($this->get_courseid() == SITEID) {
108
            $data->course_id = SITEID;
109
        } else {
110
            $data->course_id = 0;
111
        }
112
 
113
        $newitemid = $DB->insert_record('feedback_value', $data);
114
        $this->set_mapping('feedback_value', $oldid, $newitemid);
115
    }
116
 
117
    protected function after_execute() {
118
        global $DB;
119
        // Add feedback related files, no need to match by itemname (just internally handled context)
120
        $this->add_related_files('mod_feedback', 'intro', null);
121
        $this->add_related_files('mod_feedback', 'page_after_submit', null);
122
        $this->add_related_files('mod_feedback', 'item', 'feedback_item');
123
 
124
        // Once all items are restored we can set their dependency.
125
        if ($records = $DB->get_records('feedback_item', array('feedback' => $this->task->get_activityid()))) {
126
            foreach ($records as $record) {
127
                // Get new id for dependitem if present. This will also reset dependitem if not found.
128
                $record->dependitem = $this->get_mappingid('feedback_item', $record->dependitem);
129
                $DB->update_record('feedback_item', $record);
130
            }
131
        }
132
    }
133
}