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
 * All the steps to restore mod_h5pactivity are defined here.
19
 *
20
 * @package     mod_h5pactivity
21
 * @copyright   2020 Ferran Recio <ferran@moodle.com>
22
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
/**
28
 * Defines the structure step to restore one mod_h5pactivity activity.
29
 */
30
class restore_h5pactivity_activity_structure_step extends restore_activity_structure_step {
31
 
32
    /**
33
     * Defines the structure to be restored.
34
     *
35
     * @return restore_path_element[].
36
     */
37
    protected function define_structure(): array {
38
        $paths = [];
39
        $userinfo = $this->get_setting_value('userinfo');
40
        $paths[] = new restore_path_element('h5pactivity', '/activity/h5pactivity');
41
        if ($userinfo) {
42
            $paths[] = new restore_path_element('h5pactivity_attempt', '/activity/h5pactivity/attempts/attempt');
43
            $paths[] = new restore_path_element('h5pactivity_attempt_result', '/activity/h5pactivity/attempts/attempt/results/result');
44
        }
45
        return $this->prepare_activity_structure($paths);
46
    }
47
 
48
    /**
49
     * Processes the h5pactivity restore data.
50
     *
51
     * @param array $data Parsed element data.
52
     */
53
    protected function process_h5pactivity(array $data): void {
54
        global $DB;
55
        $data = (object)$data;
56
        $data->course = $this->get_courseid();
57
        // Insert the record.
58
        $newitemid = $DB->insert_record('h5pactivity', $data);
59
        // Immediately after inserting "activity" record, call this.
60
        $this->apply_activity_instance($newitemid);
61
    }
62
 
63
    /**
64
     * Processes the h5pactivity_attempts restore data.
65
     *
66
     * @param array $data Parsed element data.
67
     */
68
    protected function process_h5pactivity_attempt(array $data): void {
69
        global $DB;
70
        $data = (object)$data;
71
 
72
        $oldid = $data->id;
73
        $data->h5pactivityid = $this->get_new_parentid('h5pactivity');
74
        $data->userid = $this->get_mappingid('user', $data->userid);
75
 
76
        $newitemid = $DB->insert_record('h5pactivity_attempts', $data);
77
        $this->set_mapping('h5pactivity_attempt', $oldid, $newitemid);
78
    }
79
 
80
    /**
81
     * Processes the h5pactivity_attempts_results restore data.
82
     *
83
     * @param array $data Parsed element data.
84
     */
85
    protected function process_h5pactivity_attempt_result(array $data): void {
86
        global $DB;
87
        $data = (object)$data;
88
 
89
        $oldid = $data->id;
90
        $data->attemptid = $this->get_new_parentid('h5pactivity_attempt');
91
 
92
        $newitemid = $DB->insert_record('h5pactivity_attempts_results', $data);
93
        $this->set_mapping('h5pactivity_attempt_result', $oldid, $newitemid);
94
    }
95
 
96
    /**
97
     * Defines post-execution actions.
98
     */
99
    protected function after_execute(): void {
100
        // Add related files, no need to match by itemname (just internally handled context).
101
        $this->add_related_files('mod_h5pactivity', 'intro', null);
102
        $this->add_related_files('mod_h5pactivity', 'package', null);
103
    }
104
}