From b677b23b8691e42ca14b6128127890ca4c2761bd Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Tue, 30 May 2017 16:38:09 +0530 Subject: [PATCH] CRM-20657: get all participant ids if multiple contacts register from webform --- CRM/Event/BAO/Participant.php | 18 +++++++++------ .../phpunit/api/v3/ParticipantPaymentTest.php | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 20b94c0489..346926c300 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -1788,16 +1788,20 @@ WHERE civicrm_participant.contact_id = {$contactID} AND } // get primary participant id - $query = "SELECT participant_id FROM civicrm_participant_payment WHERE contribution_id = {$contributionId}"; - $participantId = CRM_Core_DAO::singleValueQuery($query); + $query = "SELECT participant_id + FROM civicrm_participant cp + LEFT JOIN civicrm_participant_payment cpp ON cp.id = cpp.participant_id + WHERE cpp.contribution_id = {$contributionId} + AND cp.registered_by_id IS NULL"; + $participantPayment = CRM_Core_DAO::executeQuery($query); // get additional participant ids (including cancelled) - if ($participantId) { - $ids = array_merge(array( - $participantId, - ), self::getAdditionalParticipantIds($participantId, + while ($participantPayment->fetch()) { + $ids = array_merge($ids, array_merge(array( + $participantPayment->participant_id, + ), self::getAdditionalParticipantIds($participantPayment->participant_id, $excludeCancelled - )); + ))); } return $ids; diff --git a/tests/phpunit/api/v3/ParticipantPaymentTest.php b/tests/phpunit/api/v3/ParticipantPaymentTest.php index 79f47dc02e..25da033ad0 100644 --- a/tests/phpunit/api/v3/ParticipantPaymentTest.php +++ b/tests/phpunit/api/v3/ParticipantPaymentTest.php @@ -393,4 +393,26 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams); } + /** + * test getParticipantIds() function + */ + public function testGetParticipantIds() { + $contributionID = $this->contributionCreate(array('contact_id' => $this->_contactID)); + $expectedParticipants = array($this->_participantID, $this->_participantID2); + + //Create Participant Payment record With Values + foreach ($expectedParticipants as $pid) { + $params = array( + 'participant_id' => $pid, + 'contribution_id' => $contributionID, + ); + $this->callAPISuccess('participant_payment', 'create', $params); + } + //Check if all participants are listed. + $participants = CRM_Event_BAO_Participant::getParticipantIds($contributionID); + $this->checkArrayEquals($expectedParticipants, $participants); + //delete created contribution + $this->contributionDelete($contributionID); + } + } -- 2.25.1