| Conditions | 25 |
| Paths | > 20000 |
| Total Lines | 269 |
| Code Lines | 178 |
| Lines | 29 |
| Ratio | 10.78 % |
| 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 |
||
| 19 | function definition() { |
||
|
|
|||
| 20 | global $CFG, $DB, $USER, $BIGBLUEBUTTONBN_CFG; |
||
| 21 | |||
| 22 | $course_id = optional_param('course', 0, PARAM_INT); // course ID, or |
||
| 23 | $course_module_id = optional_param('update', 0, PARAM_INT); // course_module ID, or |
||
| 24 | if ($course_id) { |
||
| 25 | $course = $DB->get_record('course', array('id' => $course_id), '*', MUST_EXIST); |
||
| 26 | $bigbluebuttonbn = null; |
||
| 27 | } else if ($course_module_id) { |
||
| 28 | $cm = get_coursemodule_from_id('bigbluebuttonbn', $course_module_id, 0, false, MUST_EXIST); |
||
| 29 | $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); |
||
| 30 | $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance), '*', MUST_EXIST); |
||
| 31 | } |
||
| 32 | |||
| 33 | $context = bigbluebuttonbn_get_context_course($course->id); |
||
| 34 | |||
| 35 | //BigBlueButton server data |
||
| 36 | $endpoint = bigbluebuttonbn_get_cfg_server_url(); |
||
| 37 | |||
| 38 | //UI configuration options |
||
| 39 | $voicebridge_editable = bigbluebuttonbn_get_cfg_voicebridge_editable(); |
||
| 40 | $recording_default = bigbluebuttonbn_get_cfg_recording_default(); |
||
| 41 | $recording_editable = bigbluebuttonbn_get_cfg_recording_editable(); |
||
| 42 | $recording_tagging_default = bigbluebuttonbn_get_cfg_recording_tagging_default(); |
||
| 43 | $recording_tagging_editable = bigbluebuttonbn_get_cfg_recording_tagging_editable(); |
||
| 44 | $waitformoderator_default = bigbluebuttonbn_get_cfg_waitformoderator_default(); |
||
| 45 | $waitformoderator_editable = bigbluebuttonbn_get_cfg_waitformoderator_editable(); |
||
| 46 | $userlimit_default = bigbluebuttonbn_get_cfg_userlimit_default(); |
||
| 47 | $userlimit_editable = bigbluebuttonbn_get_cfg_userlimit_editable(); |
||
| 48 | $preuploadpresentation_enabled = bigbluebuttonbn_get_cfg_preuploadpresentation_enabled(); |
||
| 49 | $sendnotifications_enabled = bigbluebuttonbn_get_cfg_sendnotifications_enabled(); |
||
| 50 | |||
| 51 | //Validates if the BigBlueButton server is running |
||
| 52 | $serverVersion = bigbluebuttonbn_getServerVersion($endpoint); |
||
| 53 | if ( !isset($serverVersion) ) { |
||
| 54 | print_error( 'general_error_unable_connect', 'bigbluebuttonbn', $CFG->wwwroot.'/admin/settings.php?section=modsettingbigbluebuttonbn' ); |
||
| 55 | } |
||
| 56 | |||
| 57 | $mform =& $this->_form; |
||
| 58 | $current_activity =& $this->current; |
||
| 59 | |||
| 60 | //------------------------------------------------------------------------------- |
||
| 61 | // First block starts here |
||
| 62 | //------------------------------------------------------------------------------- |
||
| 63 | $mform->addElement('header', 'general', get_string('mod_form_block_general', 'bigbluebuttonbn')); |
||
| 64 | |||
| 65 | $mform->addElement('text', 'name', get_string('mod_form_field_name','bigbluebuttonbn'), 'maxlength="64" size="32"'); |
||
| 66 | $mform->setType('name', PARAM_TEXT); |
||
| 67 | $mform->addRule('name', null, 'required', null, 'client'); |
||
| 68 | |||
| 69 | $version_major = bigbluebuttonbn_get_moodle_version_major(); |
||
| 70 | if ( $version_major < '2015051100' ) { |
||
| 71 | //This is valid before v2.9 |
||
| 72 | $this->add_intro_editor(false, get_string('mod_form_field_intro', 'bigbluebuttonbn')); |
||
| 73 | } else { |
||
| 74 | //This is valid after v2.9 |
||
| 75 | $this->standard_intro_elements(get_string('mod_form_field_intro', 'bigbluebuttonbn')); |
||
| 76 | } |
||
| 77 | $mform->setAdvanced('introeditor'); |
||
| 78 | $mform->setAdvanced('showdescription'); |
||
| 79 | |||
| 80 | $mform->addElement('textarea', 'welcome', get_string('mod_form_field_welcome','bigbluebuttonbn'), 'wrap="virtual" rows="5" cols="60"'); |
||
| 81 | $mform->addHelpButton('welcome', 'mod_form_field_welcome', 'bigbluebuttonbn'); |
||
| 82 | $mform->setType('welcome', PARAM_TEXT); |
||
| 83 | $mform->setAdvanced('welcome'); |
||
| 84 | |||
| 85 | if ( $voicebridge_editable ) { |
||
| 86 | $mform->addElement('text', 'voicebridge', get_string('mod_form_field_voicebridge','bigbluebuttonbn'), array('maxlength'=>4, 'size'=>6)); |
||
| 87 | $mform->addRule('voicebridge', get_string('mod_form_field_voicebridge_format_error', 'bigbluebuttonbn'), 'numeric', '####', 'server'); |
||
| 88 | $mform->setDefault( 'voicebridge', 0 ); |
||
| 89 | $mform->addHelpButton('voicebridge', 'mod_form_field_voicebridge', 'bigbluebuttonbn'); |
||
| 90 | $mform->setAdvanced('voicebridge'); |
||
| 91 | } |
||
| 92 | $mform->setType('voicebridge', PARAM_INT); |
||
| 93 | |||
| 94 | View Code Duplication | if ( $waitformoderator_editable ) { |
|
| 95 | $mform->addElement('checkbox', 'wait', get_string('mod_form_field_wait', 'bigbluebuttonbn')); |
||
| 96 | $mform->addHelpButton('wait', 'mod_form_field_wait', 'bigbluebuttonbn'); |
||
| 97 | $mform->setDefault( 'wait', $waitformoderator_default ); |
||
| 98 | $mform->setAdvanced('wait'); |
||
| 99 | } else { |
||
| 100 | $mform->addElement('hidden', 'wait', $waitformoderator_default ); |
||
| 101 | } |
||
| 102 | $mform->setType('wait', PARAM_INT); |
||
| 103 | |||
| 104 | View Code Duplication | if ( $userlimit_editable ) { |
|
| 105 | $mform->addElement('text', 'userlimit', get_string('mod_form_field_userlimit','bigbluebuttonbn'), 'maxlength="3" size="5"' ); |
||
| 106 | $mform->addHelpButton('userlimit', 'mod_form_field_userlimit', 'bigbluebuttonbn'); |
||
| 107 | $mform->setDefault( 'userlimit', $userlimit_default ); |
||
| 108 | } else { |
||
| 109 | $mform->addElement('hidden', 'userlimit', $userlimit_default ); |
||
| 110 | } |
||
| 111 | $mform->setType('userlimit', PARAM_TEXT); |
||
| 112 | |||
| 113 | if ( floatval($serverVersion) >= 0.8 ) { |
||
| 114 | View Code Duplication | if ( $recording_editable ) { |
|
| 115 | $mform->addElement('checkbox', 'record', get_string('mod_form_field_record', 'bigbluebuttonbn')); |
||
| 116 | $mform->setDefault( 'record', $recording_default ); |
||
| 117 | $mform->setAdvanced('record'); |
||
| 118 | } else { |
||
| 119 | $mform->addElement('hidden', 'record', $recording_default); |
||
| 120 | } |
||
| 121 | $mform->setType('record', PARAM_INT); |
||
| 122 | |||
| 123 | View Code Duplication | if ( $recording_tagging_editable ) { |
|
| 124 | $mform->addElement('checkbox', 'tagging', get_string('mod_form_field_recordingtagging', 'bigbluebuttonbn')); |
||
| 125 | $mform->setDefault('tagging', $recording_tagging_default); |
||
| 126 | $mform->setAdvanced('tagging'); |
||
| 127 | } else { |
||
| 128 | $mform->addElement('hidden', 'tagging', $recording_tagging_default ); |
||
| 129 | } |
||
| 130 | $mform->setType('tagging', PARAM_INT); |
||
| 131 | } |
||
| 132 | |||
| 133 | if ( $sendnotifications_enabled ) { |
||
| 134 | $mform->addElement('checkbox', 'notification', get_string('mod_form_field_notification', 'bigbluebuttonbn')); |
||
| 135 | if ($this->current->instance) { |
||
| 136 | $mform->addHelpButton('notification', 'mod_form_field_notification', 'bigbluebuttonbn'); |
||
| 137 | } else { |
||
| 138 | $mform->addHelpButton('notification', 'mod_form_field_notification', 'bigbluebuttonbn'); |
||
| 139 | } |
||
| 140 | $mform->setDefault('notification', 0); |
||
| 141 | } |
||
| 142 | $mform->setType('notification', PARAM_INT); |
||
| 143 | //------------------------------------------------------------------------------- |
||
| 144 | // First block ends here |
||
| 145 | //------------------------------------------------------------------------------- |
||
| 146 | |||
| 147 | |||
| 148 | //------------------------------------------------------------------------------- |
||
| 149 | // Second block starts here |
||
| 150 | //------------------------------------------------------------------------------- |
||
| 151 | if ( $preuploadpresentation_enabled ) { |
||
| 152 | $mform->addElement('header', 'preupload', get_string('mod_form_block_presentation', 'bigbluebuttonbn')); |
||
| 153 | $mform->setExpanded('preupload'); |
||
| 154 | |||
| 155 | $filemanager_options = array(); |
||
| 156 | $filemanager_options['accepted_types'] = '*'; |
||
| 157 | $filemanager_options['maxbytes'] = 0; |
||
| 158 | $filemanager_options['subdirs'] = 0; |
||
| 159 | $filemanager_options['maxfiles'] = 1; |
||
| 160 | $filemanager_options['mainfile'] = true; |
||
| 161 | |||
| 162 | $mform->addElement('filemanager', 'presentation', get_string('selectfiles'), null, $filemanager_options); |
||
| 163 | } |
||
| 164 | //------------------------------------------------------------------------------- |
||
| 165 | // Second block ends here |
||
| 166 | //------------------------------------------------------------------------------- |
||
| 167 | |||
| 168 | |||
| 169 | //------------------------------------------------------------------------------- |
||
| 170 | // Third block starts here |
||
| 171 | //------------------------------------------------------------------------------- |
||
| 172 | $mform->addElement('header', 'permission', get_string('mod_form_block_participants', 'bigbluebuttonbn')); |
||
| 173 | |||
| 174 | // Data required for "Add participant" and initial "Participant list" setup |
||
| 175 | $roles = bigbluebuttonbn_get_roles(); |
||
| 176 | $users = bigbluebuttonbn_get_users($context); |
||
| 177 | |||
| 178 | $participant_list = bigbluebuttonbn_get_participant_list($bigbluebuttonbn, $context); |
||
| 179 | $mform->addElement('hidden', 'participants', json_encode($participant_list)); |
||
| 180 | $mform->setType('participants', PARAM_TEXT); |
||
| 181 | |||
| 182 | $html_participant_selection = ''. |
||
| 183 | '<div id="fitem_bigbluebuttonbn_participant_selection" class="fitem fitem_fselect">'."\n". |
||
| 184 | ' <div class="fitemtitle">'."\n". |
||
| 185 | ' <label for="bigbluebuttonbn_participant_selectiontype">'.get_string('mod_form_field_participant_add', 'bigbluebuttonbn').' </label>'."\n". |
||
| 186 | ' </div>'."\n". |
||
| 187 | ' <div class="felement fselect">'."\n". |
||
| 188 | ' <select id="bigbluebuttonbn_participant_selection_type" onchange="bigbluebuttonbn_participant_selection_set(); return 0;">'."\n". |
||
| 189 | ' <option value="all" selected="selected">'.get_string('mod_form_field_participant_list_type_all', 'bigbluebuttonbn').'</option>'."\n". |
||
| 190 | ' <option value="role">'.get_string('mod_form_field_participant_list_type_role', 'bigbluebuttonbn').'</option>'."\n". |
||
| 191 | ' <option value="user">'.get_string('mod_form_field_participant_list_type_user', 'bigbluebuttonbn').'</option>'."\n". |
||
| 192 | ' </select>'."\n". |
||
| 193 | ' '."\n". |
||
| 194 | ' <select id="bigbluebuttonbn_participant_selection" disabled="disabled">'."\n". |
||
| 195 | ' <option value="all" selected="selected">---------------</option>'."\n". |
||
| 196 | ' </select>'."\n". |
||
| 197 | ' '."\n". |
||
| 198 | ' <input value="'.get_string('mod_form_field_participant_list_action_add', 'bigbluebuttonbn').'" type="button" id="id_addselectionid" onclick="bigbluebuttonbn_participant_add(); return 0;" />'."\n". |
||
| 199 | ' </div>'."\n". |
||
| 200 | '</div>'."\n". |
||
| 201 | '<div id="fitem_bigbluebuttonbn_participant_list" class="fitem">'."\n". |
||
| 202 | ' <div class="fitemtitle">'."\n". |
||
| 203 | ' <label for="bigbluebuttonbn_participant_list">'.get_string('mod_form_field_participant_list', 'bigbluebuttonbn').' </label>'."\n". |
||
| 204 | ' </div>'."\n". |
||
| 205 | ' <div class="felement fselect">'."\n". |
||
| 206 | ' <table id="participant_list_table">'."\n"; |
||
| 207 | |||
| 208 | // Add participant list |
||
| 209 | foreach($participant_list as $participant){ |
||
| 210 | $participant_selectionid = ''; |
||
| 211 | $participant_selectiontype = $participant['selectiontype']; |
||
| 212 | if( $participant_selectiontype == 'all') { |
||
| 213 | $participant_selectiontype = '<b><i>'.get_string('mod_form_field_participant_list_type_'.$participant_selectiontype, 'bigbluebuttonbn').'</i></b>'; |
||
| 214 | } else { |
||
| 215 | if ( $participant_selectiontype == 'role') { |
||
| 216 | $participant_selectionid = bigbluebuttonbn_get_role_name($participant['selectionid']); |
||
| 217 | } else { |
||
| 218 | foreach($users as $user){ |
||
| 219 | if( $user->id == $participant['selectionid']) { |
||
| 220 | $participant_selectionid = $user->firstname.' '.$user->lastname; |
||
| 221 | break; |
||
| 222 | } |
||
| 223 | } |
||
| 224 | } |
||
| 225 | $participant_selectiontype = '<b><i>'.get_string('mod_form_field_participant_list_type_'.$participant_selectiontype, 'bigbluebuttonbn').':</i></b> '; |
||
| 226 | } |
||
| 227 | |||
| 228 | $html_participant_selection .= ''. |
||
| 229 | ' <tr id="participant_list_tr_'.$participant['selectiontype'].'-'.$participant['selectionid'].'">'."\n". |
||
| 230 | ' <td width="20px"><a onclick="bigbluebuttonbn_participant_remove(\''.$participant['selectiontype'].'\', \''.$participant['selectionid'].'\'); return 0;" title="'.get_string('mod_form_field_participant_list_action_remove', 'bigbluebuttonbn').'">x</a></td>'."\n". |
||
| 231 | ' <td width="125px">'.$participant_selectiontype.'</td>'."\n". |
||
| 232 | ' <td>'.$participant_selectionid.'</td>'."\n". |
||
| 233 | ' <td><i> '.get_string('mod_form_field_participant_list_text_as', 'bigbluebuttonbn').' </i>'."\n". |
||
| 234 | ' <select id="participant_list_role_'.$participant['selectiontype'].'-'.$participant['selectionid'].'" onchange="bigbluebuttonbn_participant_list_role_update(\''.$participant['selectiontype'].'\', \''.$participant['selectionid'].'\'); return 0;">'."\n". |
||
| 235 | ' <option value="'.BIGBLUEBUTTONBN_ROLE_VIEWER.'" '.($participant['role'] == BIGBLUEBUTTONBN_ROLE_VIEWER? 'selected="selected" ': '').'>'.get_string('mod_form_field_participant_bbb_role_'.BIGBLUEBUTTONBN_ROLE_VIEWER, 'bigbluebuttonbn').'</option>'."\n". |
||
| 236 | ' <option value="'.BIGBLUEBUTTONBN_ROLE_MODERATOR.'" '.($participant['role'] == BIGBLUEBUTTONBN_ROLE_MODERATOR? 'selected="selected" ': '').'>'.get_string('mod_form_field_participant_bbb_role_'.BIGBLUEBUTTONBN_ROLE_MODERATOR, 'bigbluebuttonbn').'</option><select>'."\n". |
||
| 237 | ' </td>'."\n". |
||
| 238 | ' </tr>'."\n"; |
||
| 239 | } |
||
| 240 | |||
| 241 | $html_participant_selection .= ''. |
||
| 242 | ' </table>'."\n". |
||
| 243 | ' </div>'."\n". |
||
| 244 | '</div>'."\n". |
||
| 245 | '<script type="text/javascript" src="'.$CFG->wwwroot.'/mod/bigbluebuttonbn/mod_form.js">'."\n". |
||
| 246 | '</script>'."\n"; |
||
| 247 | |||
| 248 | $mform->addElement('html', $html_participant_selection); |
||
| 249 | |||
| 250 | // Add data |
||
| 251 | $mform->addElement('html', '<script type="text/javascript">var bigbluebuttonbn_participant_selection = {"all": [], "role": '.json_encode($roles).', "user": '.bigbluebuttonbn_get_users_json($users).'}; </script>'); |
||
| 252 | $mform->addElement('html', '<script type="text/javascript">var bigbluebuttonbn_participant_list = '.json_encode($participant_list).'; </script>'); |
||
| 253 | $bigbluebuttonbn_strings = Array( "as" => get_string('mod_form_field_participant_list_text_as', 'bigbluebuttonbn'), |
||
| 254 | "viewer" => get_string('mod_form_field_participant_bbb_role_viewer', 'bigbluebuttonbn'), |
||
| 255 | "moderator" => get_string('mod_form_field_participant_bbb_role_moderator', 'bigbluebuttonbn'), |
||
| 256 | "remove" => get_string('mod_form_field_participant_list_action_remove', 'bigbluebuttonbn'), |
||
| 257 | ); |
||
| 258 | $mform->addElement('html', '<script type="text/javascript">var bigbluebuttonbn_strings = '.json_encode($bigbluebuttonbn_strings).'; </script>'); |
||
| 259 | //------------------------------------------------------------------------------- |
||
| 260 | // Third block ends here |
||
| 261 | //------------------------------------------------------------------------------- |
||
| 262 | |||
| 263 | |||
| 264 | //------------------------------------------------------------------------------- |
||
| 265 | // Fourth block starts here |
||
| 266 | //------------------------------------------------------------------------------- |
||
| 267 | $mform->addElement('header', 'schedule', get_string('mod_form_block_schedule', 'bigbluebuttonbn')); |
||
| 268 | if( isset($current_activity->openingtime) && $current_activity->openingtime != 0 || isset($current_activity->closingtime) && $current_activity->closingtime != 0 ) |
||
| 269 | $mform->setExpanded('schedule'); |
||
| 270 | |||
| 271 | $mform->addElement('date_time_selector', 'openingtime', get_string('mod_form_field_openingtime', 'bigbluebuttonbn'), array('optional' => true)); |
||
| 272 | $mform->setDefault('openingtime', 0); |
||
| 273 | $mform->addElement('date_time_selector', 'closingtime', get_string('mod_form_field_closingtime', 'bigbluebuttonbn'), array('optional' => true)); |
||
| 274 | $mform->setDefault('closingtime', 0); |
||
| 275 | //------------------------------------------------------------------------------- |
||
| 276 | // Fourth block ends here |
||
| 277 | //------------------------------------------------------------------------------- |
||
| 278 | |||
| 279 | |||
| 280 | //------------------------------------------------------------------------------- |
||
| 281 | // add standard elements, common to all modules |
||
| 282 | $this->standard_coursemodule_elements(); |
||
| 283 | |||
| 284 | //------------------------------------------------------------------------------- |
||
| 285 | // add standard buttons, common to all modules |
||
| 286 | $this->add_action_buttons(); |
||
| 287 | } |
||
| 288 | |||
| 320 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.