| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 129 |
| Code Lines | 70 |
| 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 |
||
| 50 | function &_get_form($defines, $additionalFormFields = null, $asUrl = false) |
||
| 51 | { |
||
| 52 | global $app_strings; |
||
| 53 | global $currentModule; |
||
| 54 | |||
| 55 | // Create the additional form fields with real values if they were not passed in |
||
| 56 | if(empty($additionalFormFields) && $this->additional_form_fields) |
||
| 57 | { |
||
| 58 | foreach($this->additional_form_fields as $key=>$value) |
||
| 59 | { |
||
| 60 | if(!empty($defines['focus']->$value)) |
||
| 61 | { |
||
| 62 | $additionalFormFields[$key] = $defines['focus']->$value; |
||
| 63 | } |
||
| 64 | else |
||
| 65 | { |
||
| 66 | $additionalFormFields[$key] = ''; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | if(!empty($this->module)) |
||
| 72 | { |
||
| 73 | $defines['child_module_name'] = $this->module; |
||
| 74 | } |
||
| 75 | else |
||
| 76 | { |
||
| 77 | $defines['child_module_name'] = $defines['module']; |
||
| 78 | } |
||
| 79 | |||
| 80 | $defines['parent_bean_name'] = get_class( $defines['focus']); |
||
| 81 | |||
| 82 | $relationship_name = $this->get_subpanel_relationship_name($defines); |
||
| 83 | |||
| 84 | $form = 'form' . $relationship_name; |
||
| 85 | $button = '<form onsubmit="return SUGAR.subpanelUtils.sendAndRetrieve(this.id, \'subpanel_' . $defines['subpanel_definition']->name . '\', \'' . addslashes($app_strings['LBL_LOADING']) . '\');" action="index.php" method="post" name="form" id="form' . $form . "\">\n"; |
||
| 86 | |||
| 87 | //module_button is used to override the value of module name |
||
| 88 | $button .= "<input type='hidden' name='target_module' value='".$defines['child_module_name']."'>\n"; |
||
| 89 | $button .= "<input type='hidden' name='".strtolower($defines['parent_bean_name'])."_id' value='".$defines['focus']->id."'>\n"; |
||
| 90 | |||
| 91 | if(isset($defines['focus']->name)) |
||
| 92 | { |
||
| 93 | $button .= "<input type='hidden' name='".strtolower($defines['parent_bean_name'])."_name' value='".$defines['focus']->name."'>"; |
||
| 94 | #26451,add these fields for custom one-to-many relate field. |
||
| 95 | if(!empty($defines['child_module_name'])){ |
||
| 96 | $button .= "<input type='hidden' name='". $relationship_name ."_name' value='".$defines['focus']->name."'>"; |
||
| 97 | $childFocusName = !empty($GLOBALS['beanList'][$defines['child_module_name']]) ? $GLOBALS['beanList'][$defines['child_module_name']] : ""; |
||
| 98 | if(!empty($GLOBALS['dictionary'][ $childFocusName ]["fields"][$relationship_name .'_name']['id_name'])){ |
||
| 99 | $button .= "<input type='hidden' name='". $GLOBALS['dictionary'][ $childFocusName ]["fields"][$relationship_name .'_name']['id_name'] ."' value='".$defines['focus']->id."'>"; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | //Set the return_name form variable that will allow EditView2.php |
||
| 104 | $additionalFormFields['return_name'] = $defines['focus']->name; |
||
| 105 | } |
||
| 106 | |||
| 107 | if(!empty($defines['view'])) |
||
| 108 | $button .= '<input type="hidden" name="target_view" value="'. $defines['view'] . '" />'; |
||
| 109 | $button .= '<input type="hidden" name="to_pdf" value="true" />'; |
||
| 110 | $button .= '<input type="hidden" name="tpl" value="QuickCreate.tpl" />'; |
||
| 111 | $button .= '<input type="hidden" name="return_module" value="' . $currentModule . "\" />\n"; |
||
| 112 | $button .= '<input type="hidden" name="return_action" value="' . $defines['action'] . "\" />\n"; |
||
| 113 | $button .= '<input type="hidden" name="return_id" value="' . $defines['focus']->id . "\" />\n"; |
||
| 114 | $button .= '<input type="hidden" name="return_relationship" value="' . $relationship_name . "\" />\n"; |
||
| 115 | $button .= '<input type="hidden" name="record" value="" />'; |
||
| 116 | |||
| 117 | // TODO: move this out and get $additionalFormFields working properly |
||
| 118 | if(empty($additionalFormFields['parent_type'])) |
||
| 119 | { |
||
| 120 | if($defines['focus']->object_name=='Contact') { |
||
| 121 | $additionalFormFields['parent_type'] = 'Accounts'; |
||
| 122 | } |
||
| 123 | else { |
||
| 124 | $additionalFormFields['parent_type'] = $defines['focus']->module_dir; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | if(empty($additionalFormFields['parent_name'])) |
||
| 128 | { |
||
| 129 | if($defines['focus']->object_name=='Contact') { |
||
| 130 | $additionalFormFields['parent_name'] = $defines['focus']->account_name; |
||
| 131 | $additionalFormFields['account_name'] = $defines['focus']->account_name; |
||
| 132 | } |
||
| 133 | else { |
||
| 134 | $additionalFormFields['parent_name'] = $defines['focus']->name; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | if(empty($additionalFormFields['parent_id'])) |
||
| 138 | { |
||
| 139 | if($defines['focus']->object_name=='Contact') { |
||
| 140 | $additionalFormFields['parent_id'] = $defines['focus']->account_id; |
||
| 141 | $additionalFormFields['account_id'] = $defines['focus']->account_id; |
||
| 142 | } |
||
| 143 | else { |
||
| 144 | $additionalFormFields['parent_id'] = $defines['focus']->id; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | if(strtolower($defines['child_module_name']) =='contracts') { |
||
| 149 | //set variables to account name, or parent account name |
||
| 150 | if(strtolower($defines['parent_bean_name']) == 'account' ){ |
||
| 151 | //if account is parent bean, then get focus id/focus name |
||
| 152 | if(isset($defines['focus']->id))$additionalFormFields['account_id'] = $defines['focus']->id; |
||
| 153 | if(isset($defines['focus']->name))$additionalFormFields['account_name'] = $defines['focus']->name; |
||
| 154 | }elseif(strtolower($defines['parent_bean_name']) == 'quote' ){ |
||
| 155 | //if quote is parent bean, then get billing_account_id/billing_account_name |
||
| 156 | if(isset($defines['focus']->billing_account_id))$additionalFormFields['account_id'] = $defines['focus']->billing_account_id; |
||
| 157 | if(isset($defines['focus']->billing_account_name))$additionalFormFields['account_name'] = $defines['focus']->billing_account_name; |
||
| 158 | }else{ |
||
| 159 | if(isset($defines['focus']->account_id))$additionalFormFields['account_id'] = $defines['focus']->account_id; |
||
| 160 | if(isset($defines['focus']->account_name))$additionalFormFields['account_name'] = $defines['focus']->account_name; |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | $button .= '<input type="hidden" name="action" value="SubpanelCreates" />' . "\n"; |
||
| 165 | $button .= '<input type="hidden" name="module" value="Home" />' . "\n"; |
||
| 166 | $button .= '<input type="hidden" name="target_action" value="QuickCreate" />' . "\n"; |
||
| 167 | |||
| 168 | // fill in additional form fields for all but action |
||
| 169 | foreach($additionalFormFields as $key => $value) |
||
| 170 | { |
||
| 171 | if($key != 'action') |
||
| 172 | { |
||
| 173 | $button .= '<input type="hidden" name="' . $key . '" value=\'' . $value . '\' />' . "\n"; |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | return $button; |
||
| 178 | } |
||
| 179 | |||
| 204 |