From 5fb827c17fd1730c384d9dd299e323ef9aaef5d7 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Thu, 14 Nov 2019 14:28:10 +1300 Subject: [PATCH] Further work to convert participant emails to multiple --- CRM/Contribute/BAO/Contribution.php | 38 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 81f8392ae9b3..df16e629ec09 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2816,24 +2816,22 @@ public function loadRelatedObjects(&$input, &$ids, $loadAll = FALSE) { // make sure event exists and is valid $event = new CRM_Event_BAO_Event(); $event->id = $ids['event']; - if ($ids['event'] && - !$event->find(TRUE) - ) { + if ($ids['event'] && !$event->find(TRUE)) { throw new Exception("Could not find event: " . $ids['event']); } - $this->_relatedObjects['event'] = &$event; + $this->_relatedObjects['event'] = $event; - $participant = new CRM_Event_BAO_Participant(); - $participant->id = $ids['participant']; - if ($ids['participant'] && - !$participant->find(TRUE) - ) { - throw new Exception("Could not find participant: " . $ids['participant']); - } - $participant->register_date = CRM_Utils_Date::isoToMysql($participant->register_date); + foreach ($ids['participant'] ?? [] as $participantID) { + $participant = new CRM_Event_BAO_Participant(); + $participant->id = $participantID; + if (!$participant->find(TRUE)) { + throw new Exception("Could not find participant: " . $participantID); + } + $participant->register_date = CRM_Utils_Date::isoToMysql($participant->register_date); - $this->_relatedObjects['participant'] = &$participant; + $this->_relatedObjects['participant'][] = $participant; + } // get the payment processor id from event - this is inaccurate see CRM-16923 // in future we should look at throwing an exception here rather than an dubious guess. @@ -3129,7 +3127,9 @@ public function _gatherMessageValues($input, &$values, $ids = []) { } } else { - $values = array_merge($values, $this->loadEventMessageTemplateParams((int) $ids['event'], (int) $this->_relatedObjects['participant']->id, $this->id)); + $values = array_merge($values, + $this->loadEventMessageTemplateParams((int) $ids['event'], (int) $this->_relatedObjects['participant']->id, $this->id) + ); } $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', NULL, $this->id); @@ -4477,7 +4477,6 @@ public static function completeOrder($input, &$ids, $objects, $transaction, $rec $inputContributionWhiteList[] = 'financial_type_id'; } - $participant = CRM_Utils_Array::value('participant', $objects); $recurContrib = CRM_Utils_Array::value('contributionRecur', $objects); $recurringContributionID = (empty($recurContrib->id)) ? NULL : $recurContrib->id; $event = CRM_Utils_Array::value('event', $objects); @@ -4570,9 +4569,12 @@ public static function completeOrder($input, &$ids, $objects, $transaction, $rec // @todo this should be set by the function that sends the mail after sending. $contributionParams['receipt_date'] = $changeDate; } - $participantParams['id'] = $participant->id; - $participantParams['status_id'] = 'Registered'; - civicrm_api3('Participant', 'create', $participantParams); + foreach ($objects['participant'] as $participantObject) { + // Update all related participants to registered + $participantParams['id'] = $participantObject->id; + $participantParams['status_id'] = 'Registered'; + civicrm_api3('Participant', 'create', $participantParams); + } } }