Skip to content

Commit

Permalink
Merge branch 'release/2.1' into issue/2900
Browse files Browse the repository at this point in the history
* release/2.1: (23 commits)
  refactor(form): make goal more performant and add support for donor goal #2986
  refactor(admin-form): add support for donor goal
  refactor(admin-form): add support for displaying goal column
  refactor(admin-form): add support for new donor goal type and remove unused method
  fix(form): enable donor count cache logic
  fix(db-update): return success if zero new update count
  fix(db-update): update update health check logic
  add todo
  style(code): improve fn doc
  fix(form): cache donor count
  refactor(form): move helper fn to forms/functions.php
  style(code): improve code formatting
  feat(helper-function): add fn to get donor count for form
  feat(admin-forms): add new goal screen
  refactor(form-setting): add new option for "Number of Donors" and adjusted the description #2986
  fix(donor-admin-pages): remove # from id for consistency
  fix(donation-detail-page): remove # from id for consistency
  fix(admin-tools): update donation status logic #2982
  feat(admin-tool): change export donor csv name #2964
  refactor(admin-tool): change column name in CSV and checkbox #2964
  ...
  • Loading branch information
DevinWalker committed Apr 5, 2018
2 parents c4f2eb2 + c5740c3 commit 17fd784
Show file tree
Hide file tree
Showing 17 changed files with 326 additions and 174 deletions.
9 changes: 6 additions & 3 deletions assets/src/js/admin/admin-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,18 @@ jQuery.noConflict();
var goal_option_val = $( '._give_goal_option_field input:radio:checked' ).val();

if ( 'donation' === goal_format_val ) {
$( '._give_set_goal_field' ).hide();
$( '._give_set_goal_field, ._give_number_of_donor_goal_field' ).hide();
$( '._give_number_of_donation_goal_field' ).show();
} else if ( 'donors' === goal_format_val ) {
$( '._give_set_goal_field, ._give_number_of_donation_goal_field' ).hide();
$( '._give_number_of_donor_goal_field' ).show();
} else {
('disabled' === goal_option_val) ? $( '._give_set_goal_field' ).hide() : $( '._give_set_goal_field' ).show();
$( '._give_number_of_donation_goal_field' ).hide();
$( '._give_number_of_donation_goal_field, ._give_number_of_donor_goal_field' ).hide();
}
} ).change();

//Offline Donations
// Offline Donations.
var offline_customization_option = $( '._give_customize_offline_donations_field input:radio' );
offline_customization_option.on( 'change', function() {
var offline_customization_option_val = $( '._give_customize_offline_donations_field input:radio:checked' ).val();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function render_block( $attributes ) {
'display_type' => $attributes['displayType'],
);

return give_donation_grid_shortcode( $parameters );
return give_form_grid_shortcode( $parameters );
}
}

Expand Down
3 changes: 1 addition & 2 deletions includes/admin/donors/class-donor-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ public function column_cb( $donor ){
* @return string
*/
public function column_name( $donor ) {
$name = '#' . $donor['id'] . ' ';
$name .= ! empty( $donor['name'] ) ? $donor['name'] : '<em>' . __( 'Unnamed Donor', 'give' ) . '</em>';
$name = ! empty( $donor['name'] ) ? $donor['name'] : '<em>' . __( 'Unnamed Donor', 'give' ) . '</em>';
$view_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor['id'] );
$actions = $this->get_row_actions( $donor );

Expand Down
16 changes: 9 additions & 7 deletions includes/admin/donors/donors.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ function give_render_donor_view( $view, $callbacks ) {
<?php
printf(
/* translators: %s: donor first name */
__( 'Edit Donor #%s: %s %s', 'give' ),
$donor->id,
__( 'Edit Donor: %s %s', 'give' ),
$donor->get_first_name(),
$donor->get_last_name()
);
Expand Down Expand Up @@ -335,7 +334,6 @@ function give_donor_view( $donor ) {
</div>

<div id="donor-name-wrap" class="left">
<span class="donor-id">#<?php echo $donor->id; ?></span>
<span class="donor-name info-item edit-item">
<input <?php echo $read_only; ?> size="15" data-key="first_name"
name="customerinfo[first_name]" type="text"
Expand Down Expand Up @@ -372,10 +370,14 @@ class="button info-item editable donor-edit-link"><?php _e( 'Edit Donor', 'give'

<div class="donor-main-wrapper">

<table class="widefat">
<table class="widefat striped">
<tbody>
<tr class="alternate">
<th scope="col"><label for="tablecell"><?php _e( 'User:', 'give' ); ?></label></th>
<tr>
<th scope="col"><label for="tablecell"><?php _e( 'Donor ID:', 'give' ); ?></label></th>
<td><?php echo $donor->id; ?></td>
</tr>
<tr>
<th scope="col"><label for="tablecell"><?php _e( 'User ID:', 'give' ); ?></label></th>
<td>
<span class="donor-user-id info-item edit-item">
<?php
Expand Down Expand Up @@ -405,7 +407,7 @@ class="button info-item editable donor-edit-link"><?php _e( 'Edit Donor', 'give'
<?php if ( ! empty( $userdata ) ) : ?>
<span data-key="user_id">#<?php echo $donor->user_id . ' - ' . $userdata->display_name; ?></span>
<?php else: ?>
<span data-key="user_id"><?php _e( 'None', 'give' ); ?></span>
<span data-key="user_id"><?php _e( 'Unregistered', 'give' ); ?></span>
<?php endif; ?>
<?php if ( current_user_can( $donor_edit_role ) && intval( $donor->user_id ) > 0 ):

Expand Down
23 changes: 16 additions & 7 deletions includes/admin/forms/class-metabox-form-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,15 @@ function get_settings() {

array(
'name' => __( 'Goal Format', 'give' ),
'description' => __( 'Do you want to display the total amount raised based on your monetary goal or a percentage? For instance, "$500 of $1,000 raised" or "50% funded" or "1 of 5 donations".', 'give' ),
'description' => __( 'Do you want to display the total amount raised based on your monetary goal or a percentage? For instance, "$500 of $1,000 raised" or "50% funded" or "1 of 5 donations". You can also display a donor-based goal, such as "100 of 1,000 donors have given".', 'give' ),
'id' => $prefix . 'goal_format',
'type' => 'radio_inline',
'type' => 'radio',
'default' => 'amount',
'options' => array(
'amount' => __( 'Amount', 'give' ),
'percentage' => __( 'Percentage', 'give' ),
'amount' => __( 'Amount Raised', 'give' ),
'percentage' => __( 'Percentage Raised', 'give' ),
'donation' => __( 'Number of Donations', 'give' ),
'donors' => __( 'Number of Donors', 'give' ),
),
),

Expand All @@ -388,18 +389,26 @@ function get_settings() {
),
'wrapper_class' => 'give-hidden',
),

array(
'id' => $prefix . 'number_of_donation_goal',
'name' => __( 'Donation Goal', 'give' ),
'desc' => __( 'Set total number of donations as a goal.', 'give' ),
'desc' => __( 'Set the total number of donations as a goal.', 'give' ),
'type' => 'number',
'default' => 1,
'attributes' => array(
'placeholder' => 1,
),
),
array(
'id' => $prefix . 'number_of_donor_goal',
'name' => __( 'Donor Goal', 'give' ),
'desc' => __( 'Set the total number of donors as a goal.', 'give' ),
'type' => 'number',
'default' => 1,
'attributes' => array(
'placeholder' => 1,
),
),

array(
'name' => __( 'Progress Bar Color', 'give' ),
'desc' => __( 'Customize the color of the goal progress bar.', 'give' ),
Expand Down
16 changes: 9 additions & 7 deletions includes/admin/forms/dashboard-columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ function give_render_form_columns( $column_name, $post_id ) {

$html .= sprintf(
( 'percentage' !== $goal_stats['format'] ) ?
'<div class="give-goal-text"><span>%1$s</span> %2$s <a href="%3$s">%4$s</a></div>' :
'<div class="give-goal-text"><span>%1$s</span> %2$s <a href="%3$s">%4$s</a> %5$s</div>' :
'<div class="give-goal-text"><a href="%3$s">%1$s</a></div>',
( 'percentage' !== $goal_stats['format'] ) ? $goal_stats['actual'] : $percent_complete . '%',
( 'percentage' !== $goal_stats['format'] ) ? __( 'of', 'give' ) : '',
esc_url( admin_url( "post.php?post={$post_id}&action=edit&give_tab=donation_goal_options" ) ),
$goal_stats['goal']
$goal_stats['goal'],
( 'donors' === $goal_stats['format'] ? __( 'Donors', 'give' ) : ( 'donation' === $goal_stats['format'] ? __( 'Donations', 'give' ) : '' ) )
);

if ( $goal_stats['raw_actual'] >= $goal_stats['raw_goal'] ) {
Expand All @@ -108,8 +109,9 @@ function give_render_form_columns( $column_name, $post_id ) {
$html .= sprintf( '<span style="width:%s%%;"></span>', esc_attr( $goal_stats['progress'] ) );
$html .= '</div>';
}

// Output HTML from above.
echo $html;

} else {
esc_html_e( 'No Goal Set', 'give' );
}
Expand Down Expand Up @@ -219,12 +221,12 @@ function give_sort_forms( $vars ) {
$vars['meta_query'] = array(
'relation' => 'OR',
array(
'key' => $multi_level_meta_key,
'type' => 'NUMERIC',
'key' => $multi_level_meta_key,
'type' => 'NUMERIC',
),
array(
'key' => '_give_set_price',
'type' => 'NUMERIC',
'key' => '_give_set_price',
'type' => 'NUMERIC',
)
);

Expand Down
4 changes: 2 additions & 2 deletions includes/admin/payments/view-payment-details.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
<?php
if ( $payment_meta['form_id'] ) :
printf(
'<a href="%1$s">#%2$s</a>',
'<a href="%1$s">%2$s</a>',
admin_url( 'post.php?action=edit&post=' . $payment_meta['form_id'] ),
$payment_meta['form_id']
);
Expand Down Expand Up @@ -527,7 +527,7 @@
<?php
if ( ! empty( $donor->id ) ) {
printf(
'<a href="%1$s">#%2$s</a>',
'<a href="%1$s">%2$s</a>',
admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ),
$donor->id
);
Expand Down
60 changes: 46 additions & 14 deletions includes/admin/tools/export/class-batch-export-donors.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,48 @@ class Give_Batch_Donors_Export extends Give_Batch_Export {
*/
private $query_id = '';

/**
* Give_Batch_Export constructor.
*
* @since 2.0.7
*
* @param int $_step
*/
public function __construct( $_step = 1 ) {

parent::__construct( $_step );

// Filter to change the filename.
add_filter( 'give_export_filename', array( $this, 'give_export_filename' ), 10, 2 );
}

/**
* Function to change the filename
*
* @since 2.0.7
*
* @param $filename
* @param $export_type
*
* @return string
*/
function give_export_filename( $filename, $export_type ) {


if ( $this->export_type !== $export_type ) {
return $filename;
}

if ( ! empty( (int) $_GET['forms'] ) ) {
$slug = get_post_field( 'post_name', get_post( absint( $_GET['forms'] ) ) );
$filename = 'give-export-donors-' . $slug . '-' . date( 'm-d-Y' );
} else {
$filename = 'give-export-donors-all-forms-' . date( 'm-d-Y' );
}

return $filename;
}

/**
* Set the properties specific to the donors export.
*
Expand All @@ -87,10 +129,8 @@ public function set_properties( $request ) {
}

$this->price_id = ! empty( $request['give_price_option'] ) && 'all' !== $request['give_price_option'] ? absint( $request['give_price_option'] ) : null;

}


/**
* Cache donor ids.
*
Expand Down Expand Up @@ -161,11 +201,8 @@ private function get_cols( $columns ) {
case 'userid' :
$cols['userid'] = esc_html__( 'User ID', 'give' );
break;
case 'donation_form' :
$cols['donation_form'] = esc_html__( 'Donation Form', 'give' );
break;
case 'date_first_donated' :
$cols['date_first_donated'] = esc_html__( 'First Donation Date', 'give' );
case 'donor_created_date' :
$cols['donor_created_date'] = esc_html__( 'Donor Created Date', 'give' );
break;
case 'donations' :
$cols['donations'] = esc_html__( 'Number of Donations', 'give' );
Expand Down Expand Up @@ -258,7 +295,6 @@ public function get_data() {
if ( ! empty( $this->donor_ids ) ) {
foreach ( $this->donor_ids as $donor_id ) {
$donor = Give()->donors->get_donor_by( 'id', $donor_id );
$donor->donation_form_title = $this->payment_stats[ $donor_id ]['form_title'];
$donor->purchase_count = $this->payment_stats[ $donor_id ]['donations'];
$donor->purchase_value = $this->payment_stats[ $donor_id ]['donation_sum'];
$data[] = $this->set_donor_data( $i, $data, $donor );
Expand Down Expand Up @@ -296,7 +332,6 @@ public function get_data() {
}

$payment = new Give_Payment( $donor->payment_ids );
$donor->donation_form_title = $payment->form_title;
$data[] = $this->set_donor_data( $i, $data, $donor );
$i ++;
}
Expand Down Expand Up @@ -375,11 +410,8 @@ private function set_donor_data( $i, $data, $donor ) {
if ( ! empty( $columns['userid'] ) ) {
$data[ $i ]['userid'] = ! empty( $donor->user_id ) ? $donor->user_id : '';
}
if ( ! empty( $columns['donation_form'] ) ) {
$data[ $i ]['donation_form'] = ! empty( $donor->donation_form_title ) ? $donor->donation_form_title : '';
}
if ( ! empty( $columns['date_first_donated'] ) ) {
$data[ $i ]['date_first_donated'] = date_i18n( give_date_format(), strtotime( $donor->date_created ) );
if ( ! empty( $columns['donor_created_date'] ) ) {
$data[ $i ]['donor_created_date'] = date_i18n( give_date_format(), strtotime( $donor->date_created ) );
}
if ( ! empty( $columns['donations'] ) ) {
$data[ $i ]['donations'] = $donor->purchase_count;
Expand Down
14 changes: 13 additions & 1 deletion includes/admin/tools/export/class-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,21 @@ public function can_export() {
public function headers() {
give_ignore_user_abort();

/**
* Filter to Modify CSV file name
*
* @since 2.0.7
*
* @param $file_name string file name
* @param$export_type string export type name
*
* @return $file_name string file name
*/
$file_name = apply_filters( 'give_export_filename', 'give-export-' . $this->export_type . '-' . date( 'm-d-Y' ), $this->export_type );

nocache_headers();
header( 'Content-Type: text/csv; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=give-export-' . $this->export_type . '-' . date( 'm-d-Y' ) . '.csv' );
header( 'Content-Disposition: attachment; filename=' . $file_name . '.csv' );
header( "Expires: 0" );
}

Expand Down
15 changes: 4 additions & 11 deletions includes/admin/tools/views/html-admin-page-exports.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ class="button-secondary"/>
<tr class="give-export-donors">
<td scope="row" class="row-title">
<h3>
<span><?php esc_html_e( 'Export Donors in CSV', 'give' ); ?></span>
<span><?php esc_html_e( 'Export Donors', 'give' ); ?></span>
</h3>
<p><?php esc_html_e( 'Download an export of donors for all donation forms or only those who have given to a particular form.', 'give' ); ?></p>
<p><?php esc_html_e( 'Download a CSV of donors. Column values reflect totals across all donation forms by default, or a single donation form if selected.', 'give' ); ?></p>
</td>
<td>
<form method="post" id="give_donor_export"
Expand Down Expand Up @@ -221,18 +221,11 @@ class="give-clearfix">
id="give-export-userid"><?php esc_html_e( 'User ID', 'give' ); ?>
</label>
</li>
<li>
<label for="give-export-donation-form">
<input type="checkbox" checked
name="give_export_option[donation_form]"
id="give-export-donation-form"><?php esc_html_e( 'Donation Form', 'give' ); ?>
</label>
</li>
<li>
<label for="give-export-first-donation-date">
<input type="checkbox" checked
name="give_export_option[date_first_donated]"
id="give-export-first-donation-date"><?php esc_html_e( 'First Donation Date', 'give' ); ?>
name="give_export_option[donor_created_date]"
id="give-export-first-donation-date"><?php esc_html_e( 'Donor Created Date', 'give' ); ?>
</label>
</li>
<li>
Expand Down

0 comments on commit 17fd784

Please sign in to comment.