| 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 "bigbluebutton_bbb_view_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 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         return($joinurl); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      * Return the status of an activity [open|not_started|ended]. | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      * @param array $bbbsession | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 62 |  | View Code Duplication |     public static function bigbluebuttonbn_view_get_activity_status(&$bbbsession) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $now = time(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         if (!empty($bbbsession['bigbluebuttonbn']->openingtime) && $now < $bbbsession['bigbluebuttonbn']->openingtime) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             // The activity has not been opened. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             return 'not_started'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         if (!empty($bbbsession['bigbluebuttonbn']->closingtime) && $now > $bbbsession['bigbluebuttonbn']->closingtime) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             // The activity has been closed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             return 'ended'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         // The activity is open. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         return 'open'; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |      * Helper for preparing metadata used while creating the meeting. | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |      * @param  array    $bbbsession | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 82 |  | View Code Duplication |     public static function bigbluebutton_bbb_view_create_meeting_metadata(&$bbbsession) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         global $USER; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         // Create standard metadata. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $metadatabbb = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             'bbb-origin' => $bbbsession['origin'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             'bbb-origin-version' => $bbbsession['originVersion'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             'bbb-origin-server-name' => $bbbsession['originServerName'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             'bbb-origin-server-common-name' => $bbbsession['originServerCommonName'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             'bbb-origin-tag' => $bbbsession['originTag'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             'bbb-context' => $bbbsession['course']->fullname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             'bbb-recording-name' => bigbluebuttonbn_html2text($bbbsession['meetingname'], 64), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             'bbb-recording-description' => bigbluebuttonbn_html2text($bbbsession['meetingdescription'], 64), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             'bbb-recording-tags' => bigbluebuttonbn_get_tags($bbbsession['cm']->id), // Same as $id. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         // Check recording status. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('recordingstatus_enabled')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             $metadatabbb["bn-recording-status"] = json_encode( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                 array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                     'email' => array('"' . fullname($USER) . '" <' . $USER->email . '>'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                     'context' => $bbbsession['bigbluebuttonbnURL'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('recordingready_enabled')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             $metadatabbb['bn-recording-ready-url'] = $bbbsession['recordingReadyURL']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('meetingevents_enabled')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             $metadatabbb['bn-meeting-events-url'] = $bbbsession['meetingEventsURL']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         return $metadatabbb; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |      * Helper to prepare data used for create meeting. | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |      * @param array $bbbsession | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |      * @throws \coding_exception | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     public static function bigbluebutton_bbb_view_create_meeting_data(&$bbbsession) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $data = ['meetingID' => $bbbsession['meetingid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             'name' => bigbluebuttonbn_html2text($bbbsession['meetingname'], 64), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             'attendeePW' => $bbbsession['viewerPW'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             'moderatorPW' => $bbbsession['modPW'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             'logoutURL' => $bbbsession['logoutURL'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $data['record'] = self::bigbluebutton_bbb_view_create_meeting_data_record($bbbsession['record']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         // Check if auto_start_record is enable. | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 130 |  | View Code Duplication |         if ($data['record'] == 'true' && $bbbsession['recordallfromstart']) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             $data['autoStartRecording'] = 'true'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             // Check if hide_record_button is enable. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             if ($bbbsession['recordallfromstart'] && $bbbsession['recordhidebutton']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                 $data['allowStartStopRecording'] = 'false'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $data['welcome'] = trim($bbbsession['welcome']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         // Set the duration for the meeting. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $durationtime = self::bigbluebutton_bbb_view_create_meeting_data_duration($bbbsession['bigbluebuttonbn']->closingtime); | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 140 |  | View Code Duplication |         if ($durationtime > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             $data['duration'] = $durationtime; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             $data['welcome'] .= '<br><br>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             $data['welcome'] .= str_replace( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                 '%duration%', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                 (string) $durationtime, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                 get_string('bbbdurationwarning', 'bigbluebuttonbn') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $voicebridge = intval($bbbsession['voicebridge']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         if ($voicebridge > 0 && $voicebridge < 79999) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             $data['voiceBridge'] = $voicebridge; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $maxparticipants = intval($bbbsession['userlimit']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         if ($maxparticipants > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             $data['maxParticipants'] = $maxparticipants; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         if ($bbbsession['muteonstart']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             $data['muteOnStart'] = 'true'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         return $data; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 161 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |      * Helper for returning the flag to know if the meeting is recorded. | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |      * @param  boolean    $record | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     public static function bigbluebutton_bbb_view_create_meeting_data_record($record) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         if ((boolean)\mod_bigbluebuttonbn\locallib\config::recordings_enabled() && $record) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |             return 'true'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         return 'false'; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 174 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  |      * Helper for returning the duration expected for the meeting. | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 179 |  |  |      * @param  string    $closingtime | 
            
                                                                        
                            
            
                                    
            
            
                | 180 |  |  |      * @return integer | 
            
                                                                        
                            
            
                                    
            
            
                | 181 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     public static function bigbluebutton_bbb_view_create_meeting_data_duration($closingtime) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('scheduled_duration_enabled')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |             return bigbluebuttonbn_get_duration($closingtime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         return 0; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 187 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 188 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 189 |  |  |  | 
            
                        
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.