Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace mod_bigbluebuttonbn\output;
17
 
18
use html_table;
19
use html_writer;
20
use mod_bigbluebuttonbn\instance;
21
use mod_bigbluebuttonbn\meeting;
22
use mod_bigbluebuttonbn\plugin;
23
use renderable;
24
use renderer_base;
25
use stdClass;
26
 
27
/**
28
 * Renderer for the Index page.
29
 *
30
 * @package   mod_bigbluebuttonbn
31
 * @copyright 2010 onwards, Blindside Networks Inc
32
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class index implements renderable {
35
 
36
    /** @var stdClass */
37
    protected $course;
38
 
39
    /** @var stdClass[] */
40
    protected $instances;
41
 
42
    /**
43
     * Constructor for the index renderable.
44
     *
45
     * @param stdClass $course
46
     * @param instance[] List of bbbbn instances
47
     */
48
    public function __construct(stdClass $course, array $instances) {
49
        $this->course = $course;
50
        $this->instances = $instances;
51
    }
52
 
53
    /**
54
     * Get the table for the index page.
55
     *
56
     * @param renderer_base $output
57
     * @return html_table
58
     */
59
    public function get_table(renderer_base $output): html_table {
60
        // Print the list of instances.
61
        $table = new html_table();
62
 
63
        if (course_format_uses_sections($this->course->format)) {
1441 ariadna 64
            $sectionheading = course_get_format($this->course)->get_generic_section_name();
1 efrain 65
        } else {
66
            $sectionheading = '';
67
        }
68
 
69
        $table->head = [
70
            $sectionheading,
71
            get_string('index_heading_name', plugin::COMPONENT),
72
            get_string('index_heading_group', plugin::COMPONENT),
73
            get_string('index_heading_users', plugin::COMPONENT),
74
            get_string('index_heading_viewer', plugin::COMPONENT),
75
            get_string('index_heading_moderator', plugin::COMPONENT),
76
            get_string('index_heading_recording', plugin::COMPONENT),
77
            get_string('index_heading_actions', plugin::COMPONENT),
78
        ];
79
        $table->align = ['center', 'left', 'center', 'center', 'center', 'center', 'center'];
80
 
1441 ariadna 81
        $modinfo = get_fast_modinfo($this->course);
82
        foreach ($modinfo->instances['bigbluebuttonbn'] as $cm) {
83
            $instance = $this->instances[$cm->id];
1 efrain 84
            $this->add_instance_to_table($output, $table, $instance);
85
        }
86
 
87
        return $table;
88
    }
89
 
90
    /**
91
     * Add details of the bigbluebuttonbn instance to the table.
92
     *
93
     * @param renderer_base $output
94
     * @param html_table $table
95
     * @param instance $instance
96
     */
97
    protected function add_instance_to_table(renderer_base $output, html_table $table, instance $instance): void {
98
        $cm = $instance->get_cm();
99
        if (!$cm->uservisible) {
100
            return;
101
        }
102
        if (groups_get_activity_groupmode($cm) == 0) {
103
            $table->data[] = $this->add_room_row_to_table($output, $instance);
104
        } else {
105
            // Add 'All participants' room information.
106
            $table->data[] = $this->add_room_row_to_table($output, $instance, 0);
107
 
108
            // Add data for the groups belonging to the bbb instance, if any.
109
            $groups = groups_get_activity_allowed_groups($cm);
110
            foreach ($groups as $group) {
111
                $table->data[] = $this->add_room_row_to_table($output, $instance, $group->id);
112
            }
113
        }
114
    }
115
 
116
    /**
117
     * Displays the general view.
118
     *
119
     * @param renderer_base $output
120
     * @param instance $instance
121
     * @param int|null $group
122
     * @return array
123
     */
124
    protected function add_room_row_to_table(renderer_base $output, instance $instance, ?int $group = null): array {
125
        if ($group) {
126
            $instance = instance::get_group_instance_from_instance($instance, $group);
127
        }
128
        $meeting = new meeting($instance);
129
 
130
        if (course_format_uses_sections($this->course->format)) {
131
            $sectionname = get_section_name($this->course, $instance->get_cm()->sectionnum);
132
        } else {
133
            $sectionname = '';
134
        }
135
 
136
        $viewurl = $instance->get_view_url();
137
        if ($groupid = $instance->get_group_id()) {
138
            $viewurl->param('group', $groupid);
139
        }
140
 
141
        $joinurl = html_writer::link($viewurl, format_string($instance->get_meeting_name()));
142
 
143
        // The meeting info was returned.
144
        if ($meeting->is_running()) {
145
            return [
146
                $sectionname,
147
                $joinurl,
148
                $instance->get_group_name(),
149
                $this->get_room_usercount($meeting),
150
                $this->get_room_attendee_list($meeting, 'VIEWER'),
151
                $this->get_room_attendee_list($meeting, 'MODERATOR'),
152
                $this->get_room_record_info($output, $instance),
153
                $this->get_room_actions($output, $instance, $meeting),
154
            ];
155
        }
156
 
157
        return [$sectionname, $joinurl, $instance->get_group_name(), '', '', '', '', ''];
158
    }
159
 
160
    /**
161
     * Count the number of users in the meeting.
162
     *
163
     * @param meeting $meeting
164
     * @return int
165
     */
166
    protected function get_room_usercount(meeting $meeting): int {
167
        return count($meeting->get_attendees());
168
    }
169
 
170
    /**
171
     * Returns attendee list.
172
     *
173
     * @param meeting $meeting
174
     * @param string $role
175
     * @return string
176
     */
177
    protected function get_room_attendee_list(meeting $meeting, string $role): string {
178
        $attendees = [];
179
 
180
        // Iterate attendees, matching by their "role" property.
181
        foreach ($meeting->get_attendees() as $attendee) {
182
            if (strcmp((string) $attendee['role'], $role) === 0) {
183
                $attendees[] = $attendee['fullName'];
184
            }
185
        }
186
 
187
        return implode(', ', $attendees);
188
    }
189
 
190
    /**
191
     * Returns indication of recording enabled.
192
     *
193
     * @param renderer_base $output
194
     * @param instance $instance
195
     * @return string
196
     */
197
    protected function get_room_record_info(renderer_base $output, instance $instance): string {
198
        if ($instance->is_recorded()) {
199
            // If it has been set when meeting created, set the variable on/off.
200
            return get_string('index_enabled', 'bigbluebuttonbn');
201
        }
202
        return '';
203
    }
204
 
205
    /**
206
     * Returns room actions.
207
     *
208
     * @param renderer_base $output
209
     * @param instance $instance
210
     * @param meeting $meeting
211
     * @return string
212
     */
213
    protected function get_room_actions(renderer_base $output, instance $instance, meeting $meeting): string {
214
        if ($instance->is_moderator()) {
215
            return $output->render_from_template('mod_bigbluebuttonbn/end_session_button', (object) [
216
                'bigbluebuttonbnid' => $instance->get_instance_id(),
217
                'groupid' => $instance->get_group_id(),
218
                'statusrunning' => $meeting->is_running(),
219
            ]);
220
        }
221
 
222
        return '';
223
    }
224
}