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

Add helper for getting participantValues #16355

Merged
merged 1 commit into from
Jan 25, 2020
Merged
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
42 changes: 35 additions & 7 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
*/
public $_onlinePendingContributionId = NULL;

/**
* Stored participant record.
*
* @var array
*/
protected $participantRecord;

/**
* Explicitly declare the entity api name.
*/
Expand Down Expand Up @@ -1832,15 +1839,12 @@ protected function preparePaidEventProcessing($params): array {
}
}
if ($this->isPaymentOnExistingContribution()) {
$participantBAO = new CRM_Event_BAO_Participant();
$participantBAO->id = $this->_id;
$participantBAO->find(TRUE);
$contributionParams['total_amount'] = $participantBAO->fee_amount;
$contributionParams['total_amount'] = $this->getParticipantValue('fee_amount');

$params['discount_id'] = NULL;
//re-enter the values for UPDATE mode
$params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level;
$params['fee_amount'] = $participantBAO->fee_amount;
$params['fee_level'] = $params['amount_level'] = $this->getParticipantValue('fee_level');
$params['fee_amount'] = $this->getParticipantValue('fee_amount');
if (isset($params['priceSetId'])) {
$lineItem[0] = CRM_Price_BAO_LineItem::getLineItems($this->_id);
}
Expand Down Expand Up @@ -1977,7 +1981,7 @@ protected function assignEventDetailsToTpl($eventID, $participantRoles, $receipt
* @return bool
*/
protected function isPaymentOnExistingContribution(): bool {
return ($this->_id && $this->_action & CRM_Core_Action::UPDATE) && $this->_paymentId;
return ($this->getParticipantID() && $this->_action & CRM_Core_Action::UPDATE) && $this->_paymentId;
}

/**
Expand All @@ -1995,4 +1999,28 @@ protected function getEventValue(string $fieldName) {
return $this->_event[$fieldName];
}

/**
* Get a value from the existing participant record (applies to edits).
*
* @param string $fieldName
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
protected function getParticipantValue($fieldName) {
if (!$this->participantRecord) {
$this->participantRecord = civicrm_api3('Participant', 'get', ['id' => $this->_id]);
}
return $this->participantRecord[$fieldName];
}

/**
* Get id of participant being edited.
*
* @return int|null
*/
protected function getParticipantID() {
return $this->_id;
}

}