1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of the Zoom plugin 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_zoom_activity_task
|
|
|
19 |
*
|
|
|
20 |
* @package mod_zoom
|
|
|
21 |
* @category backup
|
|
|
22 |
* @copyright 2015 UC Regents
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace mod_zoom;
|
|
|
27 |
|
|
|
28 |
defined('MOODLE_INTERNAL') || die();
|
|
|
29 |
|
|
|
30 |
require_once($CFG->dirroot . '/mod/zoom/locallib.php');
|
|
|
31 |
|
|
|
32 |
use moodle_exception;
|
|
|
33 |
use restore_path_element;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Structure step to restore one zoom activity
|
|
|
37 |
*/
|
|
|
38 |
class restore_activity_structure_step extends \restore_activity_structure_step {
|
|
|
39 |
/**
|
|
|
40 |
* Defines structure of path elements to be processed during the restore
|
|
|
41 |
*
|
|
|
42 |
* @return array of restore_path_element
|
|
|
43 |
*/
|
|
|
44 |
protected function define_structure() {
|
|
|
45 |
$paths = [];
|
|
|
46 |
$paths[] = new restore_path_element('zoom', '/activity/zoom');
|
|
|
47 |
$paths[] = new restore_path_element('zoom_tracking_field', '/activity/zoom/trackingfields/trackingfield');
|
|
|
48 |
|
|
|
49 |
// Return the paths wrapped into standard activity structure.
|
|
|
50 |
return $this->prepare_activity_structure($paths);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Process the given restore path element data
|
|
|
55 |
*
|
|
|
56 |
* @param array $data parsed element data
|
|
|
57 |
*/
|
|
|
58 |
protected function process_zoom($data) {
|
|
|
59 |
global $DB;
|
|
|
60 |
|
|
|
61 |
$data = (object) $data;
|
|
|
62 |
|
|
|
63 |
// Update start_time before attempting to create a new meeting.
|
|
|
64 |
$data->start_time = $this->apply_date_offset($data->start_time);
|
|
|
65 |
|
|
|
66 |
// Either create a new meeting or set meeting as expired.
|
|
|
67 |
try {
|
|
|
68 |
$updateddata = zoom_webservice()->create_meeting($data);
|
|
|
69 |
$data = populate_zoom_from_response($data, $updateddata);
|
|
|
70 |
$data->exists_on_zoom = ZOOM_MEETING_EXISTS;
|
|
|
71 |
} catch (moodle_exception $e) {
|
|
|
72 |
$data->join_url = '';
|
|
|
73 |
$data->meeting_id = 0;
|
|
|
74 |
$data->exists_on_zoom = ZOOM_MEETING_EXPIRED;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
$data->course = $this->get_courseid();
|
|
|
78 |
|
|
|
79 |
if (empty($data->timemodified)) {
|
|
|
80 |
$data->timemodified = time();
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
if ($data->grade < 0) {
|
|
|
84 |
// Scale found, get mapping.
|
|
|
85 |
$data->grade = -($this->get_mappingid('scale', abs($data->grade)));
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
// Create the zoom instance.
|
|
|
89 |
$newitemid = $DB->insert_record('zoom', $data);
|
|
|
90 |
$this->apply_activity_instance($newitemid);
|
|
|
91 |
|
|
|
92 |
// Create the calendar events for the new meeting.
|
|
|
93 |
$data->id = $newitemid;
|
|
|
94 |
zoom_calendar_item_update($data);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
* Process the zoom tracking fields.
|
|
|
99 |
*
|
|
|
100 |
* @param array $data
|
|
|
101 |
*/
|
|
|
102 |
protected function process_zoom_tracking_field($data) {
|
|
|
103 |
global $DB;
|
|
|
104 |
|
|
|
105 |
$data = (object) $data;
|
|
|
106 |
$oldid = $data->id;
|
|
|
107 |
|
|
|
108 |
$data->meeting_id = $this->get_new_parentid('zoom');
|
|
|
109 |
|
|
|
110 |
$defaulttrackingfields = zoom_clean_tracking_fields();
|
|
|
111 |
|
|
|
112 |
if (isset($defaulttrackingfields[$data->tracking_field])) {
|
|
|
113 |
$newitemid = $DB->insert_record('zoom_meeting_tracking_fields', $data);
|
|
|
114 |
$this->set_mapping('zoom_tracking_field', $oldid, $newitemid);
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
/**
|
|
|
119 |
* Post-execution actions
|
|
|
120 |
*/
|
|
|
121 |
protected function after_execute() {
|
|
|
122 |
// Add zoom related files, no need to match by itemname (just internally handled context).
|
|
|
123 |
$this->add_related_files('mod_zoom', 'intro', null);
|
|
|
124 |
}
|
|
|
125 |
}
|