From 5778c4447ae57a74af487435b27b07b09e56ee62 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 7 Aug 2013 15:24:13 +0530 Subject: [PATCH] -- worked on CRM-12055 ---------------------------------------- * CRM-12055: Allow users to change label used for Contribution Amounts in online contribution page w/o switching to a price set http://issues.civicrm.org/jira/browse/CRM-12055 --- .../Form/ContributionPage/Amount.php | 70 ++++++++++++++----- CRM/Event/Form/ManageEvent/Fee.php | 4 +- .../Form/ContributionPage/Amount.tpl | 6 +- templates/CRM/Price/Form/PriceSet.tpl | 3 +- 4 files changed, 60 insertions(+), 23 deletions(-) diff --git a/CRM/Contribute/Form/ContributionPage/Amount.php b/CRM/Contribute/Form/ContributionPage/Amount.php index d90b4880f2..579e2e2711 100644 --- a/CRM/Contribute/Form/ContributionPage/Amount.php +++ b/CRM/Contribute/Form/ContributionPage/Amount.php @@ -67,6 +67,9 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co $this->add('text', 'max_amount', ts('Maximum Amount'), array('size' => 8, 'maxlength' => 8)); $this->addRule('max_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); + //CRM-12055 + $this->add('text', 'amount_label', ts('Contribution Amounts Label')); + $default = array(); $this->add('hidden', "price_field_id", '', array('id' => "price_field_id")); $this->add('hidden', "price_field_other", '', array('id' => "price_field_option")); @@ -205,12 +208,16 @@ SELECT id //$priceField = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceField', $priceSetId, 'id', 'price_set_id' ); $options = $pFIDs = array(); $priceFieldParams = array('price_set_id' => $priceSetId); - $priceFields = CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array('html_type', 'name', 'is_active')); + $priceFields = CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array('html_type', 'name', 'is_active', 'label')); foreach ($priceFields as $priceField) { if ($priceField['id'] && $priceField['html_type'] == 'Radio' && $priceField['name'] == 'contribution_amount') { $defaults['price_field_id'] = $priceField['id']; $priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($priceField['id'], $options, 'id', 1); + if (empty($priceFieldOptions)) { + continue; + } $countRow = 0; + $defaults['amount_label'] = $priceField['label']; foreach ($options as $optionId => $optionValue) { $countRow++; $defaults['value'][$countRow] = $optionValue['amount']; @@ -226,11 +233,18 @@ SELECT id } elseif ($priceField['id'] && $priceField['html_type'] == 'Text' && $priceField['name'] = 'other_amount' && $priceField['is_active']) { $defaults['price_field_other'] = $priceField['id']; + if (!isset($defaults['amount_label'])) { + $defaults['amount_label'] = $priceField['label']; + } } } } } + if (!CRM_Utils_Array::value('amount_label', $defaults)) { + $defaults['amount_label'] = ts('Contribution Amount'); + } + if (CRM_Utils_Array::value('value', $defaults) && is_array($defaults['value'])) { // CRM-4038: fix value display @@ -557,15 +571,14 @@ SELECT id CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetId); if (!empty($options)) { $editedFieldParams = array( - 'price_set_id' => $priceSetId, - 'name' => 'contribution_amount', - ); + 'price_set_id' => $priceSetId, + 'name' => 'contribution_amount', + ); $editedResults = array(); $noContriAmount = 1; CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults); if (!CRM_Utils_Array::value('id', $editedResults)) { $fieldParams['name'] = strtolower(CRM_Utils_String::munge("Contribution Amount", '_', 245)); - $fieldParams['label'] = "Contribution Amount"; } else { $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults); @@ -581,6 +594,7 @@ SELECT id else { $fieldParams['is_required'] = 1; } + $fieldParams['label'] = $params['amount_label']; $fieldParams['html_type'] = 'Radio'; $fieldParams['option_label'] = $params['label']; $fieldParams['option_amount'] = $params['value']; @@ -599,7 +613,7 @@ SELECT id $editedResults = array(); CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults); - + if (!$priceFieldID = CRM_Utils_Array::value('id', $editedResults)) { $fieldParams = array( 'name' => 'other_amount', @@ -614,28 +628,48 @@ SELECT id $fieldParams['option_amount'][1] = 1; if (!$noContriAmount) { $fieldParams['is_required'] = 1; - $fieldParams['option_label'][1] = 'Contribution Amount'; - } else { + $fieldParams['option_label'][1] = $fieldParams['label'] = $params['amount_label']; + } + else { $fieldParams['is_required'] = 0; - $fieldParams['option_label'][1] = 'Other Amount'; + $fieldParams['option_label'][1] = $fieldParams['label'] = 'Other Amount'; } $priceField = CRM_Price_BAO_PriceField::create($fieldParams); - } else { + } + else { if (!CRM_Utils_Array::value('is_active', $editedResults)) { - CRM_Price_BAO_PriceField::setIsActive($priceFieldID, '1'); + if (!$noContriAmount) { + $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id'); + CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']); + $fieldParams = array( + 'is_required' => 1, + 'label' => $params['amount_label'], + 'id' => $priceFieldID, + ); + } + $fieldParams['is_active'] = 1; + $priceField = CRM_Price_BAO_PriceField::add($fieldParams); } } - } elseif (!CRM_Utils_Array::value('is_allow_other_amount', $params) && CRM_Utils_Array::value('price_field_other', $params)) { + } + elseif (!CRM_Utils_Array::value('is_allow_other_amount', $params) && CRM_Utils_Array::value('price_field_other', $params)) { CRM_Price_BAO_PriceField::setIsActive($params['price_field_other'], '0'); - } elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) { - $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id' ); + } + elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) { + $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id'); if (!$noContriAmount) { - CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $priceFieldID, 'is_required', 1); - CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', 'Contribution Amount' ); - } else { + $fieldParams = array( + 'is_required' => 1, + 'label' => $params['amount_label'], + 'id' => $priceFieldID, + ); + CRM_Price_BAO_PriceField::add($fieldParams); + CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']); + } + else { CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $priceFieldID, 'is_required', 0 ); - CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', 'Other Amount' ); + CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', 'Other Amount'); } } } diff --git a/CRM/Event/Form/ManageEvent/Fee.php b/CRM/Event/Form/ManageEvent/Fee.php index 2542f536aa..314353f46f 100644 --- a/CRM/Event/Form/ManageEvent/Fee.php +++ b/CRM/Event/Form/ManageEvent/Fee.php @@ -628,7 +628,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_PriceSet::create($setParams); - $fieldParams['name'] = $fieldParams['label'] = $params['fee_label']; + $fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245)); $fieldParams['price_set_id'] = $priceSet->id; } else { @@ -648,7 +648,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']); } } - + $fieldParams['label'] = $params['fee_label']; $fieldParams['html_type'] = 'Radio'; CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id); $fieldParams['option_label'] = $params['label']; diff --git a/templates/CRM/Contribute/Form/ContributionPage/Amount.tpl b/templates/CRM/Contribute/Form/ContributionPage/Amount.tpl index fbf0e0ca04..9d2fe99cce 100644 --- a/templates/CRM/Contribute/Form/ContributionPage/Amount.tpl +++ b/templates/CRM/Contribute/Form/ContributionPage/Amount.tpl @@ -157,7 +157,11 @@ {/if} - + + + {$form.amount_label.label} + {$form.amount_label.html} + {$form.is_allow_other_amount.label} {$form.is_allow_other_amount.html}
{ts}Check this box if you want to give users the option to enter their own contribution amount. Your page will then include a text field labeled Other Amount.{/ts} diff --git a/templates/CRM/Price/Form/PriceSet.tpl b/templates/CRM/Price/Form/PriceSet.tpl index 7e08400b1a..f498a8286e 100644 --- a/templates/CRM/Price/Form/PriceSet.tpl +++ b/templates/CRM/Price/Form/PriceSet.tpl @@ -34,8 +34,7 @@
{if ($element.html_type eq 'CheckBox' || $element.html_type == 'Radio') && $element.options_per_line} {assign var="element_name" value="price_"|cat:$field_id} - {* quickConfig price sets - use fee_label from event record *} -
{if $quickConfig && $extends NEQ 'Membership'}{$event.fee_label} *{else}{$form.$element_name.label}{/if}
+
{$form.$element_name.label}
{assign var="rowCount" value="1"} {assign var="count" value="1"} -- 2.25.1