| Conditions | 4 |
| Paths | 6 |
| Total Lines | 56 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 81 | public function index() { |
||
| 82 | $wt_tree = Globals::getTree(); |
||
| 83 | $controller = new PageController(); |
||
| 84 | $controller |
||
| 85 | ->setPageTitle(I18N::translate('Sosa Configuration')) |
||
| 86 | ->restrictAccess(Auth::check()) |
||
| 87 | ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) |
||
| 88 | ->addInlineJavascript('autocomplete();') |
||
| 89 | ->addInlineJavascript(' |
||
| 90 | $( document ).ready(function() { |
||
| 91 | $("#bt_sosa_compute").click(function() { |
||
| 92 | majComputeSosa($("#maj_sosa_input_userid, #maj-sosa-config-select option:selected").val()); |
||
| 93 | }); |
||
| 94 | }); |
||
| 95 | |||
| 96 | function majComputeSosa(user_id) { |
||
| 97 | jQuery("#bt_sosa_compute").prop( "disabled", true ); |
||
| 98 | jQuery("#bt_sosa_computing").empty().html("<i class=\"icon-loading-small\"></i> '. I18N::translate('Computing...') .'"); |
||
| 99 | jQuery("#bt_sosa_computing").load( |
||
| 100 | "module.php?mod='.$this->module->getName().'&mod_action=SosaConfig@computeAll&ged='.$wt_tree->getNameUrl().'&userid=" + user_id, |
||
| 101 | function() { |
||
| 102 | jQuery("#bt_sosa_compute").prop( "disabled", false ); |
||
| 103 | }); |
||
| 104 | }'); |
||
| 105 | |||
| 106 | $action = Filter::post('action'); |
||
| 107 | if($action === 'update') $this->update($controller); |
||
| 108 | |||
| 109 | $view_bag = new ViewBag(); |
||
| 110 | $view_bag->set('title', $controller->getPageTitle()); |
||
| 111 | $view_bag->set('tree', $wt_tree); |
||
| 112 | $view_bag->set('form_url', 'module.php?mod='.$this->module->getName().'&mod_action=SosaConfig&ged='.$wt_tree->getNameUrl()); |
||
| 113 | |||
| 114 | $users_root = array(); |
||
| 115 | $users_js_array = 'var users_array = [];'; |
||
| 116 | if(Auth::check()) { |
||
| 117 | $root_id = $wt_tree->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID'); |
||
| 118 | $users_root[] = array( 'user' => Auth::user(), 'rootid' => $root_id); |
||
| 119 | $users_js_array .= 'users_array["'.Auth::user()->getUserId().'"] = "' . $root_id . '";'; |
||
| 120 | |||
| 121 | if(Auth::isManager($wt_tree)) { |
||
| 122 | $default_user = User::find(-1); |
||
| 123 | $default_root_id = $wt_tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'); |
||
| 124 | $users_root[] = array( 'user' => $default_user, 'rootid' => $default_root_id); |
||
| 125 | $users_js_array .= 'users_array["'.$default_user->getUserId().'"] = "' . $default_root_id . '";'; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | $view_bag->set('users_settings', $users_root); |
||
| 129 | |||
| 130 | $controller->addInlineJavascript($users_js_array . ' |
||
| 131 | $("#maj-sosa-config-select").change(function() { |
||
| 132 | $("#rootid").val(users_array[this.value]); |
||
| 133 | }); |
||
| 134 | '); |
||
| 135 | |||
| 136 | ViewFactory::make('SosaConfig', $this, $controller, $view_bag)->render(); |
||
| 137 | } |
||
| 182 | } |