-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathoverview_videos.php
244 lines (209 loc) · 9.99 KB
/
overview_videos.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
/**
* Overview of all videos in a series.
*
* @package block_opencast
* @copyright 2021 Tamara Gunkel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use block_opencast\local\apibridge;
use block_opencast\local\massaction_helper;
use block_opencast\local\upload_helper;
use core\notification;
use mod_opencast\local\opencasttype;
use tool_opencast\local\settings_api;
require_once('../../config.php');
require_once($CFG->dirroot . '/lib/tablelib.php');
global $PAGE, $OUTPUT, $CFG, $DB, $USER, $SITE;
$ocinstanceid = optional_param('ocinstanceid', settings_api::get_default_ocinstance()->id, PARAM_INT);
$series = required_param('series', PARAM_ALPHANUMEXT);
$baseurl = new moodle_url('/blocks/opencast/overview_videos.php', ['ocinstanceid' => $ocinstanceid, 'series' => $series]);
$PAGE->set_url($baseurl);
$PAGE->set_context(context_system::instance());
require_login(get_course($SITE->id), false);
$PAGE->set_pagelayout('standard');
$PAGE->set_title(get_string('pluginname', 'block_opencast'));
$apibridge = apibridge::get_instance($ocinstanceid);
$opencasterror = null;
if (settings_api::num_ocinstances() > 1) {
$PAGE->set_heading(get_string('pluginname', 'block_opencast') . ': ' . settings_api::get_ocinstance($ocinstanceid)->name);
} else {
$PAGE->set_heading(get_string('pluginname', 'block_opencast'));
}
/** @var block_opencast_renderer $renderer */
$renderer = $PAGE->get_renderer('block_opencast');
// Try to retrieve name from opencast.
$ocseries = $apibridge->get_series_by_identifier($series, true);
$hasaddvideopermission = false;
$hasviewpermission = false;
$hasdownloadpermission = false;
$hasdeletepermission = false;
$hasaccesspermission = false;
// Verify that user has permission to view series.
if (!$ocseries || !$apibridge->is_owner($ocseries->acl, $USER->id, $SITE->id)) {
// User is not owner but might have read access to course where series is embedded.
$records = $DB->get_records('tool_opencast_series', ['series' => $series, 'ocinstanceid' => $ocinstanceid]);
foreach ($records as $record) {
$coursecontext = context_course::instance($record->courseid, IGNORE_MISSING);
if ($coursecontext) {
if (has_capability('block/opencast:viewunpublishedvideos', $coursecontext)) {
$hasviewpermission = true;
}
if (has_capability('block/opencast:addvideo', $coursecontext)) {
$hasaddvideopermission = true;
}
if (has_capability('block/opencast:downloadvideo', $coursecontext)) {
$hasdownloadpermission = true;
}
if (has_capability('block/opencast:deleteevent', $coursecontext)) {
$hasdeletepermission = true;
}
if (has_capability('block/opencast:sharedirectaccessvideolink', $coursecontext)) {
$hasaccesspermission = true;
}
}
}
if (!$hasviewpermission) {
redirect(new moodle_url('/blocks/opencast/overview.php', ['ocinstanceid' => $ocinstanceid]),
get_string('viewviedeosnotallowed', 'block_opencast'), null,
\core\output\notification::NOTIFY_ERROR);
}
}
if ($apibridge->is_owner($ocseries->acl, $USER->id, $SITE->id)) {
$hasviewpermission = true;
$hasaddvideopermission = true;
$hasdownloadpermission = true;
$hasdeletepermission = true;
$hasaccesspermission = true;
}
$isseriesowner = $ocseries && ($apibridge->is_owner($ocseries->acl, $USER->id, $SITE->id) ||
!$apibridge->has_owner($ocseries->acl));
$PAGE->navbar->add(get_string('opencastseries', 'block_opencast'),
new moodle_url('/blocks/opencast/overview.php', ['ocinstanceid' => $ocinstanceid]));
$PAGE->navbar->add(get_string('pluginname', 'block_opencast'), $baseurl);
$PAGE->requires->js_call_amd('block_opencast/block_massaction', 'init',
[
$SITE->id,
$ocinstanceid,
massaction_helper::get_js_selectors(),
]
);
echo $OUTPUT->header();
if ($ocseries) {
echo $OUTPUT->heading($ocseries->title);
} else {
// If that fails use id.
echo $OUTPUT->heading($series);
}
echo html_writer::tag('p', get_string('uploadvideosexplanation', 'block_opencast') . '<br />' .
get_string('uploadprocessingexplanation', 'block_opencast'));
// Show "Add video" button.
$addvideourl = new moodle_url('/blocks/opencast/addvideo.php', ['courseid' => $SITE->id,
'ocinstanceid' => $ocinstanceid, 'intoseries' => $series, ]);
$addvideobutton = $OUTPUT->single_button($addvideourl, get_string('addvideo', 'block_opencast'), 'get');
echo html_writer::div($addvideobutton);
// Show "Add videos (batch)" button.
if (get_config('block_opencast', 'batchuploadenabled_' . $ocinstanceid)) {
$batchuploadurl = new moodle_url('/blocks/opencast/batchupload.php',
['courseid' => $SITE->id, 'ocinstanceid' => $ocinstanceid, 'intoseries' => $series]);
$batchuploadbutton = $OUTPUT->single_button($batchuploadurl, get_string('batchupload', 'block_opencast'), 'get');
echo html_writer::div($batchuploadbutton, 'opencast-batchupload-wrap');
}
// If there are upload jobs scheduled, show the upload queue table.
$videojobs = upload_helper::get_upload_jobs($ocinstanceid, $SITE->id);
if (count($videojobs) > 0) {
// Show heading.
echo $OUTPUT->heading(get_string('uploadqueuetoopencast', 'block_opencast'));
// Show explanation.
echo html_writer::tag('p', get_string('uploadqueuetoopencastexplanation', 'block_opencast'));
echo $renderer->render_upload_jobs($ocinstanceid, $videojobs, true, 'overviewvideos', $series);
}
echo html_writer::tag('p', get_string('videosoverviewexplanation', 'block_opencast'));
// Should Do handle opencast connection error. Break as soon as first error occurs.
// Build table.
$columns = ['owner', 'videos', 'linked', 'activities', 'action'];
$headers = ['owner', 'video', 'embeddedasactivity', 'embeddedasactivitywolink', 'heading_actions'];
$massaction = new massaction_helper();
// Mass-Action configuration for update metadata.
if (!$hasaddvideopermission) {
$massaction->massaction_action_activation(massaction_helper::MASSACTION_UPDATEMETADATA, false);
} else {
// When it is offered, we add extra parameters.
$massaction->set_action_path_parameter(massaction_helper::MASSACTION_UPDATEMETADATA, 'redirectpage', 'overviewvideos');
$massaction->set_action_path_parameter(massaction_helper::MASSACTION_UPDATEMETADATA, 'series', $series);
}
// Mass-Action configuration for delete.
if (!$hasdeletepermission) {
$massaction->massaction_action_activation(massaction_helper::MASSACTION_DELETE, false);
} else {
// When it is offered, we add extra parameters.
$massaction->set_action_path_parameter(massaction_helper::MASSACTION_DELETE, 'redirectpage', 'overviewvideos');
$massaction->set_action_path_parameter(massaction_helper::MASSACTION_DELETE, 'series', $series);
}
// No visiblity change and no strat workflow is allowed from overview page!
$massaction->massaction_action_activation(massaction_helper::MASSACTION_CHANGEVISIBILITY, false);
$massaction->massaction_action_activation(massaction_helper::MASSACTION_STARTWORKFLOW, false);
// We add the select columns and headers into the beginning of the headers and columns arrays, when mass actions are there!
if ($massaction->has_massactions()) {
array_unshift($headers, 'selectall');
array_unshift($columns, 'select');
}
$headers = array_map(function ($header) use ($massaction) {
if ($header == 'selectall') {
return $massaction->render_master_checkbox();
}
return get_string($header, 'block_opencast');
}, $headers);
$tableid = 'opencast-overview-videos-table-' . $series;
$table = $renderer->create_overview_videos_table($tableid, $headers, $columns, $baseurl);
$videos = $apibridge->get_series_videos($series)->videos;
$activityinstalled = core_plugin_manager::instance()->get_plugin_info('mod_opencast') != null;
$showchangeownerlink = has_capability('block/opencast:viewusers', context_system::instance()) &&
!empty(get_config('block_opencast', 'aclownerrole_' . $ocinstanceid));
// To store rows, and use them later, which gives better control over the table.
$rows = [];
foreach ($renderer->create_overview_videos_rows($videos, $apibridge, $ocinstanceid,
$activityinstalled, $showchangeownerlink, false, $isseriesowner, $hasaddvideopermission,
$hasdownloadpermission, $hasdeletepermission, '', $hasaccesspermission, $massaction) as $row) {
$rows[] = $row;
}
// Last check to deactivate mass action, if there is nothing to display in the table.
$activatedmassaction = !empty($rows);
$massaction->activate_massaction($activatedmassaction);
$tablecontainerclasses = ['position-relative'];
if ($activatedmassaction) {
$tablecontainerclasses[] = massaction_helper::TABLE_CONTAINER_CLASSNAME;
}
// Rendering the table containter div.
echo html_writer::start_div(implode(' ', $tablecontainerclasses));
// Rendering mass action on top.
echo $massaction->render_table_mass_actions_select('bulkselect-top', $tableid);
// Add rows to the table, which initalizes the table starting html.
if (!empty($rows)) {
foreach ($rows as $row) {
$table->add_data($row);
}
}
// Rendering table.
$table->finish_html();
// Rendering mass action on bottom.
echo $massaction->render_table_mass_actions_select('bulkselect-bottom', $tableid);
echo html_writer::end_div();
if ($opencasterror) {
notification::error($opencasterror);
}
echo $OUTPUT->footer();