X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FAdmin%2FForm%2FPreferences%2FContribute.php;h=6fc6b26d50164f7fdd9d2d9a476624291e2bc410;hb=780c8f48c69ad81040949dab1ddb58240b97315b;hp=f650ec51de4b96a855e580c1b2d4c114872b9f9c;hpb=fee14197b427c1781e369e5bfd36816afad6d7ee;p=civicrm-core.git diff --git a/CRM/Admin/Form/Preferences/Contribute.php b/CRM/Admin/Form/Preferences/Contribute.php index f650ec51de..6fc6b26d50 100644 --- a/CRM/Admin/Form/Preferences/Contribute.php +++ b/CRM/Admin/Form/Preferences/Contribute.php @@ -46,127 +46,127 @@ class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences { ); /** - * Process the form submission. + * Our standards for settings are to have a setting per value with defined metadata. + * + * Unfortunately the 'contribution_invoice_settings' has been added in non-compliance. + * We use this array to hack-handle. + * + * I think the best way forwards would be to covert to multiple individual settings. + * + * @var array */ - public function preProcess() { - $config = CRM_Core_Config::singleton(); - CRM_Utils_System::setTitle(ts('CiviContribute Component Settings')); - $this->_varNames = array( - CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME => array( - 'invoice_prefix' => array( - 'html_type' => 'text', - 'title' => ts('Invoice Prefix'), - 'weight' => 1, - 'description' => ts('Enter prefix to be display on PDF for invoice'), - ), - 'credit_notes_prefix' => array( - 'html_type' => 'text', - 'title' => ts('Credit Notes Prefix'), - 'weight' => 2, - 'description' => ts('Enter prefix to be display on PDF for credit notes.'), - ), - 'due_date' => array( - 'html_type' => 'text', - 'title' => ts('Due Date'), - 'weight' => 3, - ), - 'due_date_period' => array( - 'html_type' => 'select', - 'title' => ts('For transmission'), - 'weight' => 4, - 'description' => ts('Select the interval for due date.'), - 'option_values' => array( - 'select' => ts('- select -'), - 'days' => ts('Days'), - 'months' => ts('Months'), - 'years' => ts('Years'), - ), - ), - 'notes' => array( - 'html_type' => 'wysiwyg', - 'title' => ts('Notes or Standard Terms'), - 'weight' => 5, - 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '), - 'attributes' => array('rows' => 2, 'cols' => 40), - ), - 'is_email_pdf' => array( - 'html_type' => 'checkbox', - 'title' => ts('Automatically email invoice when user purchases online'), - 'weight' => 6, - ), - 'tax_term' => array( - 'html_type' => 'text', - 'title' => ts('Tax Term'), - 'weight' => 7, - ), - 'tax_display_settings' => array( - 'html_type' => 'select', - 'title' => ts('Tax Display Settings'), - 'weight' => 8, - 'option_values' => array( - 'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' . - $config->defaultCurrencySymbol . '120.00'), - 'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' . - $config->defaultCurrencySymbol . - '120.00 (includes [tax term] of ' . - $config->defaultCurrencySymbol . '20.00)'), - 'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' . - $config->defaultCurrencySymbol . '100.00 + ' . - $config->defaultCurrencySymbol . '20.00 [tax term]'), - ), - ), - ), - ); - parent::preProcess(); - } + protected $invoiceSettings = []; /** * Build the form object. */ public function buildQuickForm() { - $htmlFields = array(); - foreach ($this->_settings as $setting => $group) { - $settingMetaData = civicrm_api3('setting', 'getfields', array('name' => $setting)); - $props = $settingMetaData['values'][$setting]; - if (isset($props['quick_form_type'])) { - $add = 'add' . $props['quick_form_type']; - if ($add == 'addElement') { - if (in_array($props['html_type'], array('checkbox', 'textarea'))) { - $this->add($props['html_type'], - $setting, - $props['title'] - ); - } - else { - if ($props['html_type'] == 'select') { - $functionName = CRM_Utils_Array::value('name', CRM_Utils_Array::value('pseudoconstant', $props)); - if ($functionName) { - $props['option_values'] = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::$functionName(); - } - } - $this->$add( - $props['html_type'], - $setting, - ts($props['title']), - CRM_Utils_Array::value($props['html_type'] == 'select' ? 'option_values' : 'html_attributes', $props, array()), - $props['html_type'] == 'select' ? CRM_Utils_Array::value('html_attributes', $props) : NULL - ); - } - } - elseif ($add == 'addMonthDay') { - $this->add('date', $setting, ts($props['title']), CRM_Core_SelectValues::date(NULL, 'M d')); - } - elseif ($add == 'addDate') { - $this->addDate($setting, ts($props['title']), FALSE, array('formatType' => $props['type'])); - } - else { - $this->$add($setting, ts($props['title'])); - } + parent::buildQuickForm(); + $config = CRM_Core_Config::singleton(); + $this->invoiceSettings = [ + 'invoice_prefix' => [ + 'html_type' => 'text', + 'title' => ts('Invoice Prefix'), + 'weight' => 1, + 'description' => ts('Enter prefix to be display on PDF for invoice'), + ], + 'credit_notes_prefix' => [ + 'html_type' => 'text', + 'title' => ts('Credit Notes Prefix'), + 'weight' => 2, + 'description' => ts('Enter prefix to be display on PDF for credit notes.'), + ], + 'due_date' => [ + 'html_type' => 'text', + 'title' => ts('Due Date'), + 'weight' => 3, + ], + 'due_date_period' => [ + 'html_type' => 'select', + 'title' => ts('For transmission'), + 'weight' => 4, + 'description' => ts('Select the interval for due date.'), + 'option_values' => [ + 'select' => ts('- select -'), + 'days' => ts('Days'), + 'months' => ts('Months'), + 'years' => ts('Years'), + ], + ], + 'notes' => [ + 'html_type' => 'wysiwyg', + 'title' => ts('Notes or Standard Terms'), + 'weight' => 5, + 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '), + 'attributes' => ['rows' => 2, 'cols' => 40], + ], + 'is_email_pdf' => [ + 'html_type' => 'checkbox', + 'title' => ts('Automatically email invoice when user purchases online'), + 'weight' => 6, + 'description' => ts('Should a pdf invoice be emailed automatically?'), + ], + 'tax_term' => [ + 'html_type' => 'text', + 'title' => ts('Tax Term'), + 'weight' => 7, + ], + 'tax_display_settings' => [ + 'html_type' => 'select', + 'title' => ts('Tax Display Settings'), + 'weight' => 8, + 'option_values' => [ + 'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' . + $config->defaultCurrencySymbol . '120.00'), + 'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' . + $config->defaultCurrencySymbol . + '120.00 (includes [tax term] of ' . + $config->defaultCurrencySymbol . '20.00)'), + 'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' . + $config->defaultCurrencySymbol . '100.00 + ' . + $config->defaultCurrencySymbol . '20.00 [tax term]'), + ], + ], + ]; + + // @todo this is a faux metadata approach - we should be honest & add them correctly or find a way to make this + // compatible with our settings standards. + foreach ($this->invoiceSettings as $fieldName => $fieldValue) { + switch ($fieldValue['html_type']) { + case 'text': + $this->addElement('text', + $fieldName, + $fieldValue['title'], + [ + 'maxlength' => 64, + 'size' => 32, + ] + ); + break; + + case 'checkbox': + $this->add($fieldValue['html_type'], + $fieldName, + $fieldValue['title'] + ); + break; + + case 'select': + $this->addElement('select', + $fieldName, + $fieldValue['title'], + $fieldValue['option_values'], + CRM_Utils_Array::value('attributes', $fieldValue) + ); + break; + + case 'wysiwyg': + $this->add('wysiwyg', $fieldName, $fieldValue['title'], $fieldValue['attributes']); + break; } - $htmlFields[$setting] = ts($props['description']); } - $this->assign('htmlFields', $htmlFields); - parent::buildQuickForm(); + + $this->assign('htmlFields', $this->invoiceSettings); } /** @@ -175,16 +175,8 @@ class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences { * default values are retrieved from the database */ public function setDefaultValues() { - $defaults = Civi::settings()->get('contribution_invoice_settings'); - //CRM-16691: Changes made related to settings of 'CVV'. - foreach (array('cvv_backoffice_required') as $setting) { - $defaults[$setting] = civicrm_api3('setting', 'getvalue', - array( - 'name' => $setting, - 'group' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, - ) - ); - } + $defaults = parent::setDefaultValues(); + $defaults = array_merge($defaults, Civi::settings()->get('contribution_invoice_settings')); return $defaults; } @@ -194,40 +186,14 @@ class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences { public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); - unset($params['qfKey']); - unset($params['entryURL']); - Civi::settings()->set('contribution_invoice_settings', $params); - Civi::settings()->set('update_contribution_on_membership_type_change', - CRM_Utils_Array::value('update_contribution_on_membership_type_change', $params) - ); - - // to set default value for 'Invoices / Credit Notes' checkbox on display preferences - $values = CRM_Core_BAO_Setting::getItem("CiviCRM Preferences"); - $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name'); - $setKey = array_search('Invoices / Credit Notes', $optionValues); - - if (isset($params['invoicing'])) { - $value = array($setKey => $optionValues[$setKey]); - $setInvoice = CRM_Core_DAO::VALUE_SEPARATOR . - implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value)) . - CRM_Core_DAO::VALUE_SEPARATOR; - Civi::settings()->set('user_dashboard_options', $values['user_dashboard_options'] . $setInvoice); - } - else { - $setting = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values['user_dashboard_options'], 1, -1)); - $invoiceKey = array_search($setKey, $setting); - if ($invoiceKey !== FALSE) { - unset($setting[$invoiceKey]); - } - $settingName = CRM_Core_DAO::VALUE_SEPARATOR . - implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($setting)) . - CRM_Core_DAO::VALUE_SEPARATOR; - Civi::settings()->set('user_dashboard_options', $settingName); - } - //CRM-16691: Changes made related to settings of 'CVV'. - $settings = array_intersect_key($params, array('cvv_backoffice_required' => 1)); - $result = civicrm_api3('setting', 'create', $settings); - CRM_Core_Session::setStatus(ts('Your changes have been saved.'), ts('Changes Saved'), "success"); + $invoiceParams = array_intersect_key($params, $this->invoiceSettings); + // This is a hack - invoicing is it's own setting but it is being used from invoice params + // too. This means that saving from api will not have the desired core effect. + // but we should fix that elsewhere - ie. stop abusing the settings + // and fix the code repetition associated with invoicing + $invoiceParams['invoicing'] = CRM_Utils_Array::value('invoicing', $params, 0); + Civi::settings()->set('contribution_invoice_settings', $invoiceParams); + parent::postProcess(); } }