Completed
Push — master ( 770f64...44031d )
by Jesus
02:14
created

index.php ➔ bigbluebuttonbn_index_display_room()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 43
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 29
nc 8
nop 4
dl 0
loc 43
rs 6.7272
c 0
b 0
f 0
1
<?php
2
// This file is part of 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
 * View all BigBlueButton instances in this course.
19
 *
20
 * @author    Fred Dixon  (ffdixon [at] blindsidenetworks [dt] com)
21
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
22
 * @copyright 2010-2017 Blindside Networks Inc
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
24
 */
25
26
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
27
require_once(dirname(__FILE__).'/locallib.php');
28
29
$id = required_param('id', PARAM_INT);
30
$a = optional_param('a', 0, PARAM_INT);
31
$g = optional_param('g', 0, PARAM_INT);
32
33
if (!$id) {
34
    print_error('You must specify a course_module ID or an instance ID');
35
    return;
36
}
37
38
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
39
40
require_login($course, true);
41
42
$context = context_course::instance($course->id);
43
44
// Print the header.
45
$PAGE->set_url('/mod/bigbluebuttonbn/index.php', array('id' => $id));
46
$PAGE->set_title(get_string('modulename', 'bigbluebuttonbn'));
47
$PAGE->set_heading($course->fullname);
48
$PAGE->set_cacheable(false);
49
$PAGE->set_pagelayout('incourse');
50
51
$PAGE->navbar->add(get_string('modulename', 'bigbluebuttonbn'), "index.php?id=$course->id");
52
53
// Get all the appropriate data.
54
if (!$bigbluebuttonbns = get_all_instances_in_course('bigbluebuttonbn', $course)) {
55
    notice('There are no instances of bigbluebuttonbn', "../../course/view.php?id=$course->id");
56
}
57
58
// Print the list of instances.
59
$timenow = time();
60
$strweek = get_string('week');
61
$strtopic = get_string('topic');
62
$headingname = get_string('index_heading_name', 'bigbluebuttonbn');
63
$headinggroup = get_string('index_heading_group', 'bigbluebuttonbn');
64
$headingusers = get_string('index_heading_users', 'bigbluebuttonbn');
65
$headingviewer = get_string('index_heading_viewer', 'bigbluebuttonbn');
66
$headingmoderator = get_string('index_heading_moderator', 'bigbluebuttonbn');
67
$headingactions = get_string('index_heading_actions', 'bigbluebuttonbn');
68
$headingrecording = get_string('index_heading_recording', 'bigbluebuttonbn');
69
70
$table = new html_table();
71
72
$table->head = array($strweek, $headingname, $headinggroup, $headingusers, $headingviewer, $headingmoderator,
73
    $headingrecording, $headingactions);
74
$table->align = array('center', 'left', 'center', 'center', 'center', 'center', 'center');
75
76
$submit = optional_param('submit', '', PARAM_TEXT);
77
if ($submit === 'end') {
78
    // A request to end the meeting.
79
    $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $a), '*', MUST_EXIST);
80
    if (!$bigbluebuttonbn) {
81
        print_error("BigBlueButton ID $a is incorrect");
82
    }
83
    $course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST);
84
    $cm = get_coursemodule_from_instance('bigbluebuttonbn', $bigbluebuttonbn->id, $course->id, false, MUST_EXIST);
85
86
    // User roles.
87
    $moderator = bigbluebuttonbn_is_moderator($context, $bigbluebuttonbn->participants);
88
    $administrator = is_siteadmin();
89
90
    if ($moderator || $administrator) {
91
        bigbluebuttonbn_event_log(BIGBLUEBUTTON_EVENT_MEETING_ENDED, $bigbluebuttonbn, $cm);
92
93
        echo get_string('index_ending', 'bigbluebuttonbn');
94
95
        $meetingid = $bigbluebuttonbn->meetingid.'-'.$course->id.'-'.$bigbluebuttonbn->id;
96
        if ($g != '0') {
97
            $meetingid .= '['.$g.']';
98
        }
99
        bigbluebuttonbn_wrap_xml_load_file(bigbluebuttonbn_getEndMeetingURL($meetingid));
100
        redirect('index.php?id='.$id);
101
    }
102
}
103
104
foreach ($bigbluebuttonbns as $bigbluebuttonbn) {
105
    if ($bigbluebuttonbn->visible) {
106
        $cm = get_coursemodule_from_id('bigbluebuttonbn', $bigbluebuttonbn->coursemodule, 0, false, MUST_EXIST);
107
108
        // User roles.
109
        $moderator = bigbluebuttonbn_is_moderator($context, $bigbluebuttonbn->participants);
110
        $administrator = is_siteadmin();
111
112
        $canmoderate = ($administrator || $moderator);
113
114
        // Add a the data for the bigbluebuttonbn instance.
115
        $groupobj = null;
116
        if (groups_get_activity_groupmode($cm) > 0) {
117
            $groupobj = (object) array('id' => 0, 'name' => get_string('allparticipants'));
118
        }
119
        $table->data[] = bigbluebuttonbn_index_display_room($canmoderate, $course, $bigbluebuttonbn, $groupobj);
120
121
        // Add a the data for the groups belonging to the bigbluebuttonbn instance, if any.
122
        $groups = groups_get_activity_allowed_groups($cm);
123
        foreach ($groups as $group) {
124
            $table->data[] = bigbluebuttonbn_index_display_room($canmoderate, $course, $bigbluebuttonbn, $group);
125
        }
126
    }
127
}
128
129
echo $OUTPUT->header();
130
131
echo $OUTPUT->heading(get_string('index_heading', 'bigbluebuttonbn'));
132
echo html_writer::table($table);
133
134
echo $OUTPUT->footer();
135
136
// Functions.
137
function bigbluebuttonbn_index_display_room($moderator, $course, $bigbluebuttonbn, $groupobj = null) {
138
    $meetingid = $bigbluebuttonbn->meetingid.'-'.$course->id.'-'.$bigbluebuttonbn->id;
139
    $paramgroup = '';
140
    $groupname = '';
141
142
    if ($groupobj) {
143
        $meetingid .= '['.$groupobj->id.']';
144
        $paramgroup = '&group='.$groupobj->id;
145
        $groupname = $groupobj->name;
146
    }
147
    $meetinginfo = bigbluebuttonbn_get_meeting_info_array($meetingid);
148
149
    if (!$meetinginfo) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $meetinginfo of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
150
        // The server was unreachable.
151
        print_error(get_string('index_error_unable_display', 'bigbluebuttonbn'));
152
        return;
153
    }
154
155
    if (isset($meetinginfo['messageKey']) && $meetinginfo['messageKey'] == 'checksumError') {
156
        // There was an error returned.
157
        print_error(get_string('index_error_checksum', 'bigbluebuttonbn'));
158
        return;
159
    }
160
161
    // Output Users in the meeting.
162
    $joinurl = '<a href="view.php?id='.$bigbluebuttonbn->coursemodule.$paramgroup.'">'.format_string($bigbluebuttonbn->name).'</a>';
163
    $group = $groupname;
164
    $users = '';
165
    $viewerlist = '';
166
    $moderatorlist = '';
167
    $recording = '';
168
    $actions = '';
169
    // The meeting info was returned.
170
    if (array_key_exists('running', $meetinginfo) && $meetinginfo['running'] == 'true') {
171
        $users = bigbluebuttonbn_index_display_room_users($meetinginfo);
172
        $viewerlist = bigbluebuttonbn_index_display_room_users_attendee_list($meetinginfo, 'VIEWER');
173
        $moderatorlist = bigbluebuttonbn_index_display_room_users_attendee_list($meetinginfo, 'MODERATOR');
174
        $recording = bigbluebuttonbn_index_display_room_recordings($meetinginfo);
175
        $actions = bigbluebuttonbn_index_display_room_actions($moderator, $course, $bigbluebuttonbn, $groupobj);
176
    }
177
178
    return array($bigbluebuttonbn->section, $joinurl, $group, $users, $viewerlist, $moderatorlist, $recording, $actions);
179
}
180
181
function bigbluebuttonbn_index_display_room_users($meetinginfo) {
182
    $users = '';
183
184
    if (count($meetinginfo['attendees']) && count($meetinginfo['attendees']->attendee)) {
185
        $users = count($meetinginfo['attendees']->attendee);
186
    }
187
188
    return $users;
189
}
190
191
function bigbluebuttonbn_index_display_room_users_attendee_list($meetinginfo, $role) {
192
    $attendeelist = '';
193
194
    if (count($meetinginfo['attendees']) && count($meetinginfo['attendees']->attendee)) {
195
        $attendeecount = 0;
196
        foreach ($meetinginfo['attendees']->attendee as $attendee) {
197
            if ($attendee->role == $role) {
198
                $attendeelist .= ($attendeecount++ > 0 ? ', ' : '').$attendee->fullName;
199
            }
200
        }
201
    }
202
203
    return $attendeelist;
204
}
205
206
function bigbluebuttonbn_index_display_room_recordings($meetinginfo) {
207
    $recording = '';
208
209
    if (isset($meetinginfo['recording']) && $meetinginfo['recording'] === 'true') {
210
        // If it has been set when meeting created, set the variable on/off.
211
        $recording = get_string('index_enabled', 'bigbluebuttonbn');
212
    }
213
214
    return $recording;
215
}
216
217
function bigbluebuttonbn_index_display_room_actions($moderator, $course, $bigbluebuttonbn, $groupobj = null) {
218
    $actions = '';
219
220
    if ($moderator) {
221
        $actions .= '<form name="form1" method="post" action="">'.'/n';
222
        $actions .= '  <INPUT type="hidden" name="id" value="'.$course->id.'">'.'/n';
223
        $actions .= '  <INPUT type="hidden" name="a" value="'.$bigbluebuttonbn->id.'">'.'/n';
224
        if ($groupobj != null) {
225
            $actions .= '  <INPUT type="hidden" name="g" value="'.$groupobj->id.'">'.'/n';
226
        }
227
        $actions .= '  <INPUT type="submit" name="submit" value="end" onclick="return confirm(\''.
228
            get_string('index_confirm_end', 'bigbluebuttonbn').'\')">'.'/n';
229
        $actions .= '</form>'.'/n';
230
    }
231
232
    return $actions;
233
}
234