| Conditions | 16 |
| Paths | 1296 |
| Total Lines | 105 |
| Code Lines | 55 |
| 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 |
||
| 48 | function &_get_form($defines, $additionalFormFields = null, $asUrl = false) |
||
| 49 | { |
||
| 50 | global $app_strings; |
||
| 51 | global $currentModule; |
||
| 52 | |||
| 53 | $this->module="Calls"; |
||
| 54 | $this->subpanelDiv = "activities"; |
||
| 55 | |||
| 56 | // Create the additional form fields with real values if they were not passed in |
||
| 57 | if(empty($additionalFormFields) && $this->additional_form_fields) |
||
| 58 | { |
||
| 59 | foreach($this->additional_form_fields as $key=>$value) |
||
| 60 | { |
||
| 61 | if(!empty($defines['focus']->$value)) |
||
| 62 | { |
||
| 63 | $additionalFormFields[$key] = $defines['focus']->$value; |
||
| 64 | } |
||
| 65 | else |
||
| 66 | { |
||
| 67 | $additionalFormFields[$key] = ''; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | if(!empty($this->module)) |
||
| 73 | { |
||
| 74 | $defines['child_module_name'] = $this->module; |
||
| 75 | } |
||
| 76 | else |
||
| 77 | { |
||
| 78 | $defines['child_module_name'] = $defines['module']; |
||
| 79 | } |
||
| 80 | |||
| 81 | if(!empty($this->subpanelDiv)) |
||
| 82 | { |
||
| 83 | $defines['subpanelDiv'] = $this->subpanelDiv; |
||
| 84 | } |
||
| 85 | |||
| 86 | $defines['parent_bean_name'] = get_class( $defines['focus']); |
||
| 87 | |||
| 88 | $form = 'form' . $defines['child_module_name']; |
||
| 89 | $button = '<form onsubmit="return SUGAR.subpanelUtils.sendAndRetrieve(this.id, \'subpanel_' . strtolower($defines['subpanelDiv']) . '\', \'' . addslashes($app_strings['LBL_LOADING']) . '\');" action="index.php" method="post" name="form" id="form' . $form . "\">\n"; |
||
| 90 | |||
| 91 | //module_button is used to override the value of module name |
||
| 92 | $button .= "<input type='hidden' name='target_module' value='".$defines['child_module_name']."'>\n"; |
||
| 93 | $button .= "<input type='hidden' name='".strtolower($defines['parent_bean_name'])."_id' value='".$defines['focus']->id."'>\n"; |
||
| 94 | |||
| 95 | if(isset($defines['focus']->name)) |
||
| 96 | { |
||
| 97 | $button .= "<input type='hidden' name='".strtolower($defines['parent_bean_name'])."_name' value='".$defines['focus']->name."'>"; |
||
| 98 | } |
||
| 99 | |||
| 100 | $button .= '<input type="hidden" name="to_pdf" value="true" />'; |
||
| 101 | $button .= '<input type="hidden" name="tpl" value="QuickCreate.tpl" />'; |
||
| 102 | $button .= '<input type="hidden" name="return_module" value="' . $currentModule . "\" />\n"; |
||
| 103 | $button .= '<input type="hidden" name="return_action" value="' . $defines['action'] . "\" />\n"; |
||
| 104 | $button .= '<input type="hidden" name="return_id" value="' . $defines['focus']->id . "\" />\n"; |
||
| 105 | $button .= '<input type="hidden" name="record" value="" />'; |
||
| 106 | |||
| 107 | // TODO: move this out and get $additionalFormFields working properly |
||
| 108 | if(empty($additionalFormFields['parent_type'])) |
||
| 109 | { |
||
| 110 | if($defines['focus']->object_name=='Contact') { |
||
| 111 | $additionalFormFields['parent_type'] = 'Accounts'; |
||
| 112 | } |
||
| 113 | else { |
||
| 114 | $additionalFormFields['parent_type'] = $defines['focus']->module_dir; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | if(empty($additionalFormFields['parent_name'])) |
||
| 118 | { |
||
| 119 | if($defines['focus']->object_name=='Contact') { |
||
| 120 | $additionalFormFields['parent_name'] = $defines['focus']->account_name; |
||
| 121 | $additionalFormFields['account_name'] = $defines['focus']->account_name; |
||
| 122 | } |
||
| 123 | else { |
||
| 124 | $additionalFormFields['parent_name'] = $defines['focus']->name; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | if(empty($additionalFormFields['parent_id'])) |
||
| 128 | { |
||
| 129 | if($defines['focus']->object_name=='Contact') { |
||
| 130 | $additionalFormFields['parent_id'] = $defines['focus']->account_id; |
||
| 131 | $additionalFormFields['account_id'] = $defines['focus']->account_id; |
||
| 132 | } |
||
| 133 | else { |
||
| 134 | $additionalFormFields['parent_id'] = $defines['focus']->id; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | $button .= '<input type="hidden" name="action" value="SubpanelCreates" />' . "\n"; |
||
| 139 | $button .= '<input type="hidden" name="module" value="Home" />' . "\n"; |
||
| 140 | $button .= '<input type="hidden" name="target_action" value="QuickCreate" />' . "\n"; |
||
| 141 | |||
| 142 | // fill in additional form fields for all but action |
||
| 143 | foreach($additionalFormFields as $key => $value) |
||
| 144 | { |
||
| 145 | if($key != 'action') |
||
| 146 | { |
||
| 147 | $button .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />' . "\n"; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | $button .= getVersionedScript('include/SugarFields/Fields/Datetimecombo/Datetimecombo.js')."\n"; |
||
| 151 | return $button; |
||
| 152 | } |
||
| 153 | |||
| 165 |