|
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
|
|
|
* The mod_bigbluebuttonbn locallib/mobileview. |
|
19
|
|
|
* |
|
20
|
|
|
* @package mod_bigbluebuttonbn |
|
21
|
|
|
* @copyright 2018 onwards, Blindside Networks Inc |
|
22
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace mod_bigbluebuttonbn\locallib; |
|
26
|
|
|
|
|
27
|
|
|
defined('MOODLE_INTERNAL') || die(); |
|
28
|
|
|
|
|
29
|
|
|
require_once($CFG->dirroot . '/mod/bigbluebuttonbn/locallib.php'); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Methods used to render view BBB in mobile. |
|
33
|
|
|
* |
|
34
|
|
|
* @copyright 2018 onwards, Blindside Networks Inc |
|
35
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|
36
|
|
|
*/ |
|
37
|
|
|
class mobileview { |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Setup the bbbsession variable that is used all accross the plugin. |
|
41
|
|
|
* |
|
42
|
|
|
* @param object $context |
|
43
|
|
|
* @param array $bbbsession |
|
44
|
|
|
* @return array $bbbsession |
|
45
|
|
|
*/ |
|
46
|
|
View Code Duplication |
public static function bigbluebuttonbn_view_bbbsession_set($context, &$bbbsession) { |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
global $CFG, $USER; |
|
49
|
|
|
// User data. |
|
50
|
|
|
$bbbsession['username'] = fullname($USER); |
|
51
|
|
|
$bbbsession['userID'] = $USER->id; |
|
52
|
|
|
// User roles. |
|
53
|
|
|
$bbbsession['administrator'] = is_siteadmin($bbbsession['userID']); |
|
54
|
|
|
$participantlist = bigbluebuttonbn_get_participant_list($bbbsession['bigbluebuttonbn'], $context); |
|
55
|
|
|
$bbbsession['moderator'] = bigbluebuttonbn_is_moderator($context, $participantlist); |
|
56
|
|
|
$bbbsession['managerecordings'] = ($bbbsession['administrator'] |
|
57
|
|
|
|| has_capability('mod/bigbluebuttonbn:managerecordings', $context)); |
|
58
|
|
|
$bbbsession['importrecordings'] = ($bbbsession['managerecordings']); |
|
59
|
|
|
// Server data. |
|
60
|
|
|
$bbbsession['modPW'] = $bbbsession['bigbluebuttonbn']->moderatorpass; |
|
61
|
|
|
$bbbsession['viewerPW'] = $bbbsession['bigbluebuttonbn']->viewerpass; |
|
62
|
|
|
// Database info related to the activity. |
|
63
|
|
|
$bbbsession['meetingid'] = $bbbsession['bigbluebuttonbn']->meetingid.'-'.$bbbsession['course']->id.'-'. |
|
64
|
|
|
$bbbsession['bigbluebuttonbn']->id; |
|
65
|
|
|
$bbbsession['meetingname'] = $bbbsession['bigbluebuttonbn']->name; |
|
66
|
|
|
$bbbsession['meetingdescription'] = $bbbsession['bigbluebuttonbn']->intro; |
|
67
|
|
|
// Extra data for setting up the Meeting. |
|
68
|
|
|
$bbbsession['userlimit'] = intval((int)\mod_bigbluebuttonbn\locallib\config::get('userlimit_default')); |
|
69
|
|
|
if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('userlimit_editable')) { |
|
70
|
|
|
$bbbsession['userlimit'] = intval($bbbsession['bigbluebuttonbn']->userlimit); |
|
71
|
|
|
} |
|
72
|
|
|
$bbbsession['voicebridge'] = $bbbsession['bigbluebuttonbn']->voicebridge; |
|
73
|
|
|
if ($bbbsession['bigbluebuttonbn']->voicebridge > 0) { |
|
74
|
|
|
$bbbsession['voicebridge'] = 70000 + $bbbsession['bigbluebuttonbn']->voicebridge; |
|
75
|
|
|
} |
|
76
|
|
|
$bbbsession['wait'] = $bbbsession['bigbluebuttonbn']->wait; |
|
77
|
|
|
$bbbsession['record'] = $bbbsession['bigbluebuttonbn']->record; |
|
78
|
|
|
$bbbsession['welcome'] = $bbbsession['bigbluebuttonbn']->welcome; |
|
79
|
|
|
if (!isset($bbbsession['welcome']) || $bbbsession['welcome'] == '') { |
|
80
|
|
|
$bbbsession['welcome'] = get_string('mod_form_field_welcome_default', 'bigbluebuttonbn'); |
|
81
|
|
|
} |
|
82
|
|
|
if ($bbbsession['bigbluebuttonbn']->record) { |
|
83
|
|
|
$bbbsession['welcome'] .= '<br><br>'.get_string('bbbrecordwarning', 'bigbluebuttonbn'); |
|
84
|
|
|
} |
|
85
|
|
|
$bbbsession['openingtime'] = $bbbsession['bigbluebuttonbn']->openingtime; |
|
86
|
|
|
$bbbsession['closingtime'] = $bbbsession['bigbluebuttonbn']->closingtime; |
|
87
|
|
|
// Additional info related to the course. |
|
88
|
|
|
$bbbsession['context'] = $context; |
|
89
|
|
|
// Metadata (origin). |
|
90
|
|
|
$bbbsession['origin'] = 'Moodle'; |
|
91
|
|
|
$bbbsession['originVersion'] = $CFG->release; |
|
92
|
|
|
$parsedurl = parse_url($CFG->wwwroot); |
|
93
|
|
|
$bbbsession['originServerName'] = $parsedurl['host']; |
|
94
|
|
|
$bbbsession['originServerUrl'] = $CFG->wwwroot; |
|
95
|
|
|
$bbbsession['originServerCommonName'] = ''; |
|
96
|
|
|
$bbbsession['originTag'] = 'moodle-mod_bigbluebuttonbn ('.get_config('mod_bigbluebuttonbn', 'version').')'; |
|
97
|
|
|
$bbbsession['bnserver'] = bigbluebuttonbn_is_bn_server(); |
|
98
|
|
|
// Setting for clienttype, assign flash if not enabled, or default if not editable. |
|
99
|
|
|
$bbbsession['clienttype'] = \mod_bigbluebuttonbn\locallib\config::get('clienttype_default'); |
|
100
|
|
|
if (\mod_bigbluebuttonbn\locallib\config::get('clienttype_editable')) { |
|
101
|
|
|
$bbbsession['clienttype'] = $bbbsession['bigbluebuttonbn']->clienttype; |
|
102
|
|
|
} |
|
103
|
|
|
if (!\mod_bigbluebuttonbn\locallib\config::clienttype_enabled()) { |
|
104
|
|
|
$bbbsession['clienttype'] = BIGBLUEBUTTON_CLIENTTYPE_FLASH; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return($bbbsession); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Build url for join to session. |
|
112
|
|
|
* This method is similar to "bigbluebutton_bbb_view_join_meeting" in bbb_view. |
|
113
|
|
|
* @param $bbbsession |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public static function build_url_join_session($bbbsession) { |
|
117
|
|
|
$password = $bbbsession['viewerPW']; |
|
118
|
|
|
if ($bbbsession['administrator'] || $bbbsession['moderator']) { |
|
119
|
|
|
$password = $bbbsession['modPW']; |
|
120
|
|
|
} |
|
121
|
|
|
$joinurl = bigbluebuttonbn_get_join_url($bbbsession['meetingid'], $bbbsession['username'], |
|
122
|
|
|
$password, $bbbsession['logoutURL'], null, $bbbsession['userID'], $bbbsession['clienttype']); |
|
123
|
|
|
|
|
124
|
|
|
return($joinurl); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Return the status of an activity [open|not_started|ended]. |
|
129
|
|
|
* |
|
130
|
|
|
* @param array $bbbsession |
|
131
|
|
|
* @return string |
|
132
|
|
|
*/ |
|
133
|
|
|
public static function bigbluebuttonbn_view_get_activity_status(&$bbbsession) { |
|
134
|
|
|
$now = time(); |
|
135
|
|
View Code Duplication |
if (!empty($bbbsession['bigbluebuttonbn']->openingtime) && $now < $bbbsession['bigbluebuttonbn']->openingtime) { |
|
|
|
|
|
|
136
|
|
|
// The activity has not been opened. |
|
137
|
|
|
return 'not_started'; |
|
138
|
|
|
} |
|
139
|
|
|
if (!empty($bbbsession['bigbluebuttonbn']->closingtime) && $now > $bbbsession['bigbluebuttonbn']->closingtime) { |
|
140
|
|
|
// The activity has been closed. |
|
141
|
|
|
return 'ended'; |
|
142
|
|
|
} |
|
143
|
|
|
// The activity is open. |
|
144
|
|
|
return 'open'; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Helper for preparing metadata used while creating the meeting. |
|
149
|
|
|
* |
|
150
|
|
|
* @param array $bbbsession |
|
151
|
|
|
* @return array |
|
152
|
|
|
*/ |
|
153
|
|
View Code Duplication |
public static function bigbluebutton_bbb_view_create_meeting_metadata(&$bbbsession) { |
|
|
|
|
|
|
154
|
|
|
global $USER; |
|
155
|
|
|
$metadata = ['bbb-origin' => $bbbsession['origin'], |
|
156
|
|
|
'bbb-origin-version' => $bbbsession['originVersion'], |
|
157
|
|
|
'bbb-origin-server-name' => $bbbsession['originServerName'], |
|
158
|
|
|
'bbb-origin-server-common-name' => $bbbsession['originServerCommonName'], |
|
159
|
|
|
'bbb-origin-tag' => $bbbsession['originTag'], |
|
160
|
|
|
'bbb-context' => $bbbsession['course']->fullname, |
|
161
|
|
|
'bbb-recording-name' => bigbluebuttonbn_html2text($bbbsession['meetingname'], 64), |
|
162
|
|
|
'bbb-recording-description' => bigbluebuttonbn_html2text($bbbsession['meetingdescription'], 64), |
|
163
|
|
|
'bbb-recording-tags' => bigbluebuttonbn_get_tags($bbbsession['cm']->id), // Same as $id. |
|
164
|
|
|
]; |
|
165
|
|
|
if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('recordingstatus_enabled')) { |
|
166
|
|
|
$metadata["bn-recording-status"] = json_encode( |
|
167
|
|
|
array( |
|
168
|
|
|
'email' => array('"' . fullname($USER) . '" <' . $USER->email . '>'), |
|
169
|
|
|
'context' => $bbbsession['bigbluebuttonbnURL'] |
|
170
|
|
|
) |
|
171
|
|
|
); |
|
172
|
|
|
} |
|
173
|
|
|
if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('recordingready_enabled')) { |
|
174
|
|
|
$metadata['bn-recording-ready-url'] = $bbbsession['recordingReadyURL']; |
|
175
|
|
|
} |
|
176
|
|
|
if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('meetingevents_enabled')) { |
|
177
|
|
|
$metadata['bn-meeting-events-url'] = $bbbsession['meetingEventsURL']; |
|
178
|
|
|
} |
|
179
|
|
|
return $metadata; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Helper for preparing data used for creating the meeting. |
|
184
|
|
|
* |
|
185
|
|
|
* @param array $bbbsession |
|
186
|
|
|
* @return object |
|
187
|
|
|
*/ |
|
188
|
|
View Code Duplication |
public static function bigbluebutton_bbb_view_create_meeting_data(&$bbbsession) { |
|
|
|
|
|
|
189
|
|
|
$data = ['meetingID' => $bbbsession['meetingid'], |
|
190
|
|
|
'name' => bigbluebuttonbn_html2text($bbbsession['meetingname'], 64), |
|
191
|
|
|
'attendeePW' => $bbbsession['viewerPW'], |
|
192
|
|
|
'moderatorPW' => $bbbsession['modPW'], |
|
193
|
|
|
'logoutURL' => $bbbsession['logoutURL'], |
|
194
|
|
|
]; |
|
195
|
|
|
$data['record'] = self::bigbluebutton_bbb_view_create_meeting_data_record($bbbsession['record']); |
|
196
|
|
|
$data['welcome'] = trim($bbbsession['welcome']); |
|
197
|
|
|
// Set the duration for the meeting. |
|
198
|
|
|
$durationtime = self::bigbluebutton_bbb_view_create_meeting_data_duration($bbbsession['bigbluebuttonbn']->closingtime); |
|
199
|
|
|
if ($durationtime > 0) { |
|
200
|
|
|
$data['duration'] = $durationtime; |
|
201
|
|
|
$data['welcome'] .= '<br><br>'; |
|
202
|
|
|
$data['welcome'] .= str_replace( |
|
203
|
|
|
'%duration%', |
|
204
|
|
|
(string) $durationtime, |
|
205
|
|
|
get_string('bbbdurationwarning', 'bigbluebuttonbn') |
|
206
|
|
|
); |
|
207
|
|
|
} |
|
208
|
|
|
$voicebridge = intval($bbbsession['voicebridge']); |
|
209
|
|
|
if ($voicebridge > 0 && $voicebridge < 79999) { |
|
210
|
|
|
$data['voiceBridge'] = $voicebridge; |
|
211
|
|
|
} |
|
212
|
|
|
$maxparticipants = intval($bbbsession['userlimit']); |
|
213
|
|
|
if ($maxparticipants > 0) { |
|
214
|
|
|
$data['maxParticipants'] = $maxparticipants; |
|
215
|
|
|
} |
|
216
|
|
|
return $data; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Helper for returning the flag to know if the meeting is recorded. |
|
221
|
|
|
* |
|
222
|
|
|
* @param boolean $record |
|
223
|
|
|
* @return string |
|
224
|
|
|
*/ |
|
225
|
|
|
public static function bigbluebutton_bbb_view_create_meeting_data_record($record) { |
|
226
|
|
|
if ((boolean)\mod_bigbluebuttonbn\locallib\config::recordings_enabled() && $record) { |
|
227
|
|
|
return 'true'; |
|
228
|
|
|
} |
|
229
|
|
|
return 'false'; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* Helper for returning the duration expected for the meeting. |
|
234
|
|
|
* |
|
235
|
|
|
* @param string $closingtime |
|
236
|
|
|
* @return integer |
|
237
|
|
|
*/ |
|
238
|
|
|
public static function bigbluebutton_bbb_view_create_meeting_data_duration($closingtime) { |
|
239
|
|
|
if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('scheduled_duration_enabled')) { |
|
240
|
|
|
return bigbluebuttonbn_get_duration($closingtime); |
|
241
|
|
|
} |
|
242
|
|
|
return 0; |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|
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.