From a3aed42a453009733e8feb2c56fde5750b37cd14 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 18 Jan 2020 11:31:02 +1300 Subject: [PATCH] Add helper for getting participantValues --- CRM/Event/Form/Participant.php | 42 ++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 302b0a412b..3a3ddfcdf8 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -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. */ @@ -1832,15 +1839,12 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment } } 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); } @@ -1977,7 +1981,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * @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; } /** @@ -1995,4 +1999,28 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment 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; + } + } -- 2.25.1