mobileview   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 124
Duplicated Lines 23.39 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 29
loc 124
rs 10
c 0
b 0
f 0
wmc 24
lcom 0
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A build_url_join_session() 0 11 3
A get_activity_status() 13 13 5
A create_meeting_metadata() 0 3 1
B create_meeting_data() 16 41 10
A create_meeting_data_record() 0 6 3
A create_meeting_data_duration() 0 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
global $CFG;
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
     * Build url for join to session.
41
     * This method is similar to "join_meeting()" in bbb_view.
42
     * @param array $bbbsession
43
     * @return string
44
     */
45
    public static function build_url_join_session(&$bbbsession) {
46
        $password = $bbbsession['viewerPW'];
47
        if ($bbbsession['administrator'] || $bbbsession['moderator']) {
48
            $password = $bbbsession['modPW'];
49
        }
50
        $joinurl = bigbluebuttonbn_get_join_url($bbbsession['meetingid'], $bbbsession['username'],
51
            $password, $bbbsession['logoutURL'], null, $bbbsession['userID'], $bbbsession['clienttype'],
52
            $bbbsession['createtime']);
53
54
        return($joinurl);
55
    }
56
57
    /**
58
     * Return the status of an activity [open|not_started|ended].
59
     *
60
     * @param array $bbbsession
61
     * @return string
62
     */
63 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...
64
        $now = time();
65
        if (!empty($bbbsession['bigbluebuttonbn']->openingtime) && $now < $bbbsession['bigbluebuttonbn']->openingtime) {
66
            // The activity has not been opened.
67
            return 'not_started';
68
        }
69
        if (!empty($bbbsession['bigbluebuttonbn']->closingtime) && $now > $bbbsession['bigbluebuttonbn']->closingtime) {
70
            // The activity has been closed.
71
            return 'ended';
72
        }
73
        // The activity is open.
74
        return 'open';
75
    }
76
77
    /**
78
     * Helper for preparing metadata used while creating the meeting.
79
     *
80
     * @param  array    $bbbsession
81
     * @return array
82
     */
83
    public static function create_meeting_metadata(&$bbbsession) {
84
        return bigbluebuttonbn_create_meeting_metadata($bbbsession);
85
    }
86
87
    /**
88
     * Helper to prepare data used for create meeting.
89
     * @param array $bbbsession
90
     * @return array
91
     * @throws \coding_exception
92
     */
93
    public static function create_meeting_data(&$bbbsession) {
94
        $data = ['meetingID' => $bbbsession['meetingid'],
95
            'name' => bigbluebuttonbn_html2text($bbbsession['meetingname'], 64),
96
            'attendeePW' => $bbbsession['viewerPW'],
97
            'moderatorPW' => $bbbsession['modPW'],
98
            'logoutURL' => $bbbsession['logoutURL'],
99
        ];
100
        $data['record'] = self::create_meeting_data_record($bbbsession['record']);
101
        // Check if auto_start_record is enable.
102 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...
103
            $data['autoStartRecording'] = 'true';
104
            // Check if hide_record_button is enable.
105
            if ($bbbsession['recordallfromstart'] && $bbbsession['recordhidebutton']) {
106
                $data['allowStartStopRecording'] = 'false';
107
            }
108
        }
109
        $data['welcome'] = trim($bbbsession['welcome']);
110
        // Set the duration for the meeting.
111
        $durationtime = self::create_meeting_data_duration($bbbsession['bigbluebuttonbn']->closingtime);
112 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...
113
            $data['duration'] = $durationtime;
114
            $data['welcome'] .= '<br><br>';
115
            $data['welcome'] .= str_replace(
116
                '%duration%',
117
                (string) $durationtime,
118
                get_string('bbbdurationwarning', 'bigbluebuttonbn')
119
            );
120
        }
121
        $voicebridge = intval($bbbsession['voicebridge']);
122
        if ($voicebridge > 0 && $voicebridge < 79999) {
123
            $data['voiceBridge'] = $voicebridge;
124
        }
125
        $maxparticipants = intval($bbbsession['userlimit']);
126
        if ($maxparticipants > 0) {
127
            $data['maxParticipants'] = $maxparticipants;
128
        }
129
        if ($bbbsession['muteonstart']) {
130
            $data['muteOnStart'] = 'true';
131
        }
132
        return $data;
133
    }
134
135
    /**
136
     * Helper for returning the flag to know if the meeting is recorded.
137
     *
138
     * @param  boolean    $record
139
     * @return string
140
     */
141
    public static function create_meeting_data_record($record) {
142
        if ((boolean)\mod_bigbluebuttonbn\locallib\config::recordings_enabled() && $record) {
143
            return 'true';
144
        }
145
        return 'false';
146
    }
147
148
    /**
149
     * Helper for returning the duration expected for the meeting.
150
     *
151
     * @param  string    $closingtime
152
     * @return integer
153
     */
154
    public static function create_meeting_data_duration($closingtime) {
155
        if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('scheduled_duration_enabled')) {
156
            return bigbluebuttonbn_get_duration($closingtime);
157
        }
158
        return 0;
159
    }
160
}
161