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

Fix: Export donors - filter by donation form #7146

Merged
merged 2 commits into from
Dec 22, 2023
Merged
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
23 changes: 21 additions & 2 deletions src/Exports/DonorsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class DonorsExport extends Give_Batch_Export
/** @var String */
protected $searchBy;

/**
* @var int
*/
protected $donationFormId;

/**
* @inheritdoc
*/
Expand All @@ -44,11 +49,14 @@ public function set_properties($request)
if ($this->postedData['searchBy']) {
$this->searchBy = $this->postedData['searchBy'];
}

$this->donationFormId = (int)$this->postedData['forms'];
}

/**
* @since 2.29.0 Include donor created date
* @since 2.29.0 Include donor created date
* @since 2.21.2
* @unreleased Filter donors by form ID
*/
public function get_data(): array
{
Expand Down Expand Up @@ -91,6 +99,17 @@ public function get_data(): array
}
}

if ($this->donationFormId) {
$donationQuery
->join(function (JoinQueryBuilder $builder) {
$builder
->leftJoin('give_donationmeta', 'form')
->on('donations.ID', 'form.donation_id')
->andOn('form.meta_key', '_give_payment_form_id', true);
})
->where('form.meta_value', $this->donationFormId);
}

$donorQuery->joinRaw("JOIN ({$donationQuery->getSQL()}) AS sub ON donors.id = sub.donorId");

if ($this->shouldIncludeAddress()) {
Expand Down Expand Up @@ -136,7 +155,7 @@ protected function filterExportData(array $exportData): array
}

/**
* @since 2.29.0 Include donor created col
* @since 2.29.0 Include donor created col
* @since 2.21.2
*/
public function csv_cols(): array
Expand Down
Loading