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

Issues/1486 #1496

Merged
merged 3 commits into from
Feb 14, 2017
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
76 changes: 54 additions & 22 deletions includes/admin/customers/class-customer-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,28 +271,10 @@ public function get_search() {
public function reports_data() {
global $wpdb;

$data = array();
$paged = $this->get_paged();
$offset = $this->per_page * ( $paged - 1 );
$search = $this->get_search();
$order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC';
$orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id';

$args = array(
'number' => $this->per_page,
'offset' => $offset,
'order' => $order,
'orderby' => $orderby
);

if ( is_email( $search ) ) {
$args['email'] = $search;
} elseif ( is_numeric( $search ) ) {
$args['id'] = $search;
} else {
$args['name'] = $search;
}
$data = array();

// Get donor query.
$args = $this->get_donor_query();
$customers = Give()->customers->get_customers( $args );

if ( $customers ) {
Expand All @@ -316,6 +298,56 @@ public function reports_data() {
return $data;
}

/**
* Get donor count.
*
* @since 1.8.1
* @access private
*/
private function get_donor_count() {
// Get donor query.
$_donor_query = $this->get_donor_query();

$_donor_query['number'] = -1;
$donors = Give()->customers->get_customers( $_donor_query );

return count( $donors );
}

/**
* Get donor query.
*
* @since 1.8.1
* @access public
* @return array
*/
public function get_donor_query() {
$paged = $this->get_paged();
$offset = $this->per_page * ( $paged - 1 );
$search = $this->get_search();
$order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC';
$orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id';

$args = array(
'number' => $this->per_page,
'offset' => $offset,
'order' => $order,
'orderby' => $orderby,
);

if( $search ) {
if ( is_email( $search ) ) {
$args['email'] = $search;
} elseif ( is_numeric( $search ) ) {
$args['id'] = $search;
} else {
$args['name'] = $search;
}
}

return $args;
}

/**
* Setup the final data for the table.
*
Expand All @@ -337,7 +369,7 @@ public function prepare_items() {

$this->items = $this->reports_data();

$this->total = give_count_total_customers();
$this->total = $this->get_donor_count();

$this->set_pagination_args( array(
'total_items' => $this->total,
Expand Down
94 changes: 64 additions & 30 deletions includes/admin/reporting/class-donor-reports-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct() {
parent::__construct( array(
'singular' => esc_html__( 'Donor', 'give' ), // Singular name of the listed records
'plural' => esc_html__( 'Donors', 'give' ), // Plural name of the listed records
'ajax' => false // Does this table support ajax?
'ajax' => false,// Does this table support ajax?
) );

}
Expand Down Expand Up @@ -155,10 +155,10 @@ protected function display_tablenav( $which ) {
</div>


<br class="clear" />
<br class="clear"/>

</div>
<?php
<?php
}

/**
Expand All @@ -173,16 +173,16 @@ protected function display_tablenav( $which ) {
* @return string Column Name
*/
public function column_default( $item, $column_name ) {

switch ( $column_name ) {

case 'name' :
$name = '#' . $item['id'] . ' ';
$name .= ! empty( $item['name'] ) ? $item['name'] : '<em>' . esc_html__( 'Unnamed Donor', 'give' ) . '</em>';
$view_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $item['id'] );
$value = '<a href="' . esc_url( $view_url ) . '">' . $name . '</a>';
$value = '<a href="' . esc_url( $view_url ) . '">' . $name . '</a>';
break;

case 'num_donations' :
$value = '<a href="' .
admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . urlencode( $item['email'] )
Expand Down Expand Up @@ -213,7 +213,7 @@ public function get_columns() {
'name' => esc_html__( 'Name', 'give' ),
'email' => esc_html__( 'Email', 'give' ),
'num_donations' => esc_html__( 'Donations', 'give' ),
'amount_spent' => esc_html__( 'Total Donated', 'give' )
'amount_spent' => esc_html__( 'Total Donated', 'give' ),
);

return apply_filters( 'give_report_donor_columns', $columns );
Expand Down Expand Up @@ -281,26 +281,10 @@ public function get_search() {
public function reports_data() {
global $wpdb;

$data = array();
$paged = $this->get_paged();
$offset = $this->per_page * ( $paged - 1 );
$search = $this->get_search();
$order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC';
$orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id';

$args = array(
'number' => $this->per_page,
'offset' => $offset,
'order' => $order,
'orderby' => $orderby
);

if ( is_email( $search ) ) {
$args['email'] = $search;
} elseif ( is_numeric( $search ) ) {
$args['id'] = $search;
}
$data = array();

// Get donor query.
$args = $this->get_donor_query();
$donors = Give()->customers->get_customers( $args );

if ( $donors ) {
Expand All @@ -317,14 +301,64 @@ public function reports_data() {
'name' => $donor->name,
'email' => $donor->email,
'num_donations' => $donor->purchase_count,
'amount_spent' => $donor->purchase_value
'amount_spent' => $donor->purchase_value,
);
}
}

return $data;
}

/**
* Get donor count.
*
* @since 1.8.1
* @access private
*/
private function get_donor_count() {
// Get donor query.
$_donor_query = $this->get_donor_query();

$_donor_query['number'] = -1;
$donors = Give()->customers->get_customers( $_donor_query );

return count( $donors );
}

/**
* Get donor query.
*
* @since 1.8.1
* @access public
* @return array
*/
public function get_donor_query() {
$paged = $this->get_paged();
$offset = $this->per_page * ( $paged - 1 );
$search = $this->get_search();
$order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC';
$orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id';

$args = array(
'number' => $this->per_page,
'offset' => $offset,
'order' => $order,
'orderby' => $orderby,
);

if( $search ) {
if ( is_email( $search ) ) {
$args['email'] = $search;
} elseif ( is_numeric( $search ) ) {
$args['id'] = $search;
} else {
$args['name'] = $search;
}
}

return $args;
}

/**
* Setup the final data for the table
*
Expand All @@ -346,12 +380,12 @@ public function prepare_items() {

$this->items = $this->reports_data();

$this->total = give_count_total_customers();
$this->total = $this->get_donor_count();

$this->set_pagination_args( array(
'total_items' => $this->total,
'per_page' => $this->per_page,
'total_pages' => ceil( $this->total / $this->per_page )
'total_pages' => ceil( $this->total / $this->per_page ),
) );
}
}
}