Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * List all zoom meetings.
19
 *
20
 * @package    mod_zoom
21
 * @copyright  2015 UC Regents
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require(__DIR__ . '/../../config.php');
26
require_once(__DIR__ . '/lib.php');
27
require_once(__DIR__ . '/locallib.php');
28
require_once($CFG->libdir . '/accesslib.php');
29
require_once($CFG->libdir . '/moodlelib.php');
30
 
31
require_login();
32
// Additional access checks in zoom_get_instance_setup().
33
[$course, $cm, $zoom] = zoom_get_instance_setup();
34
 
35
global $DB;
36
 
37
// Check capability.
38
$context = context_module::instance($cm->id);
39
require_capability('mod/zoom:addinstance', $context);
40
 
41
$uuid = required_param('uuid', PARAM_RAW);
42
$export = optional_param('export', null, PARAM_ALPHA);
43
 
44
$PAGE->set_url('/mod/zoom/participants.php', ['id' => $cm->id, 'uuid' => $uuid, 'export' => $export]);
45
 
46
$strname = $zoom->name;
47
$strtitle = get_string('participants', 'mod_zoom');
48
$PAGE->navbar->add($strtitle);
49
$PAGE->set_title("$course->shortname: $strname");
50
$PAGE->set_heading($course->fullname);
51
$PAGE->set_pagelayout('incourse');
52
 
53
$maskparticipantdata = get_config('zoom', 'maskparticipantdata');
54
// If participant data is masked then display a message stating as such and be done with it.
55
if ($maskparticipantdata) {
56
    zoom_fatal_error(
57
        'participantdatanotavailable_help',
58
        'mod_zoom',
59
        new moodle_url('/mod/zoom/report.php', ['id' => $cm->id])
60
    );
61
}
62
 
63
$sessions = zoom_get_sessions_for_display($zoom->id);
64
$participants = $sessions[$uuid]['participants'];
65
 
66
// Display the headers/etc if we're not exporting, or if there is no data.
67
if (empty($export) || empty($participants)) {
68
    echo $OUTPUT->header();
69
    echo $OUTPUT->heading($strname);
70
    echo $OUTPUT->heading($strtitle, 4);
71
 
72
    // Stop if there is no data.
73
    if (empty($participants)) {
74
        notice(get_string('noparticipants', 'mod_zoom'), new moodle_url('/mod/zoom/report.php', ['id' => $cm->id]));
75
        echo $OUTPUT->footer();
76
        exit();
77
    }
78
}
79
 
80
// Loop through each user to generate id->idnumber mapping.
81
$coursecontext = context_course::instance($course->id);
82
$enrolled = get_enrolled_users($coursecontext);
83
$moodleidtouids = [];
84
foreach ($enrolled as $user) {
85
    $moodleidtouids[$user->id] = $user->idnumber;
86
}
87
 
88
$table = new html_table();
89
// If we are exporting, then put email as a separate column.
90
if (!empty($export)) {
91
    $table->head = [
92
        get_string('idnumber'),
93
        get_string('name'),
94
        get_string('email'),
95
        get_string('jointime', 'mod_zoom'),
96
        get_string('leavetime', 'mod_zoom'),
97
        get_string('duration', 'mod_zoom'),
98
    ];
99
} else {
100
    $table->head = [
101
        get_string('idnumber'),
102
        get_string('name'),
103
        get_string('jointime', 'mod_zoom'),
104
        get_string('leavetime', 'mod_zoom'),
105
        get_string('duration', 'mod_zoom'),
106
    ];
107
}
108
 
109
foreach ($participants as $p) {
110
    $row = [];
111
 
112
    // Gets moodleuser so we can try to match information to Moodle database.
113
    $moodleuser = new stdClass();
114
    if (!empty($p->userid)) {
115
        $moodleuser = $DB->get_record('user', ['id' => $p->userid], 'idnumber, email');
116
    }
117
 
118
    // ID number.
119
    if (array_key_exists($p->userid, $moodleidtouids)) {
120
        $row[] = $moodleidtouids[$p->userid];
121
    } else if (isset($moodleuser->idnumber)) {
122
        $row[] = $moodleuser->idnumber;
123
    } else {
124
        $row[] = '';
125
    }
126
 
127
    // Name/email.
128
    $name = $p->name;
129
    $email = '';
130
    if (!empty($moodleuser->email)) {
131
        $email = $moodleuser->email;
132
    } else if (!empty($p->user_email)) {
133
        $email = $p->user_email;
134
    }
135
 
136
    // Put email in separate column if we are exporting to Excel.
137
    if (!empty($export)) {
138
        $row[] = $name;
139
        $row[] = $email;
140
    } else if (!empty($email)) {
141
        $row[] = html_writer::link("mailto:$email", $name);
142
    } else {
143
        $row[] = $name;
144
    }
145
 
146
    // Join/leave times.
147
    $row[] = userdate($p->join_time, get_string('strftimedatetimeshort', 'langconfig'));
148
    $row[] = userdate($p->leave_time, get_string('strftimedatetimeshort', 'langconfig'));
149
 
150
    // Duration.
151
    $durationremainder = $p->duration % 60;
152
    if ($durationremainder != 0) {
153
        $p->duration += 60 - $durationremainder;
154
    }
155
 
156
    $row[] = $p->duration / 60;
157
 
158
    $table->data[] = $row;
159
}
160
 
161
if ($export != 'xls') {
162
    echo html_writer::table($table);
163
 
164
    $exporturl = new moodle_url('/mod/zoom/participants.php', [
165
        'id' => $cm->id,
166
        'uuid' => $uuid,
167
        'export' => 'xls',
168
    ]);
169
    $xlsstring = get_string('application/vnd.ms-excel', 'mimetypes');
170
    $xlsicon = html_writer::img(
171
        $OUTPUT->image_url('f/spreadsheet'),
172
        $xlsstring,
173
        ['title' => $xlsstring, 'class' => 'mimetypeicon']
174
    );
175
    echo get_string('export', 'mod_zoom') . ': ' . html_writer::link($exporturl, $xlsicon);
176
 
177
    echo $OUTPUT->footer();
178
} else {
179
    require_once($CFG->libdir . '/excellib.class.php');
180
 
181
    $workbook = new MoodleExcelWorkbook("zoom_participants_{$zoom->meeting_id}");
182
    $worksheet = $workbook->add_worksheet($strtitle);
183
    $boldformat = $workbook->add_format();
184
    $boldformat->set_bold(true);
185
    $row = $col = 0;
186
 
187
    foreach ($table->head as $colname) {
188
        $worksheet->write_string($row, $col++, $colname, $boldformat);
189
    }
190
 
191
    $row++;
192
    $col = 0;
193
 
194
    foreach ($table->data as $entry) {
195
        foreach ($entry as $value) {
196
            $worksheet->write_string($row, $col++, $value);
197
        }
198
 
199
        $row++;
200
        $col = 0;
201
    }
202
 
203
    $workbook->close();
204
    exit();
205
}