| Conditions | 25 |
| Paths | 19601 |
| Total Lines | 115 |
| Code Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 650 |
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 |
||
| 79 | function display($widget_data, $additionalFormFields = NULL, $nonbutton = false) |
||
| 80 | { |
||
| 81 | global $app_strings; |
||
| 82 | $initial_filter = ''; |
||
| 83 | |||
| 84 | $this->title = $this->getTitle(); |
||
| 85 | $this->accesskey = $this->getAccesskey(); |
||
| 86 | $this->value = $this->getDisplayName(); |
||
| 87 | |||
| 88 | if (is_array($this->button_properties)) { |
||
| 89 | if( isset($this->button_properties['title'])) { |
||
| 90 | $this->title = $app_strings[$this->button_properties['title']]; |
||
| 91 | } |
||
| 92 | if( isset($this->button_properties['accesskey'])) { |
||
| 93 | $this->accesskey = $app_strings[$this->button_properties['accesskey']]; |
||
| 94 | } |
||
| 95 | if( isset($this->button_properties['form_value'])) { |
||
| 96 | $this->value = $app_strings[$this->button_properties['form_value']]; |
||
| 97 | } |
||
| 98 | if( isset($this->button_properties['module'])) { |
||
| 99 | $this->module_name = $this->button_properties['module']; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | |||
| 104 | $focus = $widget_data['focus']; |
||
| 105 | if(ACLController::moduleSupportsACL($widget_data['module']) && !ACLController::checkAccess($widget_data['module'], 'list', true)){ |
||
| 106 | $button = ' <input type="button" name="' . $this->getWidgetId() . '" id="' . $this->getWidgetId() . '" class="button"' . "\n" |
||
| 107 | . ' title="' . $this->title . '"' |
||
| 108 | . ' value="' . $this->value . "\"\n" |
||
| 109 | .' disabled />'; |
||
| 110 | return $button; |
||
| 111 | } |
||
| 112 | |||
| 113 | //refresh the whole page after end of action? |
||
| 114 | $refresh_page = 0; |
||
| 115 | if(!empty($widget_data['subpanel_definition']->_instance_properties['refresh_page'])){ |
||
| 116 | $refresh_page = 1; |
||
| 117 | } |
||
| 118 | |||
| 119 | $subpanel_definition = $widget_data['subpanel_definition']; |
||
| 120 | $button_definition = $subpanel_definition->get_buttons(); |
||
| 121 | |||
| 122 | $subpanel_name = $subpanel_definition->get_name(); |
||
| 123 | if (empty($this->module_name)) { |
||
| 124 | $this->module_name = $subpanel_definition->get_module_name(); |
||
| 125 | } |
||
| 126 | $link_field_name = $subpanel_definition->get_data_source_name(true); |
||
| 127 | $popup_mode='Single'; |
||
| 128 | if(isset($widget_data['mode'])){ |
||
| 129 | $popup_mode=$widget_data['mode']; |
||
| 130 | } |
||
| 131 | if(isset($widget_data['initial_filter_fields'])){ |
||
| 132 | if (is_array($widget_data['initial_filter_fields'])) { |
||
| 133 | foreach ($widget_data['initial_filter_fields'] as $value=>$alias) { |
||
| 134 | if (isset($focus->$value) and !empty($focus->$value)) { |
||
| 135 | $initial_filter.="&".$alias . '='.urlencode($focus->$value); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | $create="true"; |
||
| 141 | if(isset($widget_data['create'])){ |
||
| 142 | $create=$widget_data['create']; |
||
| 143 | } |
||
| 144 | $return_module = $_REQUEST['module']; |
||
| 145 | $return_action = 'SubPanelViewer'; |
||
| 146 | $return_id = $_REQUEST['record']; |
||
| 147 | |||
| 148 | //field_to_name_array |
||
| 149 | $fton_array= array('id' => 'subpanel_id'); |
||
| 150 | if(isset($widget_data['field_to_name_array']) && is_array($widget_data['field_to_name_array'])){ |
||
| 151 | $fton_array=array_merge($fton_array,$widget_data['field_to_name_array']); |
||
| 152 | } |
||
| 153 | |||
| 154 | $return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel_name&record=$return_id&sugar_body_only=1"; |
||
| 155 | |||
| 156 | $popup_request_data = array( |
||
| 157 | 'call_back_function' => 'set_return_and_save_background', |
||
| 158 | 'form_name' => 'DetailView', |
||
| 159 | 'field_to_name_array' => $fton_array, |
||
| 160 | 'passthru_data' => array( |
||
| 161 | 'child_field' => $subpanel_name, |
||
| 162 | 'return_url' => urlencode($return_url), |
||
| 163 | 'link_field_name' => $link_field_name, |
||
| 164 | 'module_name' => $subpanel_name, |
||
| 165 | 'refresh_page'=>$refresh_page, |
||
| 166 | ), |
||
| 167 | ); |
||
| 168 | |||
| 169 | // bugfix #57850 add marketing_id to the request data to allow filtering based on it |
||
| 170 | if (!empty($_REQUEST['mkt_id'])) |
||
| 171 | { |
||
| 172 | $popup_request_data['passthru_data']['marketing_id'] = $_REQUEST['mkt_id']; |
||
| 173 | } |
||
| 174 | |||
| 175 | if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data'])) |
||
| 176 | { |
||
| 177 | $popup_request_data['passthru_data']= array_merge($popup_request_data['passthru_data'],$this->button_properties['add_to_passthru_data']); |
||
| 178 | } |
||
| 179 | |||
| 180 | if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data']['return_type'])) { |
||
| 181 | |||
| 182 | if ($this->button_properties['add_to_passthru_data']['return_type']=='report') { |
||
| 183 | $initial_filter = "&module_name=". urlencode($widget_data['module']); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | //acl_roles_users_selectuser_button |
||
| 187 | |||
| 188 | $json_encoded_php_array = $this->_create_json_encoded_popup_request($popup_request_data); |
||
| 189 | return ' <input type="button" name="' . $this->getWidgetId() . '" id="' . $this->getWidgetId() . '" class="button"' . "\n" |
||
| 190 | . ' title="' . $this->title . '"' |
||
| 191 | . ' value="' . $this->value . "\"\n" |
||
| 192 | . " onclick='open_popup(\"$this->module_name\",600,400,\"$initial_filter\",true,true,$json_encoded_php_array,\"$popup_mode\",$create);' />\n"; |
||
| 193 | } |
||
| 194 | |||
| 213 |