Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-12252 Add in help_pre and help_post fields for price field options #8521

Merged
merged 11 commits into from
Jun 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions CRM/Price/BAO/PriceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,22 +375,26 @@ public static function addQuickFormElement(
foreach ($customOption as $opId => $opt) {
$taxAmount = CRM_Utils_Array::value('tax_amount', $opt);
if ($field->is_display_amounts) {
$opt['label'] = !empty($opt['label']) ? $opt['label'] . ' - ' : '';
$opt['label'] = !empty($opt['label']) ? $opt['label'] . '<span class="crm-price-amount-label-separator">&nbsp;-&nbsp;</span>' : '';
$pre_help = isset($opt['help_pre']) ?
'<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span>: ' : '';
$post_help = isset($opt['help_post']) ?
': <span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>' : '';
if (isset($taxAmount) && $invoicing) {
if ($displayOpt == 'Do_not_show') {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
$opt['label'] = $pre_help . '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>' . $post_help;
}
elseif ($displayOpt == 'Inclusive') {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
$opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money::format($opt['tax_amount']) . ')</span>';
$opt['label'] = $pre_help . '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
$opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money::format($opt['tax_amount']) . ')</span>' . $post_help;
}
else {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
$opt['label'] .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
$opt['label'] = $pre_help . '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
$opt['label'] .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>' . $post_help;
}
}
else {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
$opt['label'] = $pre_help . '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>' . $post_help;
}
}
$count = CRM_Utils_Array::value('count', $opt, '');
Expand All @@ -414,7 +418,6 @@ public static function addQuickFormElement(
}

$choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);

if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
}
Expand Down Expand Up @@ -527,12 +530,16 @@ public static function addQuickFormElement(
$max_value = CRM_Utils_Array::value('max_value', $opt, '');

if ($field->is_display_amounts) {
$pre_help = isset($opt['help_pre']) ?
'<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span>: ' : '';
$post_help = isset($opt['help_post']) ?
': <span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>' : '';
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>&nbsp;-&nbsp;';
if (isset($taxAmount) && $invoicing) {
$opt['label'] .= self::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
$opt['label'] .= $pre_help . self::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm) . $post_help;
}
else {
$opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
$opt['label'] .= $pre_help . CRM_Utils_Money::format($opt[$valueFieldName]) . $post_help;
}
}
$priceVal = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
Expand Down
2 changes: 2 additions & 0 deletions CRM/Price/Form/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ public function buildQuickForm() {
$this->addRule('amount', ts('Please enter a monetary value for this field.'), 'money');

$this->add('textarea', 'description', ts('Description'));
$this->add('textarea', 'help_pre', ts('Pre Option Help'), NULL, TRUE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the problem is in the postProcess on this file? You shouldn't need to do anything re multilingual - esp if you use the api

$this->add('textarea', 'help_post', ts('Post Option Help'), NULL, TRUE);

// weight
$this->add('text', 'weight', ts('Order'), NULL, TRUE);
Expand Down
47 changes: 47 additions & 0 deletions CRM/Upgrade/Incremental/php/FourSeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ public function upgrade_4_7_8($rev) {
$this->addTask('Upgrade mailing foreign key constraints', 'upgradeMailingFKs');
}

/**
* Upgrade function.
*
* @param string $rev
*/
public function upgrade_4_7_10($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
$this->addTask(ts('Upgrade Add Help Pre and Post Fields to price value table'), 'addHelpPreAndHelpPostFieldsPriceFieldValue');
}

/*
* Important! All upgrade functions MUST call the 'runSql' task.
* Uncomment and use the following template for a new upgrade version
Expand Down Expand Up @@ -619,6 +629,43 @@ public function addDeletedByMergeActivityType(CRM_Queue_TaskContext $ctx) {
return TRUE;
}

/**
* CRM-12252 Add Help Pre and Help Post Fields for Price Field Value Table.
*
* @param \CRM_Queue_TaskContext $ctx
*
* @return bool
*/
public function addHelpPreAndHelpPostFieldsPriceFieldValue(CRM_Queue_TaskContext $ctx) {
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
if ($domain->locales) {
$locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
foreach ($locales as $locale) {
if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists("civicrm_price_field_value", "help_pre_{$locale}")) {
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_price_field_value`
ADD COLUMN `help_pre_{$locale}` text COLLATE utf8_unicode_ci COMMENT 'Price field option pre help text.'", array(), TRUE, NULL, FALSE, FALSE);
}
if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists("civicrm_price_field_value", "help_post_{$locale}")) {
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_price_field_value`
ADD COLUMN `help_post_{$locale}` text COLLATE utf8_unicode_ci COMMENT 'Price field option post help text.'", array(), TRUE, NULL, FALSE, FALSE);
}
}
CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, NULL);
}
else {
if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_price_field_value', 'help_pre')) {
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_price_field_value`
ADD COLUMN `help_pre` text COLLATE utf8_unicode_ci COMMENT 'Price field option pre help text.'");
}
if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_price_field_value', 'help_post')) {
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_price_field_value`
ADD COLUMN `help_post` text COLLATE utf8_unicode_ci COMMENT 'Price field option post help text.'");
}
}
return TRUE;
}

/**
* Remove a foreign key from a table if it exists
*
Expand Down
70 changes: 35 additions & 35 deletions sql/civicrm_generated.mysql

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions templates/CRM/Price/Form/Option.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
<td class="label">{$form.description.label}</td>
<td>{if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_price_field_value' field='description' id=$optionId}{/if}{$form.description.html}</td>
</tr>
<tr class="crm-price-option-form-block-help-pre">
<td class="label">{$form.help_pre.label}</td>
<td>{if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_price_field_value' field='help_pre' id=$optionId}{/if}{$form.help_pre.html}</td>
</tr>
<tr class="crm-price-option-form-block-help-post">
<td class="label">{$form.help_post.label}</td>
<td>{if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_price_field_value' field='help_post' id=$optionId}{/if}{$form.help_post.html}</td>
</tr>
<tr class="crm-price-option-form-block-financial-type">
<td class="label">{$form.financial_type_id.label}</td>
<td>
Expand Down
4 changes: 4 additions & 0 deletions templates/CRM/Price/Page/Option.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<tr>
<th>{ts}Option Label{/ts}</th>
<th>{ts}Option Amount{/ts}</th>
<th>{ts}Pre Help{/ts}</th>
<th>{ts}Post Help{/ts}</th>
{if $isEvent}
<th>{ts}Participant Count{/ts}</th>
<th>{ts}Maximum{/ts}</th>
Expand All @@ -74,6 +76,8 @@
<tr id="price_field_value-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {$row.class}{if NOT $row.is_active} disabled{/if}">
<td class="crm-price-option-label crm-editable" data-field="label">{$row.label}</td>
<td class="crm-price-option-value">{$row.amount|crmMoney}</td>
<td class="crm-price-option-pre-help">{$row.help_pre}</td>
<td class="crm-price-option-post-help">{$row.help_post}</td>
{if $isEvent}
<td class="crm-price-option-count">{$row.count}</td>
<td class="crm-price-option-max">{$row.max_value}</td>
Expand Down
26 changes: 26 additions & 0 deletions xml/schema/Price/PriceFieldValue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@
<comment>>Price field option description.</comment>
<add>3.3</add>
</field>
<field>
<name>help_pre</name>
<type>text</type>
<html>
<type>TextArea</type>
<rows>2</rows>
<cols>60</cols>
</html>
<default>NULL</default>
<localizable>true</localizable>
<comment>Price field option pre help text.</comment>
<add>4.7</add>
</field>
<field>
<name>help_post</name>
<type>text</type>
<html>
<type>TextArea</type>
<rows>2</rows>
<cols>60</cols>
</html>
<default>NULL</default>
<localizable>true</localizable>
<comment>Price field option post field help.</comment>
<add>4.7</add>
</field>
<field>
<name>amount</name>
<type>varchar</type>
Expand Down