Skip to content

Commit

Permalink
allow deregistration
Browse files Browse the repository at this point in the history
  • Loading branch information
larssandergreen committed Dec 17, 2022
1 parent 46a20e8 commit e1d996a
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 156 deletions.
5 changes: 0 additions & 5 deletions CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,11 +795,6 @@ public static function formatFieldsForOptionFull(&$form) {
$option['total_option_count'] = $dbTotalCount + $currentTotalCount;
}

//ignore option full for offline registration.
if ($className == 'CRM_Event_Form_Participant' || $className === 'CRM_Event_Form_Task_Register') {
$optionFullIds = [];
}

//finally get option ids in.
$field['option_full_ids'] = $optionFullIds;
}
Expand Down
193 changes: 79 additions & 114 deletions CRM/Price/BAO/PriceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,33 +295,25 @@ public static function addQuickFormElement(
$useRequired = FALSE;
}

$className = CRM_Utils_System::getClassName($qf);
$formClasses = ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register', 'CRM_Event_Form_ParticipantFeeSelection'];
$isFrontEnd = (!in_array($className, $formClasses));

$customOption = $fieldOptions;
if (!is_array($customOption)) {
$customOption = CRM_Price_BAO_PriceField::getOptions($field->id, $inactiveNeeded);
}

//use value field.
$valueFieldName = 'amount';
$separator = '|';
$taxTerm = Civi::settings()->get('tax_term');
$displayOpt = Civi::settings()->get('tax_display_settings');
$invoicing = Civi::settings()->get('invoicing');
switch ($field->html_type) {
case 'Text':
$optionKey = key($customOption);
$count = CRM_Utils_Array::value('count', $customOption[$optionKey], '');
$max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], '');
$taxAmount = $customOption[$optionKey]['tax_amount'] ?? NULL;
if (isset($taxAmount) && $displayOpt && $invoicing) {
$qf->assign('displayOpt', $displayOpt);
$qf->assign('taxTerm', $taxTerm);
$qf->assign('invoicing', $invoicing);
}
$priceVal = implode($separator, [
$customOption[$optionKey][$valueFieldName] + $taxAmount,
$count,
$max_value,
]);

// Text elements have a label before and this second label after with amount etc, added here starting with a NULL label
$customOption[$optionKey]['label'] = NULL;
$priceOptionText = self::buildPriceOptionText($customOption[$optionKey], $field->is_display_amounts, $valueFieldName);
$elementLabelAfter = &$qf->add('static', $elementName . '_label_after', $priceOptionText['label']);

$extra = [];
if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) {
Expand All @@ -343,7 +335,7 @@ public static function addQuickFormElement(
$element = &$qf->add('text', $elementName, $label,
array_merge($extra,
[
'price' => json_encode([$optionKey, $priceVal]),
'price' => json_encode([$optionKey, $priceOptionText['priceVal']]),
'size' => '4',
]
),
Expand All @@ -355,9 +347,10 @@ public static function addQuickFormElement(

// CRM-6902 - Add "max" option for a price set field
if (in_array($optionKey, $freezeOptions)) {
self::freezeIfEnabled($element, $fieldOptions[$optionKey]);
// CRM-14696 - Improve display for sold out price set options
$element->setLabel($label . '&nbsp;<span class="sold-out-option">' . ts('Sold out') . '</span>');
if ($isFrontEnd) {
self::freezeIfEnabled($element, $fieldOptions[$optionKey]);
}
$elementLabelAfter->setLabel('<span class="sold-out-option">' . $elementLabelAfter->getLabel() . '&nbsp;(' . ts('Sold out') . ')</span>');
}

//CRM-10117
Expand All @@ -381,38 +374,16 @@ public static function addQuickFormElement(
}

foreach ($customOption as $opId => $opt) {
$preHelpText = $postHelpText = '';
$opt['label'] = !empty($opt['label']) ? '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' : '';
if (!empty($opt['help_pre'])) {
$preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span><span class="crm-price-amount-help-pre-separator">:&nbsp;</span>';
}
if (!empty($opt['help_post'])) {
$postHelpText = '<span class="crm-price-amount-help-post-separator">:&nbsp;</span><span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
}

$taxAmount = $opt['tax_amount'] ?? NULL;
if ($field->is_display_amounts) {
$opt['label'] = !empty($opt['label']) ? $opt['label'] . '<span class="crm-price-amount-label-separator">&nbsp;-&nbsp;</span>' : '';
if (isset($taxAmount) && $invoicing) {
$opt['label'] = $opt['label'] . self::getTaxLabel($opt, $valueFieldName);
}
else {
$opt['label'] = $opt['label'] . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
}
}
$priceOptionText = self::buildPriceOptionText($opt, $field->is_display_amounts, $valueFieldName);

$opt['label'] = $preHelpText . $opt['label'] . $postHelpText;
$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');
$priceVal = implode($separator, [$opt[$valueFieldName] + $taxAmount, $count, $max_value]);
if (isset($opt['visibility_id'])) {
$visibility_id = $opt['visibility_id'];
}
else {
$visibility_id = self::getVisibilityOptionID('public');
}
$extra = [
'price' => json_encode([$elementName, $priceVal]),
'price' => json_encode([$elementName, $priceOptionText['priceVal']]),
'data-amount' => $opt[$valueFieldName],
'data-currency' => $currencyName,
'data-price-field-values' => json_encode($customOption),
Expand All @@ -429,7 +400,7 @@ public static function addQuickFormElement(
$qf->assign('membershipFieldID', $field->id);
}

$choice[$opt['id']] = $opt['label'];
$choice[$opt['id']] = $priceOptionText['label'];
$choiceAttrs[$opt['id']] = $extra;
if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, ['size' => '4']);
Expand All @@ -456,15 +427,17 @@ public static function addQuickFormElement(
$none = ts('- none -');
}

$choice['0'] = $none;
$choice['0'] = '<span class="crm-price-amount-label">' . $none . '</span>';
$choiceAttrs['0'] = ['price' => json_encode([$elementName, '0'])];
}

$element = &$qf->addRadio($elementName, $label, $choice, [], NULL, FALSE, $choiceAttrs);
foreach ($element->getElements() as $radioElement) {
// CRM-6902 - Add "max" option for a price set field
if (in_array($radioElement->getValue(), $freezeOptions)) {
self::freezeIfEnabled($radioElement, $customOption[$radioElement->getValue()]);
if ($isFrontEnd) {
self::freezeIfEnabled($radioElement, $customOption[$radioElement->getValue()]);
}
// CRM-14696 - Improve display for sold out price set options
$radioElement->setText('<span class="sold-out-option">' . $radioElement->getText() . '&nbsp;(' . ts('Sold out') . ')</span>');
}
Expand All @@ -483,46 +456,24 @@ public static function addQuickFormElement(
break;

case 'Select':
$selectOption = $allowedOptions = $priceVal = [];
$selectOption = $allowedOptions = [];

foreach ($customOption as $opt) {
$taxAmount = $opt['tax_amount'] ?? NULL;
$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');

$preHelpText = $postHelpText = '';
if (!empty($opt['help_pre'])) {
$preHelpText = $opt['help_pre'] . ':&nbsp;';
}
if (!empty($opt['help_post'])) {
$postHelpText = ':&nbsp;' . $opt['help_post'];
}

$taxAmount = $opt['tax_amount'] ?? NULL;
if ($field->is_display_amounts) {
$opt['label'] = !empty($opt['label']) ? $opt['label'] . '&nbsp;-&nbsp;' : '';
if (isset($taxAmount) && $invoicing) {
$opt['label'] = $opt['label'] . self::getTaxLabel($opt, $valueFieldName);
}
else {
$opt['label'] = $opt['label'] . CRM_Utils_Money::format($opt[$valueFieldName]);
}
}

$opt['label'] = $preHelpText . $opt['label'] . $postHelpText;

$priceVal[$opt['id']] = implode($separator, [$opt[$valueFieldName] + $taxAmount, $count, $max_value]);
$priceOptionText = self::buildPriceOptionText($opt, $field->is_display_amounts, $valueFieldName);
$priceOptionText['label'] = strip_tags($priceOptionText['label']);

if (!in_array($opt['id'], $freezeOptions)) {
$allowedOptions[] = $opt['id'];
}
// CRM-14696 - Improve display for sold out price set options
else {
$opt['id'] = 'crm_disabled_opt-' . $opt['id'];
$opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
if ($isFrontEnd) {
$opt['id'] = 'crm_disabled_opt-' . $opt['id'];
}
$priceOptionText['label'] = $priceOptionText['label'] . ' (' . ts('Sold out') . ')';
}

$selectOption[$opt['id']] = $opt['label'];
$selectOption[$opt['id']] = $priceOptionText['label'];

if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, ['size' => '4']);
Expand All @@ -546,64 +497,36 @@ public static function addQuickFormElement(

$element = &$qf->add('select', $elementName, $label, $selectOption, $useRequired && $field->is_required, [
'placeholder' => ts('- select %1 -', [1 => $label]),
'price' => json_encode($priceVal),
'price' => json_encode($priceOptionText['priceVal']),
'class' => 'crm-select2' . $class,
'data-price-field-values' => json_encode($customOption),
]);

// CRM-6902 - Add "max" option for a price set field
$button = substr($qf->controller->getButtonName(), -4);
if (!empty($freezeOptions) && $button != 'skip') {
$qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
}
break;

case 'CheckBox':

$check = [];
foreach ($customOption as $opId => $opt) {
$taxAmount = $opt['tax_amount'] ?? NULL;
$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');

$preHelpText = $postHelpText = '';
$opt['label'] = !empty($opt['label']) ? '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' : '';
if (!empty($opt['help_pre'])) {
$preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span><span class="crm-price-amount-help-pre-separator">:&nbsp;</span>';
}
if (!empty($opt['help_post'])) {
$postHelpText = '<span class="crm-price-amount-help-post-separator">:&nbsp;</span><span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
}
$priceOptionText = self::buildPriceOptionText($opt, $field->is_display_amounts, $valueFieldName);

$taxAmount = $opt['tax_amount'] ?? NULL;
if ($field->is_display_amounts) {
$opt['label'] = !empty($opt['label']) ? $opt['label'] . '<span class="crm-price-amount-label-separator">&nbsp;-&nbsp;</span>' : '';
if (isset($taxAmount) && $invoicing) {
$opt['label'] = $opt['label'] . self::getTaxLabel($opt, $valueFieldName);
}
else {
$opt['label'] = $opt['label'] . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
}
}

$opt['label'] = $preHelpText . $opt['label'] . $postHelpText;

$priceVal = implode($separator, [$opt[$valueFieldName] + $taxAmount, $count, $max_value]);
$check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
$check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $priceOptionText['label'],
[
'price' => json_encode([$opt['id'], $priceVal]),
'price' => json_encode([$opt['id'], $priceOptionText['priceVal']]),
'data-amount' => $opt[$valueFieldName],
'data-currency' => $currencyName,
'visibility' => $opt['visibility_id'],
]
);
if ($is_pay_later) {
$txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], ['size' => '4']);
$txtcheck[$opId] =& $qf->createElement('text', $opId, $priceOptionText['label'], ['size' => '4']);
$qf->addGroup($txtcheck, 'txt-' . $elementName, $label);
}
// CRM-6902 - Add "max" option for a price set field
if (in_array($opId, $freezeOptions)) {
self::freezeIfEnabled($check[$opId], $customOption[$opId]);
if ($isFrontEnd) {
self::freezeIfEnabled($check[$opId], $customOption[$opId]);
}
// CRM-14696 - Improve display for sold out price set options
$check[$opId]->setText('<span class="sold-out-option">' . $check[$opId]->getText() . '&nbsp;(' . ts('Sold out') . ')</span>');
}
Expand Down Expand Up @@ -851,6 +774,48 @@ public static function priceSetValidation($priceSetId, $fields, &$error, $allowN
}
}

/**
* Build the label and priceVal string for a price option.
*
* @param array $opt
* Price field option.
* @param bool $isDisplayAmounts
* @param string $valueFieldName
*
* @return array
* Price field option label, price value
*/
public static function buildPriceOptionText($opt, $isDisplayAmounts, $valueFieldName) {
$preHelpText = $postHelpText = '';
$optionLabel = !empty($opt['label']) ? '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' : '';
if (!empty($opt['help_pre'])) {
$preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span><span class="crm-price-amount-help-pre-separator">:&nbsp;</span>';
}
if (!empty($opt['help_post'])) {
$postHelpText = '<span class="crm-price-amount-help-post-separator">:&nbsp;</span><span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
}

$invoicing = Civi::settings()->get('invoicing');
$taxAmount = $opt['tax_amount'] ?? NULL;
if ($isDisplayAmounts) {
$optionLabel = !empty($optionLabel) ? $optionLabel . '<span class="crm-price-amount-label-separator">&nbsp;-&nbsp;</span>' : '';
if (isset($taxAmount) && $invoicing) {
$optionLabel = $optionLabel . self::getTaxLabel($opt, $valueFieldName);
}
else {
$optionLabel = $optionLabel . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
}
}

$optionLabel = $preHelpText . $optionLabel . $postHelpText;

$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');
$priceVal = implode('|', [$opt[$valueFieldName] + $taxAmount, $count, $max_value]);

return ['label' => $optionLabel, 'priceVal' => $priceVal];
}

/**
* Generate the label for price fields based on tax display setting option on CiviContribute Component Settings page.
*
Expand Down
19 changes: 12 additions & 7 deletions css/civicrm.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ div.crm-container fieldset label {
}

input.crm-form-radio + label,
input.crm-form-checkbox + label {
input.crm-form-checkbox + label,
.crm-frozen-field .sold-out-option {
margin-left: 7px;
}

Expand Down Expand Up @@ -834,6 +835,14 @@ input.crm-form-entityref {
margin: 0;
}

.crm-container .description.help_post {
margin-top: 0.45em;
}

.crm-container .description.help_pre {
margin-bottom: 0.45em;
}

.crm-container .price-set-option-content .description {
font-size: 1em;
}
Expand Down Expand Up @@ -3800,12 +3809,8 @@ span.crm-status-icon {
display: none;
}

#crm-container .sold-out-option,
#crm-container .price-set-row span.sold-out-option .crm-price-amount-label,
#crm-container .price-set-row span.sold-out-option .crm-price-amount-amount {
font-style: italic !important;
font-weight: normal !important;
font-size: 15px;
.crm-container span.sold-out-option,
.crm-container span.sold-out-option span {
color: #666 !important;
}

Expand Down
Loading

0 comments on commit e1d996a

Please sign in to comment.