| Conditions | 25 |
| Paths | 39 |
| Total Lines | 177 |
| Lines | 23 |
| Ratio | 12.99 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 55 | public static function mobile_course_view($args) { |
||
| 56 | |||
| 57 | global $OUTPUT, $SESSION; |
||
| 58 | |||
| 59 | $args = (object) $args; |
||
| 60 | $viewinstance = bigbluebuttonbn_view_validator($args->cmid, null); |
||
|
|
|||
| 61 | if (!$viewinstance) { |
||
| 62 | $error = get_string('view_error_url_missing_parameters', 'bigbluebuttonbn'); |
||
| 63 | return(self::mobile_print_error($error)); |
||
| 64 | } |
||
| 65 | |||
| 66 | $bbbsession = bigbluebutton::build_bbb_session_fromviewinstance($viewinstance); |
||
| 67 | |||
| 68 | // Create variables for easy access. |
||
| 69 | $bigbluebuttonbn = $viewinstance['bigbluebuttonbn']; |
||
| 70 | $serverversion = $bbbsession['serverversion']; |
||
| 71 | $cm = $bbbsession['cm']; |
||
| 72 | $course = $bbbsession['course']; |
||
| 73 | $context = $bbbsession['context']; |
||
| 74 | |||
| 75 | // Check activity status. |
||
| 76 | $activitystatus = \mod_bigbluebuttonbn\locallib\mobileview::get_activity_status($bbbsession); |
||
| 77 | if ($activitystatus == 'not_started') { |
||
| 78 | $message = get_string('view_message_conference_not_started', 'bigbluebuttonbn'); |
||
| 79 | |||
| 80 | $notstarted = array(); |
||
| 81 | $notstarted['starts_at'] = ''; |
||
| 82 | $notstarted['ends_at'] = ''; |
||
| 83 | if (!empty($bigbluebuttonbn->openingtime)) { |
||
| 84 | $notstarted['starts_at'] = sprintf( |
||
| 85 | '%s: %s', |
||
| 86 | get_string('mod_form_field_openingtime', 'bigbluebuttonbn'), |
||
| 87 | userdate($bigbluebuttonbn->openingtime) |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | if (!empty($bigbluebuttonbn->closingtime)) { |
||
| 91 | $notstarted['ends_at'] = sprintf( |
||
| 92 | '%s: %s', |
||
| 93 | get_string('mod_form_field_closingtime', 'bigbluebuttonbn'), |
||
| 94 | userdate($bigbluebuttonbn->closingtime) |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | |||
| 98 | return(self::mobile_print_notification($bigbluebuttonbn, $cm, $message, $notstarted)); |
||
| 99 | } |
||
| 100 | if ($activitystatus == 'ended') { |
||
| 101 | $message = get_string('view_message_conference_has_ended', 'bigbluebuttonbn'); |
||
| 102 | return(self::mobile_print_notification($bigbluebuttonbn, $cm, $message)); |
||
| 103 | } |
||
| 104 | |||
| 105 | // Check if the BBB server is working. |
||
| 106 | View Code Duplication | if (is_null($serverversion)) { |
|
| 107 | |||
| 108 | if ($bbbsession['administrator']) { |
||
| 109 | $error = get_string('view_error_unable_join', 'bigbluebuttonbn'); |
||
| 110 | } else if ($bbbsession['moderator']) { |
||
| 111 | $error = get_string('view_error_unable_join_teacher', 'bigbluebuttonbn'); |
||
| 112 | } else { |
||
| 113 | $error = get_string('view_error_unable_join_student', 'bigbluebuttonbn'); |
||
| 114 | } |
||
| 115 | |||
| 116 | return(self::mobile_print_error($error)); |
||
| 117 | } |
||
| 118 | |||
| 119 | // Mark viewed by user (if required). |
||
| 120 | $completion = new \completion_info($course); |
||
| 121 | $completion->set_module_viewed($cm); |
||
| 122 | |||
| 123 | // Validate if the user is in a role allowed to join. |
||
| 124 | if (!has_capability('moodle/category:manage', $context) && |
||
| 125 | !has_capability('mod/bigbluebuttonbn:join', $context)) { |
||
| 126 | $error = get_string('view_nojoin', 'bigbluebuttonbn'); |
||
| 127 | return(self::mobile_print_error($error)); |
||
| 128 | } |
||
| 129 | |||
| 130 | // Initialize session variable used across views. |
||
| 131 | $SESSION->bigbluebuttonbn_bbbsession = $bbbsession; |
||
| 132 | |||
| 133 | // Logic of bbb_view for join to session. |
||
| 134 | // If user is not administrator nor moderator (user is student) and waiting is required. |
||
| 135 | if (!$bbbsession['administrator'] && !$bbbsession['moderator'] && $bbbsession['wait']) { |
||
| 136 | $canjoin = \mod_bigbluebuttonbn\locallib\bigbluebutton::can_join_meeting($args->cmid); |
||
| 137 | if (!$canjoin['can_join']) { |
||
| 138 | $message = get_string('view_message_conference_wait_for_moderator', 'bigbluebuttonbn'); |
||
| 139 | return (self::mobile_print_notification($bigbluebuttonbn, $cm, $message)); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | // See if the BBB session is already in progress. |
||
| 144 | if (!bigbluebuttonbn_is_meeting_running($bbbsession['meetingid'])) { |
||
| 145 | |||
| 146 | // The meeting doesnt exist in BBB server, must be created. |
||
| 147 | $response = bigbluebuttonbn_get_create_meeting_array( |
||
| 148 | \mod_bigbluebuttonbn\locallib\mobileview::create_meeting_data($bbbsession), |
||
| 149 | \mod_bigbluebuttonbn\locallib\mobileview::create_meeting_metadata($bbbsession), |
||
| 150 | $bbbsession['presentation']['name'], |
||
| 151 | $bbbsession['presentation']['url'] |
||
| 152 | ); |
||
| 153 | |||
| 154 | View Code Duplication | if (empty($response)) { |
|
| 155 | // The BBB server is failing. |
||
| 156 | if ($bbbsession['administrator']) { |
||
| 157 | $e = get_string('view_error_unable_join', 'bigbluebuttonbn'); |
||
| 158 | } else if ($bbbsession['moderator']) { |
||
| 159 | $e = get_string('view_error_unable_join_teacher', 'bigbluebuttonbn'); |
||
| 160 | } else { |
||
| 161 | $e = get_string('view_error_unable_join_student', 'bigbluebuttonbn'); |
||
| 162 | } |
||
| 163 | return(self::mobile_print_error($e)); |
||
| 164 | } |
||
| 165 | if ($response['returncode'] == 'FAILED') { |
||
| 166 | // The meeting could not be created. |
||
| 167 | $errorkey = bigbluebuttonbn_get_error_key($response['messageKey'], 'view_error_create'); |
||
| 168 | $e = get_string($errorkey, 'bigbluebuttonbn'); |
||
| 169 | return(self::mobile_print_error($e)); |
||
| 170 | } |
||
| 171 | if ($response['hasBeenForciblyEnded'] == 'true') { |
||
| 172 | $e = get_string('index_error_forciblyended', 'bigbluebuttonbn'); |
||
| 173 | return(self::mobile_print_error($e)); |
||
| 174 | } |
||
| 175 | |||
| 176 | // Event meeting created. |
||
| 177 | bigbluebuttonbn_event_log(\mod_bigbluebuttonbn\event\events::$events['meeting_create'], $bigbluebuttonbn); |
||
| 178 | // Insert a record that meeting was created. |
||
| 179 | $overrides = array('meetingid' => $bbbsession['meetingid']); |
||
| 180 | $meta = '{"record":'.($bbbsession['record'] ? 'true' : 'false').'}'; |
||
| 181 | bigbluebuttonbn_log($bbbsession['bigbluebuttonbn'], BIGBLUEBUTTONBN_LOG_EVENT_CREATE, $overrides, $meta); |
||
| 182 | } |
||
| 183 | |||
| 184 | // It is part of 'bigbluebuttonbn_bbb_view_join_meeting' in bbb_view. |
||
| 185 | // Update the cache. |
||
| 186 | $meetinginfo = bigbluebuttonbn_get_meeting_info($bbbsession['meetingid'], BIGBLUEBUTTONBN_UPDATE_CACHE); |
||
| 187 | if ($bbbsession['userlimit'] > 0 && intval($meetinginfo['participantCount']) >= $bbbsession['userlimit']) { |
||
| 188 | // No more users allowed to join. |
||
| 189 | $message = get_string('view_error_userlimit_reached', 'bigbluebuttonbn'); |
||
| 190 | return(self::mobile_print_notification($bigbluebuttonbn, $cm, $message)); |
||
| 191 | } |
||
| 192 | |||
| 193 | // Build final url to BBB. |
||
| 194 | $urltojoin = \mod_bigbluebuttonbn\locallib\mobileview::build_url_join_session($bbbsession); |
||
| 195 | |||
| 196 | // Check groups access and show message. |
||
| 197 | $msjgroup = array(); |
||
| 198 | $groupmode = groups_get_activity_groupmode($bbbsession['cm']); |
||
| 199 | if ($groupmode != NOGROUPS) { |
||
| 200 | $msjgroup = array("message" => get_string('view_mobile_message_groups_not_supported', |
||
| 201 | 'bigbluebuttonbn')); |
||
| 202 | } |
||
| 203 | |||
| 204 | $data = array( |
||
| 205 | 'bigbluebuttonbn' => $bigbluebuttonbn, |
||
| 206 | 'bbbsession' => (object) $bbbsession, |
||
| 207 | 'msjgroup' => $msjgroup, |
||
| 208 | 'urltojoin' => $urltojoin, |
||
| 209 | 'cmid' => $cm->id, |
||
| 210 | 'courseid' => $course->id |
||
| 211 | ); |
||
| 212 | |||
| 213 | // We want to show a notification when user excedded 45 seconds without click button. |
||
| 214 | $jstimecreatedmeeting = 'setTimeout(function(){ |
||
| 215 | document.getElementById("bigbluebuttonbn-mobile-notifications").style.display = "block"; |
||
| 216 | document.getElementById("bigbluebuttonbn-mobile-join").disabled = true; |
||
| 217 | document.getElementById("bigbluebuttonbn-mobile-meetingready").style.display = "none"; |
||
| 218 | }, 45000);'; |
||
| 219 | |||
| 220 | return array( |
||
| 221 | 'templates' => array( |
||
| 222 | array( |
||
| 223 | 'id' => 'main', |
||
| 224 | 'html' => $OUTPUT->render_from_template('mod_bigbluebuttonbn/mobile_view_page', $data), |
||
| 225 | ), |
||
| 226 | ), |
||
| 227 | 'javascript' => $jstimecreatedmeeting, |
||
| 228 | 'otherdata' => '', |
||
| 229 | 'files' => '' |
||
| 230 | ); |
||
| 231 | } |
||
| 232 | |||
| 290 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: