| Conditions | 75 |
| Paths | > 20000 |
| Total Lines | 263 |
| Code Lines | 150 |
| 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 |
||
| 40 | function getEditFieldHTML($module, $fieldname, $aow_field, $view = 'EditView', $id = '', $alt_type = '', $currency_id = '') |
||
| 41 | { |
||
| 42 | |||
| 43 | global $current_language, $app_strings, $app_list_strings, $current_user, $beanFiles, $beanList; |
||
| 44 | |||
| 45 | $bean = BeanFactory::getBean($module,$id); |
||
| 46 | |||
| 47 | if(!checkAccess($bean)){ |
||
| 48 | return false; |
||
| 49 | } |
||
| 50 | |||
| 51 | |||
| 52 | $value = getFieldValueFromModule($fieldname, $module, $id); |
||
| 53 | // use the mod_strings for this module |
||
| 54 | $mod_strings = return_module_language($current_language, $module); |
||
| 55 | |||
| 56 | // set the filename for this control |
||
| 57 | $file = create_cache_directory('include/InlineEditing/') . $module . $view . $alt_type . $fieldname . '.tpl'; |
||
| 58 | |||
| 59 | if (!is_file($file) |
||
| 60 | || inDeveloperMode() |
||
| 61 | || !empty($_SESSION['developerMode']) |
||
| 62 | ) { |
||
| 63 | |||
| 64 | if (!isset($vardef)) { |
||
|
|
|||
| 65 | require_once($beanFiles[$beanList[$module]]); |
||
| 66 | $focus = new $beanList[$module]; |
||
| 67 | $vardef = $focus->getFieldDefinition($fieldname); |
||
| 68 | } |
||
| 69 | |||
| 70 | $displayParams = array(); |
||
| 71 | //$displayParams['formName'] = 'EditView'; |
||
| 72 | |||
| 73 | // if this is the id relation field, then don't have a pop-up selector. |
||
| 74 | if ($vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) { |
||
| 75 | $vardef['type'] = 'varchar'; |
||
| 76 | } |
||
| 77 | |||
| 78 | if (isset($vardef['precision'])) unset($vardef['precision']); |
||
| 79 | |||
| 80 | //$vardef['precision'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user); |
||
| 81 | |||
| 82 | //TODO Fix datetimecomebo |
||
| 83 | //temp work around |
||
| 84 | if ($vardef['type'] == 'datetime') { |
||
| 85 | $vardef['type'] = 'datetimecombo'; |
||
| 86 | } |
||
| 87 | |||
| 88 | // trim down textbox display |
||
| 89 | if ($vardef['type'] == 'text') { |
||
| 90 | $vardef['rows'] = 2; |
||
| 91 | $vardef['cols'] = 32; |
||
| 92 | } |
||
| 93 | |||
| 94 | // create the dropdowns for the parent type fields |
||
| 95 | if ($vardef['type'] == 'parent_type') { |
||
| 96 | $vardef['type'] = 'enum'; |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($vardef['type'] == 'link') { |
||
| 100 | $vardef['type'] = 'relate'; |
||
| 101 | $vardef['rname'] = 'name'; |
||
| 102 | $vardef['id_name'] = $vardef['name'] . '_id'; |
||
| 103 | if ((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) { |
||
| 104 | $vardef['module'] = $focus->{$vardef['name']}->getRelatedModuleName(); |
||
| 105 | } |
||
| 106 | |||
| 107 | } |
||
| 108 | |||
| 109 | //check for $alt_type |
||
| 110 | if ($alt_type != '') { |
||
| 111 | $vardef['type'] = $alt_type; |
||
| 112 | } |
||
| 113 | |||
| 114 | // remove the special text entry field function 'getEmailAddressWidget' |
||
| 115 | if (isset($vardef['function']) |
||
| 116 | && ($vardef['function'] == 'getEmailAddressWidget' |
||
| 117 | || $vardef['function']['name'] == 'getEmailAddressWidget') |
||
| 118 | ) |
||
| 119 | unset($vardef['function']); |
||
| 120 | |||
| 121 | if (isset($vardef['name']) && ($vardef['name'] == 'date_modified')) { |
||
| 122 | $vardef['name'] = 'aow_temp_date'; |
||
| 123 | } |
||
| 124 | |||
| 125 | // load SugarFieldHandler to render the field tpl file |
||
| 126 | static $sfh; |
||
| 127 | |||
| 128 | if (!isset($sfh)) { |
||
| 129 | require_once('include/SugarFields/SugarFieldHandler.php'); |
||
| 130 | $sfh = new SugarFieldHandler(); |
||
| 131 | } |
||
| 132 | |||
| 133 | $contents = $sfh->displaySmarty('fields', $vardef, $view, $displayParams); |
||
| 134 | |||
| 135 | // Remove all the copyright comments |
||
| 136 | $contents = preg_replace('/\{\*[^\}]*?\*\}/', '', $contents); |
||
| 137 | // remove extra wrong javascript which breaks auto complete on flexi relationship parent fields |
||
| 138 | $contents = preg_replace("/<script language=\"javascript\">if\(typeof sqs_objects == \'undefined\'\){var sqs_objects = new Array;}sqs_objects\[\'EditView_parent_name\'\].*?<\/script>/","",$contents); |
||
| 139 | |||
| 140 | |||
| 141 | if ($view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')) { |
||
| 142 | |||
| 143 | $contents = str_replace('"' . $vardef['id_name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.id_name}"{literal}', $contents); |
||
| 144 | $contents = str_replace('"' . $vardef['name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.name}"{literal}', $contents); |
||
| 145 | // regex below fixes button javascript for flexi relationship |
||
| 146 | if($vardef['type'] == 'parent') { |
||
| 147 | $contents = str_replace("onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"{\$fields.parent_name.id_name}", "onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"parent_id", $contents); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | // hack to disable one of the js calls in this control |
||
| 152 | if (isset($vardef['function']) && ($vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown')) |
||
| 153 | $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}"; |
||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | // Save it to the cache file |
||
| 158 | if ($fh = @sugar_fopen($file, 'w')) { |
||
| 159 | fputs($fh, $contents); |
||
| 160 | fclose($fh); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | // Now render the template we received |
||
| 165 | $ss = new Sugar_Smarty(); |
||
| 166 | |||
| 167 | // Create Smarty variables for the Calendar picker widget |
||
| 168 | global $timedate; |
||
| 169 | $time_format = $timedate->get_user_time_format(); |
||
| 170 | $date_format = $timedate->get_cal_date_format(); |
||
| 171 | $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format()); |
||
| 172 | $ss->assign('TIME_FORMAT', $time_format); |
||
| 173 | $time_separator = ":"; |
||
| 174 | $match = array(); |
||
| 175 | if (preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) { |
||
| 176 | $time_separator = $match[1]; |
||
| 177 | } |
||
| 178 | $t23 = strpos($time_format, '23') !== false ? '%H' : '%I'; |
||
| 179 | if (!isset($match[2]) || $match[2] == '') { |
||
| 180 | $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M"); |
||
| 181 | } else { |
||
| 182 | $pm = $match[2] == "pm" ? "%P" : "%p"; |
||
| 183 | $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm); |
||
| 184 | } |
||
| 185 | |||
| 186 | $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week()); |
||
| 187 | |||
| 188 | $fieldlist = array(); |
||
| 189 | if (!isset($focus) || !($focus instanceof SugarBean)) |
||
| 190 | require_once($beanFiles[$beanList[$module]]); |
||
| 191 | $focus = new $beanList[$module]; |
||
| 192 | // create the dropdowns for the parent type fields |
||
| 193 | $vardefFields[$fieldname] = $focus->field_defs[$fieldname]; |
||
| 194 | if ($vardefFields[$fieldname]['type'] == 'parent') { |
||
| 195 | $focus->field_defs[$fieldname]['options'] = $focus->field_defs[$vardefFields[$fieldname]['group']]['options']; |
||
| 196 | } |
||
| 197 | foreach ($vardefFields as $name => $properties) { |
||
| 198 | $fieldlist[$name] = $properties; |
||
| 199 | // fill in enums |
||
| 200 | if (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) |
||
| 201 | $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']]; |
||
| 202 | // Bug 32626: fall back on checking the mod_strings if not in the app_list_strings |
||
| 203 | elseif (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) |
||
| 204 | $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']]; |
||
| 205 | } |
||
| 206 | |||
| 207 | // fill in function return values |
||
| 208 | if (!in_array($fieldname, array('email1', 'email2'))) { |
||
| 209 | if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html') { |
||
| 210 | $function = $fieldlist[$fieldname]['function']['name']; |
||
| 211 | // include various functions required in the various vardefs |
||
| 212 | if (isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) |
||
| 213 | require_once($fieldlist[$fieldname]['function']['include']); |
||
| 214 | $_REQUEST[$fieldname] = $value; |
||
| 215 | $value = $function($focus, $fieldname, $value, $view); |
||
| 216 | |||
| 217 | $value = str_ireplace($fieldname, $aow_field, $value); |
||
| 218 | } |
||
| 219 | } |
||
| 220 | |||
| 221 | if ($fieldlist[$fieldname]['type'] == 'link') { |
||
| 222 | $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'] . '_id'; |
||
| 223 | |||
| 224 | if ((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) { |
||
| 225 | $relateField = $fieldlist[$fieldname]['name']; |
||
| 226 | $fieldlist[$fieldname]['module'] = $focus->$relateField->getRelatedModuleName(); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | if($fieldlist[$fieldname]['type'] == 'parent'){ |
||
| 231 | $fieldlist['parent_id']['name'] = 'parent_id'; |
||
| 232 | } |
||
| 233 | |||
| 234 | if (isset($fieldlist[$fieldname]['name']) && ($fieldlist[$fieldname]['name'] == 'date_modified')) { |
||
| 235 | $fieldlist[$fieldname]['name'] = 'aow_temp_date'; |
||
| 236 | $fieldlist['aow_temp_date'] = $fieldlist[$fieldname]; |
||
| 237 | $fieldname = 'aow_temp_date'; |
||
| 238 | } |
||
| 239 | |||
| 240 | if (isset($fieldlist[$fieldname]['id_name']) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']) { |
||
| 241 | if($value){ |
||
| 242 | $relateIdField = $fieldlist[$fieldname]['id_name']; |
||
| 243 | $rel_value = $bean->$relateIdField; |
||
| 244 | |||
| 245 | } |
||
| 246 | $fieldlist[$fieldlist[$fieldname]['id_name']]['value'] = $rel_value; |
||
| 247 | $fieldlist[$fieldname]['value'] = $value; |
||
| 248 | $fieldlist[$fieldname]['id_name'] = $aow_field; |
||
| 249 | $fieldlist[$fieldname]['name'] = $aow_field . '_display'; |
||
| 250 | } else if (isset($fieldlist[$fieldname]['type']) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime')) { |
||
| 251 | $value = $focus->convertField($value, $fieldlist[$fieldname]); |
||
| 252 | if (!$value) { |
||
| 253 | $value = date($timedate->get_date_time_format()); |
||
| 254 | } |
||
| 255 | $fieldlist[$fieldname]['name'] = $aow_field; |
||
| 256 | $fieldlist[$fieldname]['value'] = $value; |
||
| 257 | } else if (isset($fieldlist[$fieldname]['type']) && ($fieldlist[$fieldname]['type'] == 'date')) { |
||
| 258 | $value = $focus->convertField($value, $fieldlist[$fieldname]); |
||
| 259 | $fieldlist[$fieldname]['name'] = $aow_field; |
||
| 260 | if (empty($value) == "") { |
||
| 261 | $value = str_replace("%", "", date($date_format)); |
||
| 262 | } |
||
| 263 | $fieldlist[$fieldname]['value'] = $value; |
||
| 264 | } else { |
||
| 265 | $fieldlist[$fieldname]['value'] = $value; |
||
| 266 | $fieldlist[$fieldname]['name'] = $aow_field; |
||
| 267 | |||
| 268 | } |
||
| 269 | |||
| 270 | if ($fieldlist[$fieldname]['type'] == 'currency' && $view != 'EditView') { |
||
| 271 | static $sfh; |
||
| 272 | |||
| 273 | if (!isset($sfh)) { |
||
| 274 | require_once('include/SugarFields/SugarFieldHandler.php'); |
||
| 275 | $sfh = new SugarFieldHandler(); |
||
| 276 | } |
||
| 277 | |||
| 278 | if ($currency_id != '' && !stripos($fieldname, '_USD')) { |
||
| 279 | $userCurrencyId = $current_user->getPreference('currency'); |
||
| 280 | if ($currency_id != $userCurrencyId) { |
||
| 281 | $currency = new Currency(); |
||
| 282 | $currency->retrieve($currency_id); |
||
| 283 | $value = $currency->convertToDollar($value); |
||
| 284 | $currency->retrieve($userCurrencyId); |
||
| 285 | $value = $currency->convertFromDollar($value); |
||
| 286 | } |
||
| 287 | } |
||
| 288 | |||
| 289 | $parentfieldlist[strtoupper($fieldname)] = $value; |
||
| 290 | |||
| 291 | return ($sfh->displaySmarty($parentfieldlist, $fieldlist[$fieldname], 'ListView', $displayParams)); |
||
| 292 | } |
||
| 293 | |||
| 294 | $ss->assign("fields", $fieldlist); |
||
| 295 | $ss->assign("form_name", $view); |
||
| 296 | $ss->assign("bean", $focus); |
||
| 297 | |||
| 298 | $ss->assign("MOD", $mod_strings); |
||
| 299 | $ss->assign("APP", $app_strings); |
||
| 300 | |||
| 301 | return json_encode($ss->fetch($file)); |
||
| 302 | } |
||
| 303 | |||
| 520 |
This check marks calls to
isset(...)orempty(...)that are found before the variable itself is defined. These will always have the same result.This is likely the result of code being shifted around. Consider removing these calls.