Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy last remaining usage of getComponentDetails() to relevant subsystem #29459

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1596,10 +1596,13 @@ public static function checkDuplicateIds($params) {
* @param array $componentIds
* Component ids.
*
* @deprecated since 5.72 will be removed around 5.90
*
* @return array
* associated array
*/
public static function getContributionDetails($exportMode, $componentIds) {
CRM_Core_Error::deprecatedFunctionWarning('no alternative');
$paymentDetails = [];
$componentClause = ' IN ( ' . implode(',', $componentIds) . ' ) ';

Expand Down
2 changes: 1 addition & 1 deletion CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static function exportComponents(
$paymentDetails = [];
if ($processor->isExportPaymentFields()) {
// get payment related in for event and members
$paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids);
$paymentDetails = $processor->getContributionDetails();
//get all payment headers.
// If we haven't selected specific payment fields, load in all the
// payment headers.
Expand Down
67 changes: 64 additions & 3 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public function setAddresseeGreetingTemplate($addresseeGreetingTemplate) {
* - addressee_other
*/
public function __construct($exportMode, $requestedFields, $queryOperator, $isMergeSameHousehold = FALSE, $isPostalableOnly = FALSE, $isMergeSameAddress = FALSE, $formValues = []) {
$this->setExportMode($exportMode);
$this->setExportMode((int) $exportMode);
$this->setQueryMode();
$this->setQueryOperator($queryOperator);
$this->setRequestedFields($requestedFields);
Expand Down Expand Up @@ -697,14 +697,14 @@ public function setQueryMode() {
/**
* @return int
*/
public function getExportMode() {
public function getExportMode(): int {
return $this->exportMode;
}

/**
* @param int $exportMode
*/
public function setExportMode($exportMode) {
public function setExportMode(int $exportMode) {
$this->exportMode = $exportMode;
}

Expand Down Expand Up @@ -2367,4 +2367,65 @@ protected function getContactPortionOfGreeting(int $contactID, int $greetingID,
return $copyPostalGreeting;
}

/**
* Get the contribution details for component export.
*
* @internal do not call from outside core.
*
* @return array
* associated array
*/
public function getContributionDetails() {
$paymentDetails = [];
$componentClause = ' IN ( ' . implode(',', $this->ids) . ' ) ';

if ($this->getExportMode() === CRM_Export_Form_Select::EVENT_EXPORT) {
$componentSelect = " civicrm_participant_payment.participant_id id";
$additionalClause = "
INNER JOIN civicrm_participant_payment ON (civicrm_contribution.id = civicrm_participant_payment.contribution_id
AND civicrm_participant_payment.participant_id {$componentClause} )
";
}
elseif ($this->getExportMode() === CRM_Export_Form_Select::MEMBER_EXPORT) {
$componentSelect = " civicrm_membership_payment.membership_id id";
$additionalClause = "
INNER JOIN civicrm_membership_payment ON (civicrm_contribution.id = civicrm_membership_payment.contribution_id
AND civicrm_membership_payment.membership_id {$componentClause} )
";
}
elseif ($this->getExportMode() === CRM_Export_Form_Select::PLEDGE_EXPORT) {
$componentSelect = " civicrm_pledge_payment.id id";
$additionalClause = "
INNER JOIN civicrm_pledge_payment ON (civicrm_contribution.id = civicrm_pledge_payment.contribution_id
AND civicrm_pledge_payment.pledge_id {$componentClause} )
";
}

$query = " SELECT total_amount, contribution_status.name as status_id, contribution_status.label as status, payment_instrument.name as payment_instrument, receive_date,
trxn_id, {$componentSelect}
FROM civicrm_contribution
LEFT JOIN civicrm_option_group option_group_payment_instrument ON ( option_group_payment_instrument.name = 'payment_instrument')
LEFT JOIN civicrm_option_value payment_instrument ON (civicrm_contribution.payment_instrument_id = payment_instrument.value
AND option_group_payment_instrument.id = payment_instrument.option_group_id )
LEFT JOIN civicrm_option_group option_group_contribution_status ON (option_group_contribution_status.name = 'contribution_status')
LEFT JOIN civicrm_option_value contribution_status ON (civicrm_contribution.contribution_status_id = contribution_status.value
AND option_group_contribution_status.id = contribution_status.option_group_id )
{$additionalClause}
";

$dao = CRM_Core_DAO::executeQuery($query);

while ($dao->fetch()) {
$paymentDetails[$dao->id] = [
'total_amount' => $dao->total_amount,
'contribution_status' => $dao->status,
'receive_date' => $dao->receive_date,
'pay_instru' => $dao->payment_instrument,
'trxn_id' => $dao->trxn_id,
];
}

return $paymentDetails;
}

}