Skip to content
Snippets Groups Projects
Commit 5778c444 authored by Pradeep Nayak's avatar Pradeep Nayak
Browse files

-- 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
parent 6069a556
No related branches found
No related tags found
No related merge requests found
......@@ -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');
}
}
}
......
......@@ -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'];
......
......@@ -157,7 +157,11 @@
</td>
</tr>
{/if}
<tr class="crm-contribution-form-block-amount_label">
<th scope="row" class="label" width="20%">{$form.amount_label.label}</th>
<td>{$form.amount_label.html}</td>
</tr>
<tr class="crm-contribution-form-block-is_allow_other_amount"><th scope="row" class="label" width="20%">{$form.is_allow_other_amount.label}</th>
<td>{$form.is_allow_other_amount.html}<br />
<span class="description">{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 <strong>Other Amount</strong>.{/ts}</span></td></tr>
......
......@@ -34,8 +34,7 @@
<div class="crm-section {$element.name}-section">
{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 *}
<div class="label">{if $quickConfig && $extends NEQ 'Membership'}{$event.fee_label} <span class="crm-marker" title="This field is required.">*</span>{else}{$form.$element_name.label}{/if}</div>
<div class="label">{$form.$element_name.label}</div>
<div class="content {$element.name}-content">
{assign var="rowCount" value="1"}
{assign var="count" value="1"}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment