CRM-5039 - Events don't always limit registrations to "max participants"...
<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
$addParticipantNum = substr($form->_name, 12);
foreach ($params as $pCnt => $values) {
if ($values == 'skip' ||
- $pCnt == $addParticipantNum
+ $pCnt === $addParticipantNum
) {
continue;
}
$opDbCount = CRM_Utils_Array::value('db_total_count', $options[$optId], 0);
$total += $opDbCount;
if ($optMax && $total > $optMax) {
+ $errors['soldOutOptions'][] = ts('Option %1 has sold out.', array(1 => $feeBlock[$fieldId]['options'][$optId]['label']));
if ($opDbCount && ($opDbCount >= $optMax)) {
$errors[$currentParticipantNum]["price_{$fieldId}"] =
ts('Sorry, this option is currently sold out.');
<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
else
CRM_Core_Error::fatal($paymentObjError);
- $params['payer'] = $expressParams['payer'];
+ $params['payer'] = CRM_Utils_Array::value('payer', $expressParams);
$params['payer_id'] = $expressParams['payer_id'];
$params['payer_status'] = $expressParams['payer_status'];
$params['discountAmount'] = $this->_params[0]['discountAmount'];
$params['discountMessage'] = $this->_params[0]['discountMessage'];
}
+ if (!empty($this->_params[0]['amount_priceset_level_radio'])) {
+ $params['amount_priceset_level_radio'] = $this->_params[0]['amount_priceset_level_radio'];
+ }
$params['amount_level'] = $this->_params[0]['amount_level'];
$params['currencyID'] = $this->_params[0]['currencyID'];
$params['payment_action'] = 'Sale';
// Assign Participant Count to Lineitem Table
$this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
+ $this->addFormRule(array('CRM_Event_Form_Registration_Confirm', 'formRule'), $this);
}
+ static function formRule($fields, $files, $self) {
+ $errors = array();
+ $eventFull = CRM_Event_BAO_Participant::eventFull($self->_eventId, FALSE, CRM_Utils_Array::value('has_waitlist', $self->_values['event']));
+ if ($eventFull && empty($self->_allowConfirmation)) {
+ if (empty($self->_allowWaitlist)) {
+ CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$self->_eventId}",FALSE, NULL, FALSE, TRUE));
+ }
+ }
+ $self->_feeBlock = $self->_values['fee'];
+ CRM_Event_Form_Registration_Register::formatFieldsForOptionFull($self);
+
+ if (!empty($self->_priceSetId)) {
+ $priceSetErrors = self::validatePriceSet($self, $self->_params);
+ //get price set fields errors in.
+ $errors = array_merge($errors, CRM_Utils_Array::value(0, $priceSetErrors, array()));
+ }
+
+ if (!empty($errors)) {
+ $soldOutOptions = implode("<br>", $priceSetErrors['soldOutOptions']);
+ CRM_Core_Session::setStatus(ts('You have been returned to the start of the registration process and any sold out events have been removed from your selections. You will not be able to continue until you review your booking and select different events if you wish. The following events were sold out:') , ts('Unfortunately some of your options have now sold out for one or more participants.') , 'error');
+ CRM_Core_Session::setStatus(ts("{$soldOutOptions}") , ts('Sold out:') , 'error');
+ CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "_qf_Register_display=true&qfKey=" . $fields['qfKey']));
+ }
+ return empty($errors) ? TRUE : $errors;
+ }
/**
* Process the form submission
*
<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
$dbTotalCount = CRM_Utils_Array::value($optId, $recordedOptionsCount, 0);
$currentTotalCount = CRM_Utils_Array::value($optId, $currentOptionsCount, 0);
- // Do not consider current count for select field,
- // since we are not going to freeze the options.
- if ($field['html_type'] == 'Select') {
- $totalCount = $dbTotalCount;
- }
- else {
- $totalCount = $currentTotalCount + $dbTotalCount;
- }
+ $totalCount = $currentTotalCount + $dbTotalCount;
$isFull = FALSE;
if ($maxValue &&
- (($totalCount >= $maxValue) || ($totalCount + $count > $maxValue))
+ (($totalCount > $maxValue) || ($totalCount + $count > $maxValue))
) {
$isFull = TRUE;
$optionFullIds[$optId] = $optId;
<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $id, 'is_active', $is_active);
}
+ static function freezeIfEnabled(&$element, $fieldOptions) {
+ if (!empty($fieldOptions['is_full'])) {
+ $element->freeze();
+ }
+ return;
+ }
+
/**
* Get the field title.
*
// CRM-6902 - Add "max" option for a price set field
if (in_array($optionKey, $freezeOptions)) {
- $element->freeze();
- // CRM-14696 - Styling for sold out Text input fields is handled in PriceSet.tpl
+ self::freezeIfEnabled($element, $freezeOptions);
+ // CRM-14696 - Improve display for sold out price set options
+ $element->setLabel($label . ' <span class="sold-out-option">' . ts('Sold out') . '</span>');
}
//CRM-10117
// CRM-6902 - Add "max" option for a price set field
if (in_array($opId, $freezeOptions)) {
- $choice[$opId]->freeze();
+ self::freezeIfEnabled($choice[$opId], $customOption[$opId]);
// CRM-14696 - Improve display for sold out price set options
$choice[$opId]->setText('<span class="sold-out-option">' . $choice[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
}
$opt['label'] = $opt['label'] . CRM_Utils_Money::format($opt[$valueFieldName]);
}
}
-
+
$selectOption[$opt['id']] = $opt['label'];
$priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
-
+
if (!in_array($opt['id'], $freezeOptions)) {
$allowedOptions[] = $opt['id'];
}
else {
$opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
}
-
+
$selectOption[$opt['id']] = $opt['label'];
if ($is_pay_later) {
$qf->add( 'text', 'txt-'.$elementName, $label, array( 'size' => '4'));
}
}
-
+
$element = &$qf->add('select', $elementName, $label,
array(
'' => ts('- select -')) + $selectOption,
}
// CRM-6902 - Add "max" option for a price set field
if (in_array($opId, $freezeOptions)) {
- $check[$opId]->freeze();
+ 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() . ' (' . ts('Sold out') . ')</span>');
}