| Conditions | 12 |
| Paths | 192 |
| Total Lines | 155 |
| 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 |
||
| 108 | public function getCMSFields() |
||
| 109 | { |
||
| 110 | $fields = parent::getCMSFields(); |
||
| 111 | |||
| 112 | $emailsSentField = $fields->dataFieldByName('EmailsSent'); |
||
| 113 | $fields->removeFieldFromTab('Root', 'EmailsSent'); |
||
| 114 | |||
| 115 | $disableLabel = $this->Config()->get('disabled_checkbox_label'); |
||
| 116 | $fields->addFieldToTab( |
||
| 117 | 'Root.Main', |
||
| 118 | CheckboxField::create('Disable', $disableLabel)->setDescription("If checked this email will not be sent during the daily mail out, however it can still be sent programatically") |
||
| 119 | ); |
||
| 120 | $fields->addFieldToTab( |
||
| 121 | 'Root.Main', |
||
| 122 | $dataObjecField = DropdownField::create( |
||
| 123 | 'DataObject', |
||
| 124 | 'Table/Class Name', |
||
| 125 | $this->dataObjectOptions() |
||
| 126 | ) |
||
| 127 | ->setRightTitle('Type a valid table/class name') |
||
| 128 | ); |
||
| 129 | if ($this->Config()->get('default_data_object')) { |
||
| 130 | $fields->replaceField('DataObject', $dataObjecField->performReadonlyTransformation()); |
||
| 131 | } |
||
| 132 | |||
| 133 | |||
| 134 | |||
| 135 | $fields->addFieldToTab( |
||
| 136 | 'Root.Main', |
||
| 137 | $emailFieldField = DropdownField::create( |
||
| 138 | 'EmailField', |
||
| 139 | 'Email Field', |
||
| 140 | $this->emailFieldOptions() |
||
| 141 | ) |
||
| 142 | ->setRightTitle('Select the field that will contain a valid email address') |
||
| 143 | ->setEmptyString('[ Please select ]') |
||
| 144 | ); |
||
| 145 | if ($this->Config()->get('default_email_field')) { |
||
| 146 | $fields->replaceField('EmailField', $emailFieldField->performReadonlyTransformation()); |
||
| 147 | } |
||
| 148 | |||
| 149 | $fields->addFieldToTab( |
||
| 150 | 'Root.Main', |
||
| 151 | $dateFieldField = DropdownField::create( |
||
| 152 | 'DateField', |
||
| 153 | 'Date Field', |
||
| 154 | $this->dateFieldOptions() |
||
| 155 | ) |
||
| 156 | ->setRightTitle('Select a valid Date field to calculate when reminders should be sent') |
||
| 157 | ->setEmptyString('[ Please select ]') |
||
| 158 | ); |
||
| 159 | if ($this->Config()->get('default_date_field')) { |
||
| 160 | $fields->replaceField('DateField', $dateFieldField->performReadonlyTransformation()); |
||
| 161 | } |
||
| 162 | |||
| 163 | $fields->removeFieldsFromTab( |
||
| 164 | 'Root.Main', |
||
| 165 | array('Days', 'BeforeAfter', 'RepeatDays') |
||
| 166 | ); |
||
| 167 | $fields->addFieldsToTab( |
||
| 168 | 'Root.Main', |
||
| 169 | array( |
||
| 170 | DropdownField::create('BeforeAfter', 'Before / After Expiration', array('before' => 'before', 'after' => 'after', 'immediately' => 'immediately')) |
||
| 171 | ->setRightTitle('Are the days listed above before or after the actual expiration date.'), |
||
| 172 | NumericField::create('Days', 'Days') |
||
| 173 | ->setRightTitle('How many days in advance (before) or in arrears (after) of the expiration date should this email be sent? </br>This field is ignored if set to send immediately.'), |
||
| 174 | NumericField::create('RepeatDays', 'Repeat Cycle Days') |
||
| 175 | ->setRightTitle( |
||
| 176 | ' |
||
| 177 | Number of days after which the same reminder can be sent to the same email address. |
||
| 178 | <br />We allow an e-mail to be sent to one specific email address for one specific reminder only once. |
||
| 179 | <br />In this field you can indicate for how long we will apply this rule.' |
||
| 180 | ) |
||
| 181 | ) |
||
| 182 | ); |
||
| 183 | |||
| 184 | if ($this->BeforeAfter === 'immediately') { |
||
| 185 | $fields->removeFieldsFromTab( |
||
| 186 | 'Root.Main', |
||
| 187 | array('Days', 'RepeatDays') |
||
| 188 | ); |
||
| 189 | } |
||
| 190 | |||
| 191 | $fields->addFieldsToTab( |
||
| 192 | 'Root.EmailContent', |
||
| 193 | array( |
||
| 194 | TextField::create('EmailFrom', 'Email From Address') |
||
| 195 | ->setRightTitle('The email from address, eg: "My Company <[email protected]>"'), |
||
| 196 | $subjectField = TextField::create('EmailSubject', 'Email Subject Line') |
||
| 197 | ->setRightTitle('The subject of the email'), |
||
| 198 | $contentField = HTMLEditorField::create('Content', 'Email Content') |
||
| 199 | ->SetRows(20) |
||
| 200 | ) |
||
| 201 | ); |
||
| 202 | if ($obj = $this->getReplacerObject()) { |
||
| 203 | $html = $obj->replaceHelpList($asHTML = true); |
||
| 204 | $otherFieldsThatCanBeUsed = $this->getFieldsFromDataObject(array('*')); |
||
| 205 | $replaceableFields = $this->Config()->get('replaceable_record_fields'); |
||
| 206 | if (count($otherFieldsThatCanBeUsed)) { |
||
| 207 | $html .= '<h3>You can also use the record fields (not replaced in tests):</h3><ul>'; |
||
| 208 | foreach ($otherFieldsThatCanBeUsed as $key => $value) { |
||
| 209 | if (in_array($key, $replaceableFields)) { |
||
| 210 | $html .= '<li><strong>$'.$key.'</strong> <span>'.$value.'</span></li>'; |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | $html .= '</ul>'; |
||
| 215 | $subjectField->setRightTitle('for replacement options, please see below ...'); |
||
| 216 | $contentField->setRightTitle($html); |
||
| 217 | } |
||
| 218 | $fields->addFieldsToTab( |
||
| 219 | 'Root.Sent', |
||
| 220 | array( |
||
| 221 | TextareaField::create('SendTestTo', 'Send test email to ...') |
||
| 222 | ->setRightTitle( |
||
| 223 | ' |
||
| 224 | Separate emails by commas, a test email will be sent every time you save this Email Reminder, if you do not want test emails to be sent make sure this field is empty |
||
| 225 | ' |
||
| 226 | ) |
||
| 227 | ->SetRows(3) |
||
| 228 | ) |
||
| 229 | ); |
||
| 230 | if ($emailsSentField) { |
||
| 231 | $config = $emailsSentField->getConfig(); |
||
| 232 | $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
||
| 233 | $fields->addFieldToTab( |
||
| 234 | 'Root.Sent', |
||
| 235 | $emailsSentField |
||
| 236 | ); |
||
| 237 | } |
||
| 238 | $records = $this->CurrentRecords(); |
||
| 239 | if ($records && !$this->Disable) { |
||
| 240 | $fields->addFieldsToTab( |
||
| 241 | 'Root.Review', |
||
| 242 | array( |
||
| 243 | GridField::create( |
||
| 244 | 'CurrentRecords', |
||
| 245 | 'Today we are sending to ...', |
||
| 246 | $records |
||
| 247 | ), |
||
| 248 | LiteralField::create( |
||
| 249 | 'SampleSelectStatement', |
||
| 250 | '<h3>Here is a sample statement used to select records:</h3> |
||
| 251 | <pre>'.$this->whereStatementForDays().'</pre>' |
||
| 252 | ), |
||
| 253 | LiteralField::create( |
||
| 254 | 'SampleFieldDataForRecords', |
||
| 255 | '<h3>sample of '.$this->DateField.' field values:</h3> |
||
| 256 | <li>'.implode('</li><li>', $this->SampleFieldDataForRecords()).'</li>' |
||
| 257 | ) |
||
| 258 | ) |
||
| 259 | ); |
||
| 260 | } |
||
| 261 | return $fields; |
||
| 262 | } |
||
| 263 | |||
| 569 |