Skip to content

Commit

Permalink
Merge pull request #16355 from eileenmcnaughton/ev_part
Browse files Browse the repository at this point in the history
Add helper for getting participantValues
  • Loading branch information
colemanw authored Jan 25, 2020
2 parents c9b1bc2 + a3aed42 commit 53e5c14
Showing 1 changed file with 35 additions and 7 deletions.
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 @@ -2182,7 +2186,7 @@ protected function addParticipant(&$form, $contactID) {
* @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 @@ -2200,4 +2204,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;
}

}

0 comments on commit 53e5c14

Please sign in to comment.