index::bigbluebuttonbn_index_display_room_users()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 1
dl 0
loc 7
rs 10
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
 * Renderer.
19
 *
20
 * @package   mod_bigbluebuttonbn
21
 * @copyright 2010 onwards, Blindside Networks Inc
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @author    Darko Miletic  (darko.miletic [at] gmail [dt] com)
24
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
25
 */
26
27
namespace mod_bigbluebuttonbn\output;
28
29
use renderable;
30
use html_table;
31
use html_writer;
32
use stdClass;
33
use coding_exception;
34
use mod_bigbluebuttonbn\plugin;
35
36
defined('MOODLE_INTERNAL') || die();
37
38
require_once($CFG->dirroot.'/mod/bigbluebuttonbn/locallib.php');
39
40
/**
41
 * Class index
42
 * @package   mod_bigbluebuttonbn
43
 * @copyright 2010 onwards, Blindside Networks Inc
44
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45
 * @author    Darko Miletic  (darko.miletic [at] gmail [dt] com)
46
 */
47
class index implements renderable {
48
49
    /** @var html_table */
50
    public $table = null;
51
52
    /**
53
     * index constructor.
54
     * @param  stdClass $course
55
     * @throws coding_exception
56
     */
57
    public function __construct($course) {
58
        global $PAGE;
59
60
        // Get all the appropriate data.
61
        if (!$bigbluebuttonbns = get_all_instances_in_course('bigbluebuttonbn', $course)) {
62
            notice(
63
                get_string('index_error_noinstances', plugin::COMPONENT),
64
                plugin::necurl('/course/view.php', ['id' => $course->id])
65
            );
66
        }
67
68
        // Print the list of instances.
69
        $strweek = get_string('week');
70
        $headingname = get_string('index_heading_name', plugin::COMPONENT);
71
        $headinggroup = get_string('index_heading_group', plugin::COMPONENT);
72
        $headingusers = get_string('index_heading_users', plugin::COMPONENT);
73
        $headingviewer = get_string('index_heading_viewer', plugin::COMPONENT);
74
        $headingmoderator = get_string('index_heading_moderator', plugin::COMPONENT);
75
        $headingactions = get_string('index_heading_actions', plugin::COMPONENT);
76
        $headingrecording = get_string('index_heading_recording', plugin::COMPONENT);
77
78
        $table = new html_table();
79
        $table->head = array($strweek, $headingname, $headinggroup, $headingusers, $headingviewer, $headingmoderator,
80
            $headingrecording, $headingactions);
81
        $table->align = array('center', 'left', 'center', 'center', 'center', 'center', 'center');
82
83
        foreach ($bigbluebuttonbns as $bigbluebuttonbn) {
84
            if ($bigbluebuttonbn->visible) {
85
                $cm = get_coursemodule_from_id('bigbluebuttonbn', $bigbluebuttonbn->coursemodule, 0, false, MUST_EXIST);
86
                // User roles.
87
                $participantlist = bigbluebuttonbn_get_participant_list($bigbluebuttonbn, $PAGE->context);
88
                $moderator = bigbluebuttonbn_is_moderator($PAGE->context, $participantlist);
89
                $administrator = is_siteadmin();
90
                $canmoderate = ($administrator || $moderator);
91
                // Add a the data for the bigbluebuttonbn instance.
92
                $groupobj = null;
93
                if (groups_get_activity_groupmode($cm) > 0) {
94
                    $groupobj = (object) array('id' => 0, 'name' => get_string('allparticipants'));
95
                }
96
                $table->data[] = self::bigbluebuttonbn_index_display_room($canmoderate, $course, $bigbluebuttonbn, $groupobj);
97
                // Add a the data for the groups belonging to the bigbluebuttonbn instance, if any.
98
                $groups = groups_get_activity_allowed_groups($cm);
99
                foreach ($groups as $group) {
100
                    $table->data[] = self::bigbluebuttonbn_index_display_room($canmoderate, $course, $bigbluebuttonbn, $group);
101
                }
102
            }
103
        }
104
105
        $this->table = $table;
106
    }
107
108
    /**
109
     * Displays the general view.
110
     *
111
     * @param boolean $moderator
112
     * @param object $course
113
     * @param object $bigbluebuttonbn
114
     * @param object $groupobj
115
     * @return array
116
     */
117
    public static function bigbluebuttonbn_index_display_room($moderator, $course, $bigbluebuttonbn, $groupobj = null) {
118
        $meetingid = sprintf('%s-%d-%d', $bigbluebuttonbn->meetingid, $course->id, $bigbluebuttonbn->id);
119
        $groupname = '';
120
        $urlparams = ['id' => $bigbluebuttonbn->coursemodule];
121
        if ($groupobj) {
122
            $meetingid .= sprintf('[%d]', $groupobj->id);
123
            $urlparams['group'] = $groupobj->id;
124
            $groupname = $groupobj->name;
125
        }
126
        $meetinginfo = bigbluebuttonbn_get_meeting_info_array($meetingid);
127
        if (empty($meetinginfo)) {
128
            // The server was unreachable.
129
            print_error('index_error_unable_display', plugin::COMPONENT);
130
        }
131
        if (isset($meetinginfo['messageKey']) && ($meetinginfo['messageKey'] == 'checksumError')) {
132
            // There was an error returned.
133
            print_error('index_error_checksum', plugin::COMPONENT);
134
        }
135
        // Output Users in the meeting.
136
        $joinurl = html_writer::link(
137
            plugin::necurl('/mod/bigbluebuttonbn/view.php', $urlparams),
138
            format_string($bigbluebuttonbn->name)
139
        );
140
        $group = $groupname;
141
        $users = '';
142
        $viewerlist = '';
143
        $moderatorlist = '';
144
        $recording = '';
145
        $actions = '';
146
        // The meeting info was returned.
147
        if (array_key_exists('running', $meetinginfo) && $meetinginfo['running'] == 'true') {
148
            $users = self::bigbluebuttonbn_index_display_room_users($meetinginfo);
149
            $viewerlist = self::bigbluebuttonbn_index_display_room_users_attendee_list($meetinginfo, 'VIEWER');
150
            $moderatorlist = self::bigbluebuttonbn_index_display_room_users_attendee_list($meetinginfo, 'MODERATOR');
151
            $recording = self::bigbluebuttonbn_index_display_room_recordings($meetinginfo);
152
            $actions = self::bigbluebuttonbn_index_display_room_actions($moderator, $course, $bigbluebuttonbn, $groupobj);
153
        }
154
        return array($bigbluebuttonbn->section, $joinurl, $group, $users, $viewerlist, $moderatorlist, $recording, $actions);
155
    }
156
157
    /**
158
     * Count the number of users in the meeting.
159
     *
160
     * @param array $meetinginfo
161
     * @return integer
162
     */
163
    public static function bigbluebuttonbn_index_display_room_users($meetinginfo) {
164
        $users = '';
165
        if (count($meetinginfo['attendees']) && count($meetinginfo['attendees']->attendee)) {
166
            $users = count($meetinginfo['attendees']->attendee);
167
        }
168
        return $users;
169
    }
170
171
    /**
172
     * Returns attendee list.
173
     *
174
     * @param array $meetinginfo
175
     * @param string $role
176
     * @return string
177
     */
178
    public static function bigbluebuttonbn_index_display_room_users_attendee_list($meetinginfo, $role) {
179
        $attendeelist = '';
180
        if (count($meetinginfo['attendees']) && count($meetinginfo['attendees']->attendee)) {
181
            $attendeecount = 0;
182
            foreach ($meetinginfo['attendees']->attendee as $attendee) {
183
                if ($attendee->role == $role) {
184
                    $attendeelist .= ($attendeecount++ > 0 ? ', ' : '').$attendee->fullName;
185
                }
186
            }
187
        }
188
        return $attendeelist;
189
    }
190
191
    /**
192
     * Returns indication of recording enabled.
193
     *
194
     * @param array $meetinginfo
195
     * @return string
196
     */
197
    public static function bigbluebuttonbn_index_display_room_recordings($meetinginfo) {
198
        $recording = '';
199
        if (isset($meetinginfo['recording']) && $meetinginfo['recording'] === 'true') {
200
            // If it has been set when meeting created, set the variable on/off.
201
            $recording = get_string('index_enabled', 'bigbluebuttonbn');
202
        }
203
        return $recording;
204
    }
205
206
    /**
207
     * Returns room actions.
208
     *
209
     * @param boolean $moderator
210
     * @param object $course
211
     * @param object $bigbluebuttonbn
212
     * @param object $groupobj
213
     * @return string
214
     */
215
    public static function bigbluebuttonbn_index_display_room_actions($moderator, $course, $bigbluebuttonbn, $groupobj = null) {
216
        $actions = '';
217
        if ($moderator) {
218
            $actions .= '<form name="form1" method="post" action="">'."\n";
219
            $actions .= '  <INPUT type="hidden" name="id" value="'.$course->id.'">'."\n";
220
            $actions .= '  <INPUT type="hidden" name="a" value="'.$bigbluebuttonbn->id.'">'."\n";
221
            $actions .= '  <INPUT type="hidden" name="action" value="end">'."\n";
222
            if ($groupobj != null) {
223
                $actions .= '  <INPUT type="hidden" name="g" value="'.$groupobj->id.'">'."\n";
224
            }
225
            $actions .= '  <INPUT type="submit" name="submit" value="' .
226
                get_string('view_conference_action_end', 'bigbluebuttonbn') .
227
                '" class="btn btn-primary btn-sm" onclick="return confirm(\'' .
228
                get_string('index_confirm_end', 'bigbluebuttonbn') . '\')">' . "\n";
229
            $actions .= '</form>'."\n";
230
        }
231
        return $actions;
232
    }
233
}