-
Notifications
You must be signed in to change notification settings - Fork 7
/
view.php
168 lines (150 loc) · 7.25 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
* Prints an instance of mod_opencast.
*
* @package mod_opencast
* @copyright 2020 Tobias Reischmann <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_opencast\local\opencasttype;
use mod_opencast\local\output_helper;
require(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/lib.php');
require_once($CFG->dirroot . '/course/modlib.php');
require_once($CFG->libdir . '/gradelib.php');
require_once($CFG->libdir.'/completionlib.php');
global $OUTPUT, $DB, $PAGE;
// Course_module ID, or ...
$id = optional_param('id', 0, PARAM_INT);
// ... module instance id.
$o = optional_param('o', 0, PARAM_INT);
$episode = optional_param('e', null, PARAM_ALPHANUMEXT);
if ($id) {
$cm = get_coursemodule_from_id('opencast', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
$moduleinstance = $DB->get_record('opencast', ['id' => $cm->instance], '*', MUST_EXIST);
} else if ($o) {
$moduleinstance = $DB->get_record('opencast', ['id' => $o], '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $moduleinstance->course], '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('opencast', $moduleinstance->id, $course->id, false, MUST_EXIST);
} else {
throw new moodle_exception('missingidandcmid', 'mod_opencast');
}
require_login($course, true, $cm);
$modulecontext = context_module::instance($cm->id);
if ($episode) {
$PAGE->set_url('/mod/opencast/view.php', ['id' => $cm->id, 'e' => $episode]);
} else {
$PAGE->set_url('/mod/opencast/view.php', ['id' => $cm->id]);
}
$PAGE->set_title(format_string($moduleinstance->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($modulecontext);
$viewlist = optional_param('list', null, PARAM_BOOL);
if ($viewlist !== null) {
require_sesskey();
if ($viewlist) {
set_user_preference('mod_opencast/list', '1');
} else {
unset_user_preference('mod_opencast/list');
}
redirect($PAGE->url);
die();
}
$event = \mod_opencast\event\course_module_viewed::create([
'objectid' => $moduleinstance->id,
'context' => $modulecontext,
]);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('opencast', $moduleinstance);
$event->trigger();
// Completion.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
if ($moduleinstance->type == opencasttype::EPISODE) {
output_helper::output_episode($moduleinstance->ocinstanceid, $moduleinstance->opencastid, $moduleinstance->id);
} else if ($moduleinstance->type == opencasttype::SERIES) {
if ($episode) {
output_helper::output_episode($moduleinstance->ocinstanceid, $episode, $moduleinstance->id, $moduleinstance->opencastid);
} else {
output_helper::output_series($moduleinstance);
}
} else if ($moduleinstance->type == opencasttype::UPLOAD) {
// Redirect to the upload video page in the mod_opencast by default.
$messagetext = get_string('uploadlandinginfo', 'mod_opencast');
$messagestatus = \core\output\notification::NOTIFY_INFO;
$url = new moodle_url('/mod/opencast/uploadvideo.php', ['cmid' => $cm->id]);
// Check the addvideo capability from block_opencast.
$coursecontext = context_course::instance($course->id);
if (!has_capability('block/opencast:addvideo', $coursecontext)) {
// If capability is not met, redirect back with message.
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
$messagetext = get_string('uploadnotallowed', 'mod_opencast');
$messagestatus = \core\output\notification::NOTIFY_ERROR;
} else if (empty($moduleinstance->uploaddraftitemid)) {
// If the file draft id is not avialable, we remove the instance and redirect back with message.
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
$messagetext = get_string('uploadmissingfile', 'mod_opencast');
$messagestatus = \core\output\notification::NOTIFY_ERROR;
// Delete this module as it is faulty.
course_delete_module($cm->id);
opencast_delete_instance($moduleinstance->id);
}
// Perform the redirect.
redirect($url, $messagetext, null, $messagestatus);
} else if ($moduleinstance->type == opencasttype::UPLOADED) {
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
$uploadjob = $DB->get_record('block_opencast_uploadjob', ['id' => $moduleinstance->uploadjobid]);
if (empty($uploadjob) || empty($uploadjob->opencasteventid)) {
$messagetext = get_string('uploadinprogress', 'mod_opencast', $moduleinstance->name);
$messagestatus = \core\output\notification::NOTIFY_INFO;
// Delete this module as it is faulty.
if (empty($uploadjob)) {
course_delete_module($cm->id);
opencast_delete_instance($moduleinstance->id);
$messagetext = get_string('uploadjobmissing', 'mod_opencast');
$messagestatus = \core\output\notification::NOTIFY_ERROR;
}
redirect($url, $messagetext, null, $messagestatus);
}
$opencasteventid = $uploadjob->opencasteventid;
$apibridge = \block_opencast\local\apibridge::get_instance($moduleinstance->ocinstanceid);
$video = $apibridge->get_opencast_video($opencasteventid);
if ($video->video->processing_state != 'SUCCEEDED') {
$messagetext = get_string('uploadedvideoisbeingprocesses', 'mod_opencast', $moduleinstance->name);
$messagestatus = \core\output\notification::NOTIFY_INFO;
redirect($url, $messagetext, null, $messagestatus);
} else {
try {
// Gather more information about this module so that we can update the module info in the end.
list($unusedcm, $unusedcontext, $unusedmodule, $opencastmoduledata, $unusedcw) =
get_moduleinfo_data($cm , $course);
// Using a dummy parameter 'opencastmodtype' to be replaced with type at when updating record in db.
$opencastmoduledata->opencastmodtype = opencasttype::EPISODE;
$opencastmoduledata->opencastid = $opencasteventid;
$opencastmoduledata->intro = '';
// Update the module info directly.
update_module($opencastmoduledata);
output_helper::output_episode($opencastmoduledata->ocinstanceid, $opencastmoduledata->opencastid,
$opencastmoduledata->id);
} catch (\Exception $e) {
\core\notification::warning($e->getMessage());
}
}
} else {
throw new coding_exception('This opencast activity is neither a episode nor a series.');
}