/**
* Process the form when submitted
*
* @return void
* @access public
*/
public function postProcess()
{
if (CRM_Price_BAO_PriceSet::deleteSet($this->_sid)) {
CRM_Core_Session::setStatus(ts('The Price Set \'%1\' has been deleted.', array(1 => $this->_title), ts('Deleted'), 'success'));
} else {
CRM_Core_Session::setStatus(ts('The Price Set \'%1\' has not been deleted! You must delete all price fields in this set prior to deleting the set.', array(1 => $this->_title)), 'Unable to Delete', 'error');
}
}
/**
* Test the correct amount level is returned for an event which is not presented as a price set event.
*
* (these are denoted as 'quickConfig' in the code - but quickConfig is only supposed to refer to the
* configuration interface - there should be no different post process.
*/
public function testGetAmountLevelTextAmount()
{
$priceSetID = $this->eventPriceSetCreate(9);
$priceSet = CRM_Price_BAO_PriceSet::getCachedPriceSetDetail($priceSetID);
$field = reset($priceSet['fields']);
$params = array('priceSetId' => $priceSetID, 'price_' . $field['id'] => 1);
$amountLevel = CRM_Price_BAO_PriceSet::getAmountLevelText($params);
$this->assertEquals(CRM_Core_DAO::VALUE_SEPARATOR . 'Price Field - 1' . CRM_Core_DAO::VALUE_SEPARATOR, $amountLevel);
}
//.........这里部分代码省略.........
} elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues['price_' . $fieldId] > 0) {
$proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
}
unset($params['price_' . $fieldId]);
break;
}
}
}
}
}
if (!isset($params['amount_other'])) {
$this->set('amount_level', CRM_Utils_Array::value('amount_level', $params));
}
if (!empty($this->_ccid)) {
$this->set('lineItem', $this->_lineItem);
} elseif ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) {
$lineItem = array();
$is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
if ($is_quick_config) {
foreach ($this->_values['fee'] as $key => &$val) {
if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && !empty($params['price_' . $key])) {
// Clean out any currency symbols.
$params['price_' . $key] = CRM_Utils_Rule::cleanMoney($params['price_' . $key]);
if ($params['price_' . $key] != 0) {
foreach ($val['options'] as $optionKey => &$options) {
$options['amount'] = CRM_Utils_Array::value('price_' . $key, $params);
break;
}
}
$params['price_' . $key] = 1;
break;
}
}
}
$component = '';
if ($this->_membershipBlock) {
$component = 'membership';
}
CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[$priceSetId], $component);
if ($params['tax_amount']) {
$this->set('tax_amount', $params['tax_amount']);
}
if ($proceFieldAmount) {
$lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
$lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
if (isset($lineItem[$params['priceSetId']][$fieldOption]['tax_amount'])) {
$proceFieldAmount += $lineItem[$params['priceSetId']][$fieldOption]['tax_amount'];
}
if (!$this->_membershipBlock['is_separate_payment']) {
//require when separate membership not used
$params['amount'] = $proceFieldAmount;
}
}
$this->set('lineItem', $lineItem);
}
if ($params['amount'] != 0 && ($this->_values['is_pay_later'] && empty($this->_paymentProcessor) && !array_key_exists('hidden_processor', $params) || CRM_Utils_Array::value('payment_processor_id', $params) == 0)) {
$params['is_pay_later'] = 1;
} else {
$params['is_pay_later'] = 0;
}
// Would be nice to someday understand the point of this set.
$this->set('is_pay_later', $params['is_pay_later']);
// assign pay later stuff
$this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
$this->assign('is_pay_later', $params['is_pay_later']);
if ($params['is_pay_later']) {
$this->assign('pay_later_text', $this->_values['pay_later_text']);
$this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
}
if ($this->_membershipBlock['is_separate_payment'] && !empty($params['separate_amount'])) {
$this->set('amount', $params['separate_amount']);
} else {
$this->set('amount', $params['amount']);
}
// generate and set an invoiceID for this transaction
$invoiceID = md5(uniqid(rand(), TRUE));
$this->set('invoiceID', $invoiceID);
$params['invoiceID'] = $invoiceID;
$params['description'] = ts('Online Contribution') . ': ' . (!empty($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']);
$params['button'] = $this->controller->getButtonName();
// required only if is_monetary and valid positive amount
// @todo it seems impossible for $memFee to be greater than 0 & $params['amount'] not to
// be & by requiring $memFee down here we make it harder to do a sensible refactoring of the function
// above (ie. extract the amount in a small function).
if ($this->_values['is_monetary'] && !empty($this->_paymentProcessor) && ((double) $params['amount'] > 0.0 || $memFee > 0.0)) {
// The concept of contributeMode is deprecated - as should be the 'is_monetary' setting.
$this->setContributeMode();
// Really this setting of $this->_params & params within it should be done earlier on in the function
// probably the values determined here should be reused in confirm postProcess as there is no opportunity to alter anything
// on the confirm page. However as we are dealing with a stable release we go as close to where it is used
// as possible.
// In general the form has a lack of clarity of the logic of why things are set on the form in some cases &
// the logic around when $this->_params is used compared to other params arrays.
$this->_params = array_merge($params, $this->_params);
$this->setRecurringMembershipParams();
if ($this->_paymentProcessor && $this->_paymentProcessor['object']->supports('preApproval')) {
$this->handlePreApproval($this->_params);
}
}
}
/**
* This is sometimes called in a loop (during event search)
* hence we cache the values to prevent repeated calls to the db
*/
static function usesPriceSet($id)
{
static $usesPriceSet = array();
if (!array_key_exists($id, $usesPriceSet)) {
$usesPriceSet[$id] = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $id);
}
return $usesPriceSet[$id];
}
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess()
{
//get the button name.
$button = substr($this->controller->getButtonName(), -4);
//take the participant instance.
$addParticipantNum = substr($this->_name, 12);
//user submitted params.
$params = $this->controller->exportValues($this->_name);
if (!$this->_allowConfirmation) {
// check if the participant is already registered
$params['contact_id'] = CRM_Event_Form_Registration_Register::checkRegistration($params, $this, TRUE, TRUE);
}
//carry campaign to partcipants.
if (array_key_exists('participant_campaign_id', $params)) {
$params['campaign_id'] = $params['participant_campaign_id'];
} else {
$params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
}
// if waiting is enabled
if (!$this->_allowConfirmation && is_numeric($this->_availableRegistrations)) {
$this->_allowWaitlist = FALSE;
//get the current page count.
$currentCount = self::getParticipantCount($this, $params);
if ($button == 'skip') {
$currentCount = 'skip';
}
//get the total count.
$previousCount = self::getParticipantCount($this, $this->_params, TRUE);
$totalParticipants = $previousCount;
if (is_numeric($currentCount)) {
$totalParticipants += $currentCount;
}
if (!empty($this->_values['event']['has_waitlist']) && $totalParticipants > $this->_availableRegistrations) {
$this->_allowWaitlist = TRUE;
}
$this->set('allowWaitlist', $this->_allowWaitlist);
$this->_lineItemParticipantsCount[$addParticipantNum] = $currentCount;
}
if ($button == 'skip') {
//hack for free/zero amount event.
if ($this->_resetAllowWaitlist) {
$this->_allowWaitlist = FALSE;
$this->set('allowWaitlist', FALSE);
if ($this->_requireApproval) {
$status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.");
} else {
$status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list.");
}
CRM_Core_Session::setStatus($status);
}
$this->_params[$addParticipantNum] = 'skip';
if (isset($this->_lineItem)) {
$this->_lineItem[$addParticipantNum] = 'skip';
$this->_lineItemParticipantsCount[$addParticipantNum] = 'skip';
}
} else {
$config = CRM_Core_Config::singleton();
$params['currencyID'] = $config->defaultCurrency;
if ($this->_values['event']['is_monetary']) {
//added for discount
$discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
if (!empty($this->_values['discount'][$discountId])) {
$params['discount_id'] = $discountId;
$params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
$params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
} elseif (empty($params['priceSetId'])) {
$params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
$params['amount'] = $this->_values['fee'][$params['amount']]['value'];
} else {
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
//build line item array..
//if requireApproval/waitlist is enabled we hide fees for primary participant
// (and not for additional participant which might be is a bug)
//lineItem are not correctly build for primary participant
//this results in redundancy since now lineItems for additional participant will be build against primary participantNum
//therefore lineItems must always be build against current participant No
$this->_lineItem[$addParticipantNum] = $lineItem;
}
}
if (array_key_exists('participant_role', $params)) {
$params['participant_role_id'] = $params['participant_role'];
}
if (empty($params['participant_role_id']) && $this->_values['event']['default_role_id']) {
$params['participant_role_id'] = $this->_values['event']['default_role_id'];
}
if (!empty($this->_params[0]['is_pay_later'])) {
$params['is_pay_later'] = 1;
}
//carry additional participant id, contact id if pre-registered.
if ($this->_allowConfirmation && $this->_additionalParticipantId) {
$params['contact_id'] = $this->_contactId;
$params['participant_id'] = $this->_additionalParticipantId;
}
//.........这里部分代码省略.........
请发表评论