Completed
Push — master ( 411be6...041992 )
by Jesus
03:50
created

index.php ➔ bigbluebuttonbn_index_display_room()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 48
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 29
nc 8
nop 4
dl 0
loc 48
rs 8.551
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
require_once dirname(dirname(dirname(__FILE__))).'/config.php';
26
require_once dirname(__FILE__).'/locallib.php';
27
28
$id = required_param('id', PARAM_INT); // Course Module ID, or
29
$a = optional_param('a', 0, PARAM_INT); // bigbluebuttonbn instance ID
30
$g = optional_param('g', 0, PARAM_INT); // group instance ID
31
32
if (!$id) {
33
    print_error('You must specify a course_module ID or an instance ID');
34
}
35
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
36
37
require_login($course, true);
38
39
$context = bigbluebuttonbn_get_context_course($course->id);
40
41
/// Print the header
42
$PAGE->set_url('/mod/bigbluebuttonbn/index.php', array('id' => $id));
43
$PAGE->set_title(get_string('modulename', 'bigbluebuttonbn'));
44
$PAGE->set_heading($course->fullname);
45
$PAGE->set_cacheable(false);
46
$PAGE->set_pagelayout('incourse');
47
48
//$navigation = build_navigation(array('name' => get_string('modulename', 'bigbluebuttonbn'), 'link' => '', 'type' => 'activity'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
49
$PAGE->navbar->add(get_string('modulename', 'bigbluebuttonbn'), "index.php?id=$course->id");
50
51
/// Get all the appropriate data
52
if (!$bigbluebuttonbns = get_all_instances_in_course('bigbluebuttonbn', $course)) {
53
    notice('There are no instances of bigbluebuttonbn', "../../course/view.php?id=$course->id");
54
}
55
56
/// Print the list of instances
57
$timenow = time();
58
$strweek = get_string('week');
59
$strtopic = get_string('topic');
60
$heading_name = get_string('index_heading_name', 'bigbluebuttonbn');
61
$heading_group = get_string('index_heading_group', 'bigbluebuttonbn');
62
$heading_users = get_string('index_heading_users', 'bigbluebuttonbn');
63
$heading_viewer = get_string('index_heading_viewer', 'bigbluebuttonbn');
64
$heading_moderator = get_string('index_heading_moderator', 'bigbluebuttonbn');
65
$heading_actions = get_string('index_heading_actions', 'bigbluebuttonbn');
66
$heading_recording = get_string('index_heading_recording', 'bigbluebuttonbn');
67
68
$table = new html_table();
69
70
$table->head = array($strweek, $heading_name, $heading_group, $heading_users, $heading_viewer, $heading_moderator, $heading_recording, $heading_actions);
71
$table->align = array('center', 'left', 'center', 'center', 'center', 'center', 'center');
72
73
$logoutURL = $CFG->wwwroot;
74
75
$submit = optional_param('submit', '', PARAM_TEXT);
76
if ($submit === 'end') {
77
78
    // A request to end the meeting
79
80
    $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $a), '*', MUST_EXIST);
81
    if (!$bigbluebuttonbn) {
82
        print_error("BigBlueButton ID $a is incorrect");
83
    }
84
    $course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST);
85
    $cm = get_coursemodule_from_instance('bigbluebuttonbn', $bigbluebuttonbn->id, $course->id, false, MUST_EXIST);
86
87
    //User roles
88 View Code Duplication
    if ($bigbluebuttonbn->participants == null || $bigbluebuttonbn->participants == '' || $bigbluebuttonbn->participants == '[]') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
        //The room that is being used comes from a previous version
90
        $moderator = has_capability('mod/bigbluebuttonbn:moderate', $context);
91
    } else {
92
        $moderator = bigbluebuttonbn_is_moderator($USER->id, get_user_roles($context, $USER->id, true), $bigbluebuttonbn->participants);
93
    }
94
    $administrator = has_capability('moodle/category:manage', $context);
95
96
    if ($moderator || $administrator) {
97
        bigbluebuttonbn_event_log(BIGBLUEBUTTON_EVENT_MEETING_ENDED, $bigbluebuttonbn, $cm);
98
99
        echo get_string('index_ending', 'bigbluebuttonbn');
100
101
        $meetingID = $bigbluebuttonbn->meetingid.'-'.$course->id.'-'.$bigbluebuttonbn->id;
102
        if ($g != '0') {
103
            $meetingID .= '['.$g.']';
104
        }
105
        $getArray = bigbluebuttonbn_wrap_xml_load_file(bigbluebuttonbn_getEndMeetingURL($meetingID, $bigbluebuttonbn->moderatorpass));
106
        redirect('index.php?id='.$id);
107
    }
108
}
109
110
foreach ($bigbluebuttonbns as $bigbluebuttonbn) {
111
    if ($bigbluebuttonbn->visible) {
112
        $cm = get_coursemodule_from_id('bigbluebuttonbn', $bigbluebuttonbn->coursemodule, 0, false, MUST_EXIST);
113
114
        //User roles
115 View Code Duplication
        if ($bigbluebuttonbn->participants == null || $bigbluebuttonbn->participants == '' || $bigbluebuttonbn->participants == '[]') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
            //The room that is being used comes from a previous version
117
            $moderator = has_capability('mod/bigbluebuttonbn:moderate', $context);
118
        } else {
119
            $moderator = bigbluebuttonbn_is_moderator($USER->id, get_user_roles($context, $USER->id, true), $bigbluebuttonbn->participants);
120
        }
121
        $administrator = has_capability('moodle/category:manage', $context);
122
123
        $can_moderate = ($administrator || $moderator);
124
125
        //Add a the data for the bigbluebuttonbn instance
126
        $groupObj = (groups_get_activity_groupmode($cm) > 0) ? (object) array('id' => 0, 'name' => get_string('allparticipants')) : null;
127
        $table->data[] = bigbluebuttonbn_index_display_room($can_moderate, $course, $bigbluebuttonbn, $groupObj);
128
129
        //Add a the data for the groups belonging to the bigbluebuttonbn instance, if any
130
        $groups = groups_get_activity_allowed_groups($cm);
131
        foreach ($groups as $group) {
132
            $table->data[] = bigbluebuttonbn_index_display_room($can_moderate, $course, $bigbluebuttonbn, $group);
133
        }
134
    }
135
}
136
137
echo $OUTPUT->header();
138
139
echo $OUTPUT->heading(get_string('index_heading', 'bigbluebuttonbn'));
140
echo html_writer::table($table);
141
142
echo $OUTPUT->footer();
143
144
/// Functions
145
function bigbluebuttonbn_index_display_room($moderator, $course, $bigbluebuttonbn, $groupObj = null)
146
{
147
    $meetingID = $bigbluebuttonbn->meetingid.'-'.$course->id.'-'.$bigbluebuttonbn->id;
148
    $paramGroup = '';
149
    $groupName = '';
150
151
    if ($groupObj) {
152
        $meetingID .= '['.$groupObj->id.']';
153
        $paramGroup = '&group='.$groupObj->id;
154
        $groupName = $groupObj->name;
155
    }
156
157
    $meetingInfo = bigbluebuttonbn_getMeetingInfoArray($meetingID);
158
159
    if (!$meetingInfo) {
160
        // The server was unreachable
161
        print_error(get_string('index_error_unable_display', 'bigbluebuttonbn'));
162
163
        return;
164
    }
165
166
    if (isset($meetingInfo['messageKey']) && $meetingInfo['messageKey'] == 'checksumError') {
167
        // There was an error returned
168
        print_error(get_string('index_error_checksum', 'bigbluebuttonbn'));
169
170
        return;
171
    }
172
173
    // Output Users in the meeting
174
    $joinURL = '<a href="view.php?id='.$bigbluebuttonbn->coursemodule.$paramGroup.'">'.format_string($bigbluebuttonbn->name).'</a>';
175
    $group = $groupName;
176
    $users = '';
177
    $viewerList = '';
178
    $moderatorList = '';
179
    $recording = '';
180
    $actions = '';
181
182
    // The meeting info was returned
183
    if ($meetingInfo['running'] == 'true') {
184
        $users = bigbluebuttonbn_index_display_room_users($meetingInfo);
185
        $viewerList = bigbluebuttonbn_index_display_room_users_attendee_list($meetingInfo, 'VIEWER');
186
        $moderatorList = bigbluebuttonbn_index_display_room_users_attendee_list($meetingInfo, 'MODERATOR');
187
        $recording = bigbluebuttonbn_index_display_room_recordings($meetingInfo);
188
        $actions = bigbluebuttonbn_index_display_room_actions($moderator, $course, $bigbluebuttonbn, $groupObj);
189
    }
190
191
    return array($bigbluebuttonbn->section, $joinURL, $group, $users, $viewerList, $moderatorList, $recording, $actions);
192
}
193
194
function bigbluebuttonbn_index_display_room_users($meetingInfo)
195
{
196
    $users = '';
197
198
    if (count($meetingInfo['attendees']) && count($meetingInfo['attendees']->attendee)) {
199
        $users = count($meetingInfo['attendees']->attendee);
200
    }
201
202
    return $users;
203
}
204
205
function bigbluebuttonbn_index_display_room_users_attendee_list($meetingInfo, $role)
206
{
207
    $attendeeList = '';
208
209
    if (count($meetingInfo['attendees']) && count($meetingInfo['attendees']->attendee)) {
210
        $attendee_count = 0;
211
        foreach ($meetingInfo['attendees']->attendee as $attendee) {
212
            if ($attendee->role == $role) {
213
                $attendeeList .= ($attendee_count++ > 0 ? ', ' : '').$attendee->fullName;
214
            }
215
        }
216
    }
217
218
    return $attendeeList;
219
}
220
221
function bigbluebuttonbn_index_display_room_recordings($meetingInfo)
222
{
223
    $recording = '';
224
225
    if (isset($meetingInfo['recording']) && $meetingInfo['recording'] === 'true') { // if it has been set when meeting created, set the variable on/off
226
        $recording = get_string('index_enabled', 'bigbluebuttonbn');
227
    }
228
229
    return $recording;
230
}
231
232
function bigbluebuttonbn_index_display_room_actions($moderator, $course, $bigbluebuttonbn, $groupObj = null)
233
{
234
    $actions = '';
235
236
    if ($moderator) {
237
        $actions .= '<form name="form1" method="post" action="">'.'/n';
238
        $actions .= '  <INPUT type="hidden" name="id" value="'.$course->id.'">'.'/n';
239
        $actions .= '  <INPUT type="hidden" name="a" value="'.$bigbluebuttonbn->id.'">'.'/n';
240
        if ($groupObj != null) {
241
            $actions .= '  <INPUT type="hidden" name="g" value="'.$groupObj->id.'">'.'/n';
242
        }
243
        $actions .= '  <INPUT type="submit" name="submit" value="end" onclick="return confirm(\''.get_string('index_confirm_end', 'bigbluebuttonbn').'\')">'.'/n';
244
        $actions .= '</form>'.'/n';
245
    }
246
247
    return $actions;
248
}
249