Skip to content

Commit

Permalink
Load event title from participantID
Browse files Browse the repository at this point in the history
This is a follow on to civicrm#18358 - after thinking
more I realised that I had already established this code is rarely reached and by
doing a very small query when it is we can avoid loading the whole event to pass in

Same test applies...
  • Loading branch information
eileenmcnaughton committed Sep 5, 2020
1 parent 30bd3f9 commit 26626ba
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Civi\Api4\Activity;
use Civi\Api4\ContributionPage;
use Civi\Api4\ContributionRecur;
use Civi\Api4\Participant;

/**
*
Expand Down Expand Up @@ -4406,8 +4407,9 @@ public static function completeOrder($input, $ids, $objects, $isPostPaymentCreat
'financial_type_id',
];

$eventID = $objects['event']->id ?? NULL;

// @todo - accept payment_processor_id as an input parameter as it is part of the
// incoming payment information (at least when coming from a payment processor).
// this is the last 'object' to get rid of....
$paymentProcessorId = '';
if (isset($objects['paymentProcessor'])) {
if (is_array($objects['paymentProcessor'])) {
Expand All @@ -4422,7 +4424,7 @@ public static function completeOrder($input, $ids, $objects, $isPostPaymentCreat

$contributionParams = array_merge([
'contribution_status_id' => $completedContributionStatusID,
'source' => self::getRecurringContributionDescription($contribution, $eventID),
'source' => self::getRecurringContributionDescription($contribution, $participantID),
], array_intersect_key($input, array_fill_keys($inputContributionWhiteList, 1)
));

Expand Down Expand Up @@ -4636,12 +4638,13 @@ public function loadRelatedMembershipObjects($ids = []) {
* Get the description (source field) for the recurring contribution.
*
* @param CRM_Contribute_BAO_Contribution $contribution
* @param int|null $eventID
* @param int|null $participantID
*
* @return string
* @throws \CiviCRM_API3_Exception
* @throws \API_Exception
*/
protected static function getRecurringContributionDescription($contribution, $eventID) {
protected static function getRecurringContributionDescription($contribution, $participantID) {
if (!empty($contribution->source)) {
return $contribution->source;
}
Expand All @@ -4652,8 +4655,12 @@ protected static function getRecurringContributionDescription($contribution, $ev
]);
return ts('Online Contribution') . ': ' . $contributionPageTitle;
}
elseif ($eventID) {
return ts('Online Event Registration') . ': ' . CRM_Event_PseudoConstant::event($eventID);
elseif ($participantID) {
$eventTitle = Participant::get(FALSE)
->addSelect('event.title')
->addWhere('id', '=', (int) $participantID)
->execute()->first()['event.title'];
return ts('Online Event Registration') . ': ' . $eventTitle;
}
elseif (!empty($contribution->contribution_recur_id)) {
return 'recurring contribution';
Expand Down

0 comments on commit 26626ba

Please sign in to comment.