forked from ncstate-delta/moodle-mod_zoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparticipants.php
162 lines (134 loc) · 5.47 KB
/
participants.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
<?php
// This file is part of the Zoom plugin for 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/>.
/**
* List all zoom meetings.
*
* @package mod_zoom
* @copyright 2015 UC Regents
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Login check require_login() is called in zoom_get_instance_setup();.
// @codingStandardsIgnoreLine
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/locallib.php');
require_once(dirname(__FILE__).'/../../lib/accesslib.php');
require_once(dirname(__FILE__).'/../../lib/moodlelib.php');
list($course, $cm, $zoom) = zoom_get_instance_setup();
// Check capability.
$context = context_module::instance($cm->id);
require_capability('mod/zoom:addinstance', $context);
$session = required_param('session', PARAM_INT); // Session.
$export = optional_param('export', null, PARAM_ALPHA);
$PAGE->set_url('/mod/zoom/participants.php', array('id' => $cm->id, 'session' => $session, 'export' => $export));
$strname = $zoom->name;
$strtitle = get_string('participants', 'mod_zoom');
$PAGE->navbar->add($strtitle);
$PAGE->set_title("$course->shortname: $strname");
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('incourse');
/* Cached structure: class->sessions[hostid][meetingid][starttime]
* ->reqfrom
* ->reqto
* ->resfrom
*/
$cache = cache::make('mod_zoom', 'sessions');
if (!($todisplay = $cache->get($zoom->host_id)) || empty($todisplay->sessions[$zoom->meeting_id][$session])) {
$reqdate = getdate($session);
$reqdate['month'] = $reqdate['mon'];
$reqdate['day'] = $reqdate['mday'];
$fdate = sprintf('%u-%u-%u', $reqdate['year'], $reqdate['month'], $reqdate['day']);
$todisplay = zoom_get_sessions_for_display($zoom, $fdate, $fdate);
$cache->set(strval($zoom->host_id), $todisplay);
}
$participants = $todisplay->sessions[$zoom->meeting_id][$session]->participants;
// Display the headers/etc if we're not exporting, or if there is no data.
if (empty($export) || empty($participants)) {
echo $OUTPUT->header();
echo $OUTPUT->heading($strname);
echo $OUTPUT->heading($strtitle, 4);
// Stop if there is no data.
if (empty($participants)) {
notice(get_string('noparticipants', 'mod_zoom'),
new moodle_url('/mod/zoom/report.php', array('id' => $cm->id)));
echo $OUTPUT->footer();
exit();
}
}
// Loop through each user to generate name->uids mapping.
$coursecontext = context_course::instance($course->id);
$enrolled = get_enrolled_users($coursecontext);
$nametouids = array();
foreach ($enrolled as $user) {
$name = strtoupper(fullname($user));
$uids = empty($nametouids[$name]) ? array() : $nametouids[$name];
$uids[] = $user->idnumber;
$nametouids[$name] = $uids;
}
$table = new html_table();
$table->head = array(get_string('idnumber'),
get_string('name'),
get_string('jointime', 'mod_zoom'),
get_string('leavetime', 'mod_zoom'),
get_string('duration', 'mod_zoom'));
foreach ($participants as $p) {
$row = array();
// For some reason, the Zoom report may add a space to the end of the name.
$name = trim($p->name);
// ID number.
$row[] = empty($nametouids[strtoupper($name)]) ? '' : implode(', ', $nametouids[strtoupper($name)]);
// Name.
$row[] = $name;
// Join/leave times.
$join = strtotime($p->join_time);
$row[] = userdate($join);
$leave = strtotime($p->leave_time);
$row[] = userdate($leave);
// Duration.
$row[] = format_time($leave - $join);
$table->data[] = $row;
}
if ($export != 'xls') {
echo html_writer::table($table);
$exporturl = new moodle_url('/mod/zoom/participants.php', array(
'id' => $cm->id,
'session' => $session,
'export' => 'xls'
));
$xlsstring = get_string('application/vnd.ms-excel', 'mimetypes');
$xlsicon = html_writer::img($OUTPUT->pix_url('f/spreadsheet'), $xlsstring, array('title' => $xlsstring));
echo get_string('export', 'mod_zoom') . ': ' . html_writer::link($exporturl, $xlsicon);
echo $OUTPUT->footer();
} else {
require_once(dirname(__FILE__).'/../../lib/excellib.class.php');
$workbook = new MoodleExcelWorkbook("zoom_participants_{$zoom->meeting_id}");
$worksheet = $workbook->add_worksheet($strtitle);
$boldformat = $workbook->add_format();
$boldformat->set_bold(true);
$row = $col = 0;
foreach ($table->head as $colname) {
$worksheet->write_string($row, $col++, $colname, $boldformat);
}
$row++; $col = 0;
foreach ($table->data as $entry) {
foreach ($entry as $value) {
$worksheet->write_string($row, $col++, $value);
}
$row++; $col = 0;
}
$workbook->close();
exit();
}