| Conditions | 21 |
| Paths | 2880 |
| Total Lines | 89 |
| Code Lines | 62 |
| 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 | function generateSmarty() |
||
| 82 | { |
||
| 83 | //get the selected language |
||
| 84 | $selected_lang = (!empty($_REQUEST['dropdown_lang'])?$_REQUEST['dropdown_lang']:$_SESSION['authenticated_user_language']); |
||
| 85 | $vardef = array(); |
||
| 86 | $package_name = 'studio'; |
||
| 87 | $package_strings = array(); |
||
| 88 | $new =false; |
||
| 89 | $my_list_strings = return_app_list_strings_language( $selected_lang ) ; |
||
| 90 | // $my_list_strings = $GLOBALS['app_list_strings']; |
||
| 91 | |||
| 92 | $smarty = new Sugar_Smarty(); |
||
| 93 | |||
| 94 | //if we are using ModuleBuilder then process the following |
||
| 95 | if(!empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio'){ |
||
| 96 | require_once('modules/ModuleBuilder/MB/ModuleBuilder.php'); |
||
| 97 | $mb = new ModuleBuilder(); |
||
| 98 | $module = $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']); |
||
| 99 | $package = $mb->packages[$_REQUEST['view_package']]; |
||
| 100 | $package_name = $package->name; |
||
| 101 | $module->getVardefs(); |
||
| 102 | if(empty($_REQUEST['dropdown_name']) && !empty($_REQUEST['field'])){ |
||
| 103 | $new = true; |
||
| 104 | $_REQUEST['dropdown_name'] = $_REQUEST['field']. '_list'; |
||
| 105 | } |
||
| 106 | |||
| 107 | $vardef = (!empty($module->mbvardefs->fields[$_REQUEST['dropdown_name']]))? $module->mbvardefs->fields[$_REQUEST['dropdown_name']]: array(); |
||
| 108 | $module->mblanguage->generateAppStrings(false) ; |
||
| 109 | $my_list_strings = array_merge( $my_list_strings, $module->mblanguage->appListStrings[$selected_lang.'.lang.php'] ); |
||
| 110 | $smarty->assign('module_name', $module->name); |
||
| 111 | } |
||
| 112 | |||
| 113 | $module_name = !empty($module->name) ? $module->name : ''; |
||
| 114 | $module_name = (empty($module_name) && !empty($_REQUEST['view_module'])) ? $_REQUEST['view_module'] : $module_name; |
||
| 115 | |||
| 116 | foreach($my_list_strings as $key=>$value){ |
||
| 117 | if(!is_array($value)){ |
||
| 118 | unset($my_list_strings[$key]); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | $dropdowns = array_keys($my_list_strings); |
||
| 123 | asort($dropdowns); |
||
| 124 | $keys = array_keys($dropdowns); |
||
| 125 | $first_string = $my_list_strings[$dropdowns[$keys[0]]]; |
||
| 126 | |||
| 127 | $name = ''; |
||
| 128 | $selected_dropdown = array(); |
||
| 129 | |||
| 130 | $json = getJSONobj(); |
||
| 131 | |||
| 132 | if(!empty($_REQUEST['dropdown_name']) && !$new){ |
||
| 133 | $name = $_REQUEST['dropdown_name']; |
||
| 134 | |||
| 135 | // handle the case where we've saved a dropdown in one language, and now attempt to edit it for another language. The $name exists, but $my_list_strings[$name] doesn't |
||
| 136 | // for now, we just treat it as if it was new. A better approach might be to use the first language version as a template for future languages |
||
| 137 | if (!isset($my_list_strings[$name])) |
||
| 138 | $my_list_strings[$name] = array () ; |
||
| 139 | |||
| 140 | $selected_dropdown = (!empty($vardef['options']) && !empty($my_list_strings[$vardef['options']])) ? $my_list_strings[$vardef['options']] : $my_list_strings[$name]; |
||
| 141 | $smarty->assign('ul_list', 'list = '.$json->encode(array_keys($selected_dropdown))); |
||
| 142 | $smarty->assign('dropdown_name', (!empty($vardef['options']) ? $vardef['options'] : $_REQUEST['dropdown_name'])); |
||
| 143 | $smarty->assign('name', $_REQUEST['dropdown_name']); |
||
| 144 | $smarty->assign('options', $selected_dropdown); |
||
| 145 | }else{ |
||
| 146 | $smarty->assign('ul_list', 'list = {}'); |
||
| 147 | //we should try to find a name for this dropdown based on the field name. |
||
| 148 | $pre_pop_name = ''; |
||
| 149 | if(!empty($_REQUEST['field'])) |
||
| 150 | $pre_pop_name = $_REQUEST['field']; |
||
| 151 | //ensure this dropdown name does not already exist |
||
| 152 | $use_name = $pre_pop_name.'_list'; |
||
| 153 | for($i = 0; $i < 100; $i++){ |
||
| 154 | if(empty($my_list_strings[$use_name])) |
||
| 155 | break; |
||
| 156 | else |
||
| 157 | $use_name = $pre_pop_name.'_'.$i; |
||
| 158 | } |
||
| 159 | $smarty->assign('prepopulated_name', $use_name); |
||
| 160 | } |
||
| 161 | |||
| 162 | $smarty->assign('module_name', $module_name); |
||
| 163 | $smarty->assign('APP', $GLOBALS['app_strings']); |
||
| 164 | $smarty->assign('MOD', $GLOBALS['mod_strings']); |
||
| 165 | $smarty->assign('selected_lang', $selected_lang); |
||
| 166 | $smarty->assign('available_languages',get_languages()); |
||
| 167 | $smarty->assign('package_name', $package_name); |
||
| 168 | return $smarty; |
||
| 169 | } |
||
| 170 | } |