Completed
Pull Request — master (#155)
by Jesus
02:20 queued 23s
created

mobileview::build_url_join_session()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 1
dl 0
loc 10
rs 9.9332
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
 * 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
     * Return standard array with configurations required for BBB server.
41
     * @param context $context
42
     * @param array $session
43
     * @return mixed
44
     * @throws \coding_exception
45
     * @throws \dml_exception
46
     */
47 View Code Duplication
    public static function bbbsession_set($context, &$session) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
48
49
        global $CFG, $USER;
50
51
        $session['username'] = fullname($USER);
52
        $session['userID'] = $USER->id;
53
        $session['administrator'] = is_siteadmin($session['userID']);
54
        $participantlist = bigbluebuttonbn_get_participant_list($session['bigbluebuttonbn'], $context);
55
        $session['moderator'] = bigbluebuttonbn_is_moderator($context, $participantlist);
56
        $session['managerecordings'] = ($session['administrator']
57
            || has_capability('mod/bigbluebuttonbn:managerecordings', $context));
58
        $session['importrecordings'] = ($session['managerecordings']);
59
        $session['modPW'] = $session['bigbluebuttonbn']->moderatorpass;
60
        $session['viewerPW'] = $session['bigbluebuttonbn']->viewerpass;
61
        $session['meetingid'] = $session['bigbluebuttonbn']->meetingid.'-'.$session['course']->id.'-'.
62
            $session['bigbluebuttonbn']->id;
63
        $session['meetingname'] = $session['bigbluebuttonbn']->name;
64
        $session['meetingdescription'] = $session['bigbluebuttonbn']->intro;
65
        $session['userlimit'] = intval((int)\mod_bigbluebuttonbn\locallib\config::get('userlimit_default'));
66
        if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('userlimit_editable')) {
67
            $session['userlimit'] = intval($session['bigbluebuttonbn']->userlimit);
68
        }
69
        $session['voicebridge'] = $session['bigbluebuttonbn']->voicebridge;
70
        if ($session['bigbluebuttonbn']->voicebridge > 0) {
71
            $session['voicebridge'] = 70000 + $session['bigbluebuttonbn']->voicebridge;
72
        }
73
        $session['wait'] = $session['bigbluebuttonbn']->wait;
74
        $session['record'] = $session['bigbluebuttonbn']->record;
75
76
        $session['recordallfromstart'] = $CFG->bigbluebuttonbn_recording_all_from_start_default;
77
        if ($CFG->bigbluebuttonbn_recording_all_from_start_editable) {
78
            $session['recordallfromstart'] = $session['bigbluebuttonbn']->recordallfromstart;
79
        }
80
81
        $session['recordhidebutton'] = $CFG->bigbluebuttonbn_recording_hide_button_default;
82
        if ($CFG->bigbluebuttonbn_recording_hide_button_editable) {
83
            $session['recordhidebutton'] = $session['bigbluebuttonbn']->recordhidebutton;
84
        }
85
86
        $session['welcome'] = $session['bigbluebuttonbn']->welcome;
87
        if (!isset($session['welcome']) || $session['welcome'] == '') {
88
            $session['welcome'] = get_string('mod_form_field_welcome_default', 'bigbluebuttonbn');
89
        }
90
        if ($session['bigbluebuttonbn']->record) {
91
            // Check if is enable record all from start.
92
            if ($session['recordallfromstart']) {
93
                $session['welcome'] .= '<br><br>'.get_string('bbbrecordallfromstartwarning',
94
                        'bigbluebuttonbn');
95
            } else {
96
                $session['welcome'] .= '<br><br>'.get_string('bbbrecordwarning', 'bigbluebuttonbn');
97
            }
98
        }
99
        $session['openingtime'] = $session['bigbluebuttonbn']->openingtime;
100
        $session['closingtime'] = $session['bigbluebuttonbn']->closingtime;
101
        $session['muteonstart'] = $session['bigbluebuttonbn']->muteonstart;
102
        $session['context'] = $context;
103
        $session['origin'] = 'Moodle';
104
        $session['originVersion'] = $CFG->release;
105
        $parsedurl = parse_url($CFG->wwwroot);
106
        $session['originServerName'] = $parsedurl['host'];
107
        $session['originServerUrl'] = $CFG->wwwroot;
108
        $session['originServerCommonName'] = '';
109
        $session['originTag'] = 'moodle-mod_bigbluebuttonbn ('.get_config('mod_bigbluebuttonbn', 'version').')';
110
        $session['bnserver'] = bigbluebuttonbn_is_bn_server();
111
        $session['clienttype'] = \mod_bigbluebuttonbn\locallib\config::get('clienttype_default');
112
113
        if (\mod_bigbluebuttonbn\locallib\config::get('clienttype_editable')) {
114
            $session['clienttype'] = $session['bigbluebuttonbn']->clienttype;
115
        }
116
117
        if (!\mod_bigbluebuttonbn\locallib\config::clienttype_enabled()) {
118
            $session['clienttype'] = BIGBLUEBUTTON_CLIENTTYPE_FLASH;
119
        }
120
121
        return($session);
122
    }
123
124
    /**
125
     * Build url for join to session.
126
     * This method is similar to "join_meeting()" in bbb_view.
127
     * @param array $bbbsession
128
     * @return string
129
     */
130
    public static function build_url_join_session(&$bbbsession) {
131
        $password = $bbbsession['viewerPW'];
132
        if ($bbbsession['administrator'] || $bbbsession['moderator']) {
133
            $password = $bbbsession['modPW'];
134
        }
135
        $joinurl = bigbluebuttonbn_get_join_url($bbbsession['meetingid'], $bbbsession['username'],
136
            $password, $bbbsession['logoutURL'], null, $bbbsession['userID'], $bbbsession['clienttype']);
137
138
        return($joinurl);
139
    }
140
141
    /**
142
     * Return the status of an activity [open|not_started|ended].
143
     *
144
     * @param array $bbbsession
145
     * @return string
146
     */
147 View Code Duplication
    public static function get_activity_status(&$bbbsession) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
148
        $now = time();
149
        if (!empty($bbbsession['bigbluebuttonbn']->openingtime) && $now < $bbbsession['bigbluebuttonbn']->openingtime) {
150
            // The activity has not been opened.
151
            return 'not_started';
152
        }
153
        if (!empty($bbbsession['bigbluebuttonbn']->closingtime) && $now > $bbbsession['bigbluebuttonbn']->closingtime) {
154
            // The activity has been closed.
155
            return 'ended';
156
        }
157
        // The activity is open.
158
        return 'open';
159
    }
160
161
    /**
162
     * Helper for preparing metadata used while creating the meeting.
163
     *
164
     * @param  array    $bbbsession
165
     * @return array
166
     */
167
    public static function create_meeting_metadata(&$bbbsession) {
168
        return bigbluebuttonbn_create_meeting_metadata($bbbsession);
169
    }
170
171
    /**
172
     * Helper to prepare data used for create meeting.
173
     * @param array $bbbsession
174
     * @return array
175
     * @throws \coding_exception
176
     */
177
    public static function create_meeting_data(&$bbbsession) {
178
        $data = ['meetingID' => $bbbsession['meetingid'],
179
            'name' => bigbluebuttonbn_html2text($bbbsession['meetingname'], 64),
180
            'attendeePW' => $bbbsession['viewerPW'],
181
            'moderatorPW' => $bbbsession['modPW'],
182
            'logoutURL' => $bbbsession['logoutURL'],
183
        ];
184
        $data['record'] = self::create_meeting_data_record($bbbsession['record']);
185
        // Check if auto_start_record is enable.
186 View Code Duplication
        if ($data['record'] == 'true' && $bbbsession['recordallfromstart']) {
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...
187
            $data['autoStartRecording'] = 'true';
188
            // Check if hide_record_button is enable.
189
            if ($bbbsession['recordallfromstart'] && $bbbsession['recordhidebutton']) {
190
                $data['allowStartStopRecording'] = 'false';
191
            }
192
        }
193
        $data['welcome'] = trim($bbbsession['welcome']);
194
        // Set the duration for the meeting.
195
        $durationtime = self::create_meeting_data_duration($bbbsession['bigbluebuttonbn']->closingtime);
196 View Code Duplication
        if ($durationtime > 0) {
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...
197
            $data['duration'] = $durationtime;
198
            $data['welcome'] .= '<br><br>';
199
            $data['welcome'] .= str_replace(
200
                '%duration%',
201
                (string) $durationtime,
202
                get_string('bbbdurationwarning', 'bigbluebuttonbn')
203
            );
204
        }
205
        $voicebridge = intval($bbbsession['voicebridge']);
206
        if ($voicebridge > 0 && $voicebridge < 79999) {
207
            $data['voiceBridge'] = $voicebridge;
208
        }
209
        $maxparticipants = intval($bbbsession['userlimit']);
210
        if ($maxparticipants > 0) {
211
            $data['maxParticipants'] = $maxparticipants;
212
        }
213
        if ($bbbsession['muteonstart']) {
214
            $data['muteOnStart'] = 'true';
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 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 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