forked from blindsidenetworks/moodle-mod_recordingsbn
/
view.php
394 lines (347 loc) · 18.5 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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
/**
* View and administrate BigBlueButton playback recordings
*
* @package mod_recordingsbn
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
* @copyright 2011-2014 Blindside Networks Inc.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
*/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');
require_once($CFG->dirroot.'/mod/bigbluebuttonbn/locallib.php');
$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
$r = optional_param('r', 0, PARAM_INT); // recordingsbn instance ID - it should be named as the first character of the module
$action = optional_param('action', 0, PARAM_TEXT);
$recordingid = optional_param('recordingid', 0, PARAM_TEXT);
if ($id) {
$cm = get_coursemodule_from_id('recordingsbn', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$recordingsbn = $DB->get_record('recordingsbn', array('id' => $cm->instance), '*', MUST_EXIST);
} elseif ($r) {
$recordingsbn = $DB->get_record('recordingsbn', array('id' => $r), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $recordingsbn->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('recordingsbn', $recordingsbn->id, $course->id, false, MUST_EXIST);
} else {
print_error('You must specify a course_module ID or an instance ID');
}
if ( $CFG->version < '2013111800' ) {
//This is valid before v2.6
$module = $DB->get_record('modules', array('name' => 'recordingsbn'));
$module_version = $module->version;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
} else {
//This is valid after v2.6
$module_version = get_config('mod_recordingsbn', 'version');
$context = context_module::instance($cm->id);
}
if ( $CFG->version < '2014051200' ) {
//This is valid before v2.7
add_to_log($course->id, 'recordingsbn', 'resource viewed', "view.php?id={$cm->id}", $recordingsbn->name, $cm->id);
} else {
//This is valid after v2.7
$event = \mod_recordingsbn\event\recordingsbn_resource_page_viewed::create(
array(
'context' => $context,
'objectid' => $recordingsbn->id
)
);
$event->trigger();
}
require_login($course, true, $cm);
$PAGE->set_context($context);
// show some info for guests
if (isguestuser()) {
$PAGE->set_title(format_string($recordingsbn->name));
echo $OUTPUT->header();
echo $OUTPUT->confirm('<p>'.get_string('view_noguests', 'recordingsbn').'</p>'.get_string('liketologin'),
get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id);
echo $OUTPUT->footer();
exit;
}
$moderator = has_capability('mod/bigbluebuttonbn:moderate', $context);
///Set strings to show
$view_head_recording = get_string('view_head_recording', 'recordingsbn');
$view_head_course = get_string('view_head_course', 'recordingsbn');
$view_head_activity = get_string('view_head_activity', 'recordingsbn');
$view_head_description = get_string('view_head_description', 'recordingsbn');
$view_head_date = get_string('view_head_date', 'recordingsbn');
$view_head_length = get_string('view_head_length', 'recordingsbn');
$view_head_duration = get_string('view_head_duration', 'recordingsbn');
$view_head_actionbar = get_string('view_head_actionbar', 'recordingsbn');
$view_duration_min = get_string('view_duration_min', 'recordingsbn');
/// Print the page header
$PAGE->set_url($CFG->wwwroot.'/mod/recordingsbn/view.php', array('id' => $cm->id));
$PAGE->set_title(format_string($recordingsbn->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_button(update_module_button($cm->id, $course->id, get_string('modulename', 'recordingsbn')));
$PAGE->set_context($context);
$PAGE->set_cacheable(false);
//$PAGE->set_periodic_refresh_delay(60);
/// Output starts here
echo $OUTPUT->header();
/// Shows version as a comment
echo '
<!-- moodle-mod_recordingsbn ('.$module_version.') -->'."\n";
///Declare the table
$table = new html_table();
///Initialize table headers
if ( $moderator ) {
$table->head = array ($view_head_recording, $view_head_activity, $view_head_description, $view_head_date, $view_head_duration, $view_head_actionbar);
$table->align = array ('left', 'left', 'left', 'left', 'center', 'left');
$recordingsbn_columns = array(
array("key" =>"recording", "label" => $view_head_recording, "width" => "125px", "allowHTML" => true),
array("key" =>"activity", "label" => $view_head_activity, "sortable" => true, "width" => "175px"),
array("key" =>"description", "label" => $view_head_description, "sortable" => true, "width" => "250px"),
array("key" =>"date", "label" => $view_head_date, "sortable" => true, "width" => "220px"),
array("key" =>"duration", "label" => $view_head_duration, "width" => "50px"),
array("key" =>"actionbar", "label" => $view_head_actionbar, "width" => "75px", "allowHTML" => true)
);
} else {
$table->head = array ($view_head_recording, $view_head_activity, $view_head_description, $view_head_date, $view_head_duration);
$table->align = array ('left', 'left', 'left', 'left', 'center');
$recordingsbn_columns = array(
array("key" =>"recording", "label" => $view_head_recording, "width" => "125px", "allowHTML" => true),
array("key" =>"activity", "label" => $view_head_activity, "sortable" => true, "width" => "175px"),
array("key" =>"description", "label" => $view_head_description, "sortable" => true, "width" => "250px"),
array("key" =>"date", "label" => $view_head_date, "sortable" => true, "width" => "220px"),
array("key" =>"duration", "label" => $view_head_duration, "width" => "50px")
);
}
///Initialize table data
$recordingsbn_data = array();
//Print page headers
echo $OUTPUT->heading($recordingsbn->name, 2);
// Recordings plugin code
$dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
if ($dbman->table_exists('bigbluebuttonbn_log') ) {
// BigBlueButton Setup
if( isset($CFG->bigbluebuttonbn_server_url) ) {
$url = trim(trim($CFG->bigbluebuttonbn_server_url),'/').'/';
$shared_secret = trim($CFG->bigbluebuttonbn_shared_secret);
} else {
$url = trim(trim($CFG->BigBlueButtonBNServerURL),'/').'/';
$shared_secret = trim($CFG->BigBlueButtonBNSecuritySalt);
}
//Execute actions if there is one and it is allowed
if( isset($action) && isset($recordingid) && $moderator ){
if( $action == 'show' ) {
bigbluebuttonbn_doPublishRecordings($recordingid, 'true', $url, $shared_secret);
if ( $CFG->version < '2014051200' ) {
//This is valid before v2.7
add_to_log($course->id, 'recordingsbn', 'recording published', "", $recordingsbn->name, $cm->id);
} else {
//This is valid after v2.7
$event = \mod_recordingsbn\event\recordingsbn_recording_published::create(
array(
'context' => $context,
'objectid' => $recordingsbn->id,
'other' => array(
//'title' => $title,
'rid' => $recordingid
)
)
);
$event->trigger();
}
} else if( $action == 'hide') {
bigbluebuttonbn_doPublishRecordings($recordingid, 'false', $url, $shared_secret);
if ( $CFG->version < '2014051200' ) {
//This is valid before v2.7
add_to_log($course->id, 'recordingsbn', 'recording unpublished', "", $recordingsbn->name, $cm->id);
} else {
//This is valid after v2.7
$event = \mod_recordingsbn\event\recordingsbn_recording_unpublished::create(
array(
'context' => $context,
'objectid' => $recordingsbn->id,
'other' => array(
//'title' => $title,
'rid' => $recordingid
)
)
);
$event->trigger();
}
} else if( $action == 'delete') {
bigbluebuttonbn_doDeleteRecordings($recordingid, $url, $shared_secret);
if ( $CFG->version < '2014051200' ) {
//This is valid before v2.7
add_to_log($course->id, 'recordingsbn', 'recording deleted', '', $recordingsbn->name, $cm->id);
} else {
//This is valid after v2.7
$event = \mod_recordingsbn\event\recordingsbn_recording_deleted::create(
array(
'context' => $context,
'objectid' => $recordingsbn->id,
'other' => array(
//'title' => $title,
'rid' => $recordingid
)
)
);
$event->trigger();
}
}
}
$meetingID='';
$results = $DB->get_records('bigbluebuttonbn_log', array('courseid' => $course->id, 'record' => 1, 'event' => 'Create'));
if( $results ){
//Eliminates duplicates
$mIDs = array();
foreach ($results as $result) {
$mIDs[$result->meetingid] = $result->meetingid;
}
//Generates the meetingID string
foreach ($mIDs as $mID) {
if (strlen($meetingID) > 0) $meetingID .= ',';
$meetingID .= $mID;
}
}
//If there are meetings with recordings load the data to the table
if ( $meetingID != '' ){
$recordingsbn = bigbluebuttonbn_getRecordingsArray($meetingID, $url, $shared_secret);
if( isset($recordingsbn) && !isset($recordingsbn['messageKey']) ){
foreach ( $recordingsbn as $recording ){
if ( $moderator || $recording['published'] == 'true' ) {
$length = 0;
$endTime = isset($recording['endTime'])? floatval($recording['endTime']):0;
$endTime = $endTime - ($endTime % 1000);
$startTime = isset($recording['startTime'])? floatval($recording['startTime']):0;
$startTime = $startTime - ($startTime % 1000);
$duration = intval(($endTime - $startTime) / 60000);
//$meta_course = isset($recording['meta_context'])?str_replace('"', '\"', $recording['meta_context']):'';
$meta_activity = isset($recording['meta_contextactivity'])?str_replace('"', '\"', $recording['meta_contextactivity']):'';
$meta_description = isset($recording['meta_contextactivitydescription'])?str_replace('"', '\"', $recording['meta_contextactivitydescription']):'';
$actionbar = '';
$params['id'] = $cm->id;
$params['recordingid'] = $recording['recordID'];
if ( $moderator ) {
///Set action [show|hide]
if ( $recording['published'] == 'true' ){
$params['action'] = 'hide';
} else {
$params['action'] = 'show';
}
$url = new moodle_url('/mod/recordingsbn/view.php', $params);
$action = null;
//With text
//$actionbar .= $OUTPUT->action_link( $link, get_string( $params['action'] ), $action, array( 'title' => get_string($params['action'] ) ) );
//With icon
$attributes = array('title' => get_string($params['action']));
$icon = new pix_icon('t/'.$params['action'], get_string($params['action']), 'moodle', $attributes);
$actionbar .= $OUTPUT->action_icon($url, $icon, $action, $attributes, false);
///Set action delete
$params['action'] = 'delete';
$url = new moodle_url('/mod/recordingsbn/view.php', $params);
$action = new component_action('click', 'M.util.show_confirm_dialog', array('message' => get_string('view_delete_confirmation', 'recordingsbn')));
//With text
//$actionbar .= $OUTPUT->action_link( $link, get_string( $params['action'] ), $action, array( 'title' => get_string($params['action']) ) );
//With icon
$attributes = array('title' => get_string($params['action']));
$icon = new pix_icon('t/'.$params['action'], get_string($params['action']), 'moodle', $attributes);
$actionbar .= $OUTPUT->action_icon($url, $icon, $action, $attributes, false);
}
$type = '';
foreach ( $recording['playbacks'] as $playback ){
if ($recording['published'] == 'true'){
$type .= $OUTPUT->action_link($playback['url'], $playback['type'], null, array('title' => $playback['type'], 'target' => '_new') ).' ';
} else {
$type .= $playback['type'].' ';
}
}
//Make sure the startTime is timestamp
if( !is_numeric($recording['startTime']) ){
$date = new DateTime($recording['startTime']);
$recording['startTime'] = date_timestamp_get($date);
} else {
$recording['startTime'] = $recording['startTime'] / 1000;
}
//Set corresponding format
$format = get_string('strftimerecentfull', 'langconfig');
if( isset($format) ) {
$formatedStartDate = userdate($recording['startTime'], $format);
} else {
$format = '%a %h %d, %Y %H:%M:%S %Z';
$formatedStartDate = userdate($recording['startTime'], $format, usertimezone($USER->timezone) );
}
if ( $moderator ) {
$table->data[] = array ($type, $meta_activity, $meta_description, str_replace(" ", " ", $formatedStartDate), $duration, $actionbar );
$recordingsbn_data_item = array(
"recording" => $type,
"activity" => $meta_activity,
"description" => $meta_description,
"date" => $formatedStartDate,
"duration" => $duration." ".$view_duration_min,
"actionbar" => $actionbar
);
} else {
$table->data[] = array ($type, $meta_activity, $meta_description, str_replace(" ", " ", $formatedStartDate), $duration);
$recordingsbn_data_item = array(
"recording" => $type,
"activity" => $meta_activity,
"description" => $meta_description,
"date" => $formatedStartDate,
"duration" => $duration." ".$view_duration_min
);
}
array_push($recordingsbn_data, $recordingsbn_data_item);
}
}
}
}
//Print the table
if (isset($CFG->recordingsbn_ui) && strtolower($CFG->recordingsbn_ui) == 'yui' && $CFG->version >= '2012062500' ) {
//Shows javascript YUI version.
echo '
<style type="text/css">
#recordingsbn_yui_paginator {
margin-top: 15px;
margin-bottom: 10px;
}
</style>'."\n";
echo '<link rel="stylesheet" type="text/css" href="'.$CFG->wwwroot.'/mod/recordingsbn/yui/paginatorview/assets/paginatorview-core.css" />'."\n";
echo '<link rel="stylesheet" type="text/css" href="'.$CFG->wwwroot.'/mod/recordingsbn/yui/paginatorview/assets/skins/sam/paginatorview-skin.css" />'."\n";
echo $OUTPUT->box_start('generalbox boxaligncenter', 'recordingsbn_box')."\n";
echo '<div class="yui3-skin-sam">'."\n";
echo ' <div id="recordingsbn_yui_paginator"></div>'."\n";
echo ' <div id="recordingsbn_yui_table"></div>'."\n";
echo '</div>'."\n";
echo $OUTPUT->box_end();
$gallery_datatable_paginator = array(
'name' => 'datatablepaginator',
'fullpath' => '/mod/recordingsbn/yui/datatablepaginator/datatablepaginator.js'
);
$PAGE->requires->js_module($gallery_datatable_paginator);
$gallery_paginator_view = array(
'name' => 'paginatorview',
'fullpath' => '/mod/recordingsbn/yui/paginatorview/paginatorview.js'
);
$PAGE->requires->js_module($gallery_paginator_view);
//JavaScript variables
$jsvars = array(
'columns' => $recordingsbn_columns,
'data' => $recordingsbn_data
);
$PAGE->requires->data_for_js('recordingsbn', $jsvars);
$jsmodule = array(
'name' => 'mod_recordingsbn',
'fullpath' => '/mod/recordingsbn/module.js',
'requires' => array('datatable-sort', 'datasource-get', 'datasource-jsonschema', 'datasource-polling', 'datatablepaginator', 'paginatorview'),
);
$PAGE->requires->js_init_call('M.mod_recordingsbn.gallery_datatable_init', array(), false, $jsmodule);
} else {
//Shows HTML version.
echo $OUTPUT->box_start('generalbox boxaligncenter', 'recordingsbn_box')."\n";
echo '<div id="recordingsbn_html_table">'."\n";
echo html_writer::table($table)."\n";
echo '</div>'."\n";
echo $OUTPUT->box_end();
}
} else {
echo $OUTPUT->box_start('generalbox boxaligncenter', 'dates');
print_error(get_string('view_dependency_error', 'recordingsbn'));
echo $OUTPUT->box_end();
}
// Finish the page
echo $OUTPUT->footer();