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

feature: add donor phone number exports #7394

Merged
merged 9 commits into from
May 30, 2024
4 changes: 3 additions & 1 deletion includes/admin/tools/export/export-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function give_do_ajax_export() {
* Note: This function is for internal purposes only.
* Use filter "give_export_donors_get_default_columns" instead.
*
* @unreleased add donor_phone_number column.
* @since 2.2.6
*
* @return array
Expand All @@ -154,7 +155,8 @@ function give_export_donors_get_default_columns() {
'address' => __( 'Address', 'give' ),
'userid' => __( 'User ID', 'give' ),
'donor_created_date' => __( 'Donor Created Date', 'give' ),
'donations' => __( 'Number of donations', 'give' ),
'donor_phone_number' => __( 'Donor Phone Number', 'give' ),
'donations' => __( 'Number of donations', 'give' ),
'donation_sum' => __( 'Total Donated', 'give' ),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public function csv_cols() {
/**
* CSV file columns.
*
* @unreleased add phone column.
* @since 2.1
*
* @param array $columns
Expand Down Expand Up @@ -199,6 +200,9 @@ private function get_cols( $columns ) {
$cols['address_zip'] = __( 'Zip', 'give' );
$cols['address_country'] = __( 'Country', 'give' );
break;
case 'phone':
$cols['phone'] = __( 'Donor Phone Number', 'give' );
break;
case 'comment':
$cols['comment'] = __( 'Donor Comment', 'give' );
break;
Expand Down Expand Up @@ -374,6 +378,10 @@ public function get_data() {
$data[ $i ]['address_country'] = isset( $address['country'] ) ? $address['country'] : '';
}

if ( ! empty( $columns['phone'] ) ) {
$data[ $i ]['phone'] = $payment_meta['_give_payment_donor_phone'];
}

JoshuaHungDinh marked this conversation as resolved.
Show resolved Hide resolved
if ( ! empty( $columns['comment'] ) ) {
$comment = give_get_donor_donation_comment( $payment->ID, $payment->donor_id );
$data[ $i ]['comment'] = ! empty( $comment ) ? $comment->comment_content : '';
Expand Down
31 changes: 20 additions & 11 deletions includes/admin/tools/export/give-export-donations-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ function give_export_donations_get_custom_fields() {
$donation_list = implode( ',', (array) give_get_payments( $args ) );

$query_and = sprintf(
"AND $wpdb->posts.ID IN (%s)
AND $wpdb->donationmeta.meta_key != ''
"AND $wpdb->posts.ID IN (%s)
AND $wpdb->donationmeta.meta_key != ''
AND $wpdb->donationmeta.meta_key NOT RegExp '(^[_0-9].+$)'",
$donation_list
);

$query = "
SELECT DISTINCT($wpdb->donationmeta.meta_key)
FROM $wpdb->posts
LEFT JOIN $wpdb->donationmeta
SELECT DISTINCT($wpdb->donationmeta.meta_key)
FROM $wpdb->posts
LEFT JOIN $wpdb->donationmeta
ON $wpdb->posts.ID = {$wpdb->donationmeta}.{$donationmeta_table_key}
WHERE $wpdb->posts.post_type = '%s'
" . $query_and;
Expand All @@ -56,17 +56,17 @@ function give_export_donations_get_custom_fields() {
}

$query_and = sprintf(
"AND $wpdb->posts.ID IN (%s)
AND $wpdb->donationmeta.meta_key != ''
"AND $wpdb->posts.ID IN (%s)
AND $wpdb->donationmeta.meta_key != ''
AND $wpdb->donationmeta.meta_key NOT RegExp '^[^_]'",
$donation_list
);

$query = "
SELECT DISTINCT($wpdb->donationmeta.meta_key)
FROM $wpdb->posts
LEFT JOIN $wpdb->donationmeta
ON $wpdb->posts.ID = {$wpdb->donationmeta}.{$donationmeta_table_key}
SELECT DISTINCT($wpdb->donationmeta.meta_key)
FROM $wpdb->posts
LEFT JOIN $wpdb->donationmeta
ON $wpdb->posts.ID = {$wpdb->donationmeta}.{$donationmeta_table_key}
WHERE $wpdb->posts.post_type = '%s'
" . $query_and;

Expand Down Expand Up @@ -229,6 +229,7 @@ function give_export_donation_form_search_args( $args ) {
/**
* Add Donation standard fields in export donation page
*
* @unreleased add Donor Phone Number to donor fields.
* @since 2.1
*/
function give_export_donation_standard_fields() {
Expand Down Expand Up @@ -472,6 +473,14 @@ function give_export_donation_standard_fields() {
</label>
</li>

<li>
<label for="give-export-phone">
<input type="checkbox" checked
name="give_give_donations_export_option[phone]"
id="give-export-address"><?php _e( 'Donor\'s Phone Number', 'give' ); ?>
</label>
</li>

<li>
<label for="give-export-comment">
<input type="checkbox" checked
Expand Down
4 changes: 4 additions & 0 deletions src/Exports/DonorsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function set_properties($request)
}

/**
* @unreleased Include donor phone.
* @since 2.29.0 Include donor created date
* @since 2.21.2
* @since 3.3.0 Filter donors by form ID
Expand All @@ -67,6 +68,7 @@ public function get_data(): array
['donors.email', 'email'],
['donors.user_id', 'userid'],
['donors.date_created', 'donor_created_date'],
['donors.phone', 'donor_phone_number'],
['donors.purchase_count', 'donations'],
['donors.purchase_value', 'donation_sum']
);
Expand Down Expand Up @@ -155,6 +157,7 @@ protected function filterExportData(array $exportData): array
}

/**
* @unreleased Include donor_phone_number col.
* @since 2.29.0 Include donor created col
* @since 2.21.2
*/
Expand All @@ -174,6 +177,7 @@ public function csv_cols(): array
],
'userid' => __('User ID', 'give'),
'donor_created_date' => __('Donor Created', 'give'),
'donor_phone_number' => __('Donor Phone Number', 'give'),
'donations' => __('Number of donations', 'give'),
'donation_sum' => __('Total Donated', 'give'),
], $this->postedData['give_export_columns'])
Expand Down
Loading