| Conditions | 18 |
| Paths | 4800 |
| Total Lines | 120 |
| Code Lines | 72 |
| 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 |
||
| 180 | function constructSmarty ($parser) |
||
| 181 | { |
||
| 182 | global $mod_strings; |
||
| 183 | $smarty = new Sugar_Smarty ( ) ; |
||
| 184 | $smarty->assign ( 'translate', true ) ; |
||
| 185 | $smarty->assign ( 'language', $parser->getLanguage () ) ; |
||
| 186 | |||
| 187 | $smarty->assign ( 'view', $this->editLayout ) ; |
||
| 188 | $smarty->assign ( 'module', "ModuleBuilder" ) ; |
||
| 189 | $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ; |
||
| 190 | $smarty->assign ( 'action', 'listViewSave' ) ; |
||
| 191 | $smarty->assign ( 'view_module', $this->editModule ) ; |
||
| 192 | if (!empty ( $this->subpanel ) ) |
||
| 193 | { |
||
| 194 | $smarty->assign ( 'subpanel', $this->subpanel ) ; |
||
| 195 | $smarty->assign ( 'subpanelLabel', $this->subpanelLabel ) ; |
||
| 196 | if (!$this->fromModuleBuilder) { |
||
| 197 | $subList = SubPanel::getModuleSubpanels ( $this->editModule); |
||
| 198 | $subRef = $subList[strtolower($this->subpanel)]; |
||
| 199 | $subTitleKey = !empty($subRef) ? $subRef : "LBL_" . strtoupper($this->subpanel) . "_SUBPANEL_TITLE"; |
||
| 200 | $subTitle = !empty($subRef) ? translate($subTitleKey, $this->editModule) : UCfirst($this->subpanel); |
||
| 201 | $smarty->assign ( 'subpanel_label', $subTitleKey ) ; |
||
| 202 | $smarty->assign ( 'subpanel_title', $subTitle ) ; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | $helpName = $this->subpanel ? 'subPanelEditor' : 'listViewEditor'; |
||
| 206 | $smarty->assign ( 'helpName', $helpName ) ; |
||
| 207 | $smarty->assign ( 'helpDefault', 'modify' ) ; |
||
| 208 | |||
| 209 | $smarty->assign ( 'title', $this->_constructTitle () ) ; |
||
| 210 | $groups = array ( ) ; |
||
| 211 | foreach ( $parser->columns as $column => $function ) |
||
| 212 | { |
||
| 213 | // update this so that each field has a properties set |
||
| 214 | // properties are name, value, title (optional) |
||
| 215 | $groups [ $GLOBALS [ 'mod_strings' ] [ $column ] ] = $parser->$function () ; // call the parser functions to populate the list view columns, by default 'default', 'available' and 'hidden' |
||
| 216 | } |
||
| 217 | foreach ( $groups as $groupKey => $group ) |
||
| 218 | { |
||
| 219 | foreach ( $group as $fieldKey => $field ) |
||
| 220 | { |
||
| 221 | if (isset ( $field [ 'width' ] )) |
||
| 222 | { |
||
| 223 | if (substr ( $field [ 'width' ], - 1, 1 ) == '%') |
||
| 224 | { |
||
| 225 | |||
| 226 | $groups [ $groupKey ] [ $fieldKey ] [ 'width' ] = substr ( $field [ 'width' ], 0, strlen ( $field [ 'width' ] ) - 1 ) ; |
||
| 227 | } |
||
| 228 | } |
||
| 229 | } |
||
| 230 | } |
||
| 231 | |||
| 232 | $smarty->assign ( 'groups', $groups ) ; |
||
| 233 | $smarty->assign('from_mb', $this->fromModuleBuilder); |
||
| 234 | |||
| 235 | global $image_path; |
||
| 236 | $imageSave = SugarThemeRegistry::current()->getImage('studio_save','',null,null,'.gif',$mod_strings['LBL_BTN_SAVE']) ; |
||
| 237 | |||
| 238 | // $imageHelp = SugarThemeRegistry::current()->getImage('help') ; |
||
| 239 | |||
| 240 | |||
| 241 | $history = $parser->getHistory () ; |
||
| 242 | |||
| 243 | $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")" ; |
||
| 244 | if ($this->subpanel) |
||
| 245 | $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->subpanel}\")" ; |
||
| 246 | |||
| 247 | $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'"; |
||
| 248 | if ($this->subpanel) |
||
| 249 | $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"{$this->subpanel}\")'"; |
||
| 250 | |||
| 251 | $buttons = array ( ) ; |
||
| 252 | $buttons [] = array ( 'id' =>'savebtn', 'name' => 'savebtn' , 'image' => $imageSave , 'text' => (! $this->fromModuleBuilder)?$GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVEPUBLISH' ]: $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ], 'actionScript' => "onclick='studiotabs.generateGroupForm(\"edittabs\");if (countListFields()==0) ModuleBuilder.layoutValidation.popup() ; else ModuleBuilder.handleSave(\"edittabs\" )'" ) ; |
||
| 253 | $buttons [] = array ( 'id' => 'spacer' , 'width' => '50px' ) ; |
||
| 254 | $buttons [] = array ( 'id' =>'historyBtn', 'name' => 'historyBtn' , 'text' => translate ( 'LBL_HISTORY' ) , 'actionScript' => "onclick='$histaction'" ) ; |
||
| 255 | $buttons [] = array ( 'id' => 'historyDefault' , 'name' => 'historyDefault', 'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 'actionScript' => $restoreAction ) ; |
||
| 256 | |||
| 257 | $smarty->assign ( 'buttons', $this->_buildImageButtons ( $buttons ) ) ; |
||
| 258 | |||
| 259 | $editImage = SugarThemeRegistry::current()->getImage('edit_inline','',null,null,'.gif',$mod_strings['LBL_EDIT']) ; |
||
| 260 | |||
| 261 | $smarty->assign ( 'editImage', $editImage ) ; |
||
| 262 | $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline','',null,null,'.gif',$mod_strings['LBL_MB_DELETE']) ; |
||
| 263 | |||
| 264 | $smarty->assign ( 'deleteImage', $deleteImage ) ; |
||
| 265 | $smarty->assign ( 'MOD', $GLOBALS [ 'mod_strings' ] ) ; |
||
| 266 | |||
| 267 | if ($this->fromModuleBuilder) |
||
| 268 | { |
||
| 269 | $smarty->assign ( 'MB', true ) ; |
||
| 270 | $smarty->assign ( 'view_package', $_REQUEST [ 'view_package' ] ) ; |
||
| 271 | $mb = new ModuleBuilder ( ) ; |
||
| 272 | $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $this->editModule ) ; |
||
| 273 | $smarty->assign('current_mod_strings', $module->getModStrings()); |
||
| 274 | if ($this->subpanel) |
||
| 275 | { |
||
| 276 | if (isset ( $_REQUEST [ 'local' ] )) |
||
| 277 | { |
||
| 278 | $smarty->assign ( 'local', '1' ) ; |
||
| 279 | } |
||
| 280 | $smarty->assign ( "subpanel", $this->subpanel ) ; |
||
| 281 | } else |
||
| 282 | { |
||
| 283 | $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ; |
||
| 284 | |||
| 285 | } |
||
| 286 | |||
| 287 | } else |
||
| 288 | { |
||
| 289 | if ($this->subpanel) |
||
| 290 | { |
||
| 291 | $smarty->assign ( "subpanel", "$this->subpanel" ) ; |
||
| 292 | } else |
||
| 293 | { |
||
| 294 | $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ; |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | return $smarty ; |
||
| 299 | } |
||
| 300 | |||
| 357 |