Skip to content

Commit

Permalink
Deprecated give_get_users_purchases() for give_get_users_donations() #…
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinWalker committed Jun 1, 2017
1 parent dd55482 commit f6faeff
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 33 deletions.
24 changes: 24 additions & 0 deletions includes/deprecated/deprecated-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,27 @@ function give_get_purchase_stats_by_user( $user = '' ) {
return give_get_donation_stats_by_user( $user );

}

/**
* Get Users Donations
*
* Retrieves a list of all donations by a specific user.
*
* @since 1.0
*
* @param int $user User ID or email address
* @param int $number Number of donations to retrieve
* @param bool $pagination
* @param string $status
*
* @return bool|object List of all user donations
*/
function give_get_users_purchases( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) {

$backtrace = debug_backtrace();

_give_deprecated_function( __FUNCTION__, '1.8.9', 'give_count_donations_of_donor', $backtrace );

return give_get_users_donations( $user, $number, $pagination, $status );

}
33 changes: 14 additions & 19 deletions includes/user-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
*
* @since 1.0
*
* @param int $user User ID or email address
* @param int $number Number of donations to retrieve
* @param int $user User ID or email address.
* @param int $number Number of donations to retrieve.
* @param bool $pagination
* @param string $status
*
* @return bool|object List of all user donations
* @return bool|array List of all user donations.
*/
function give_get_users_purchases( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) {
function give_get_users_donations( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) {

if ( empty( $user ) ) {
$user = get_current_user_id();
Expand All @@ -41,14 +41,13 @@ function give_get_users_purchases( $user = 0, $number = 20, $pagination = false,
}

$status = $status === 'complete' ? 'publish' : $status;
$paged = 1;

if ( $pagination ) {
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var( 'paged' );
} elseif ( get_query_var( 'page' ) ) {
$paged = get_query_var( 'page' );
} else {
$paged = 1;
}
}

Expand All @@ -60,22 +59,18 @@ function give_get_users_purchases( $user = 0, $number = 20, $pagination = false,
) );

if ( $pagination ) {

$args['page'] = $paged;

} else {

$args['nopaging'] = true;

}

$by_user_id = is_numeric( $user ) ? true : false;
$customer = new Give_Donor( $user, $by_user_id );
$donor = new Give_Donor( $user, $by_user_id );

if ( ! empty( $customer->payment_ids ) ) {
if ( ! empty( $donor->payment_ids ) ) {

unset( $args['user'] );
$args['post__in'] = array_map( 'absint', explode( ',', $customer->payment_ids ) );
$args['post__in'] = array_map( 'absint', explode( ',', $donor->payment_ids ) );

}

Expand All @@ -92,7 +87,7 @@ function give_get_users_purchases( $user = 0, $number = 20, $pagination = false,
/**
* Get Users Donations
*
* Returns a list of unique donation forms given to by a specific user
* Returns a list of unique donation forms given to by a specific user.
*
* @since 1.0
*
Expand All @@ -112,14 +107,14 @@ function give_get_users_completed_donations( $user = 0, $status = 'complete' ) {

$by_user_id = is_numeric( $user ) ? true : false;

$customer = new Give_Donor( $user, $by_user_id );
$donor = new Give_Donor( $user, $by_user_id );

if ( empty( $customer->payment_ids ) ) {
if ( empty( $donor->payment_ids ) ) {
return false;
}

// Get all the items donated
$payment_ids = array_reverse( explode( ',', $customer->payment_ids ) );
// Get all the items donated.
$payment_ids = array_reverse( explode( ',', $donor->payment_ids ) );
$limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 );
if ( ! empty( $limit_payments ) ) {
$payment_ids = array_slice( $payment_ids, 0, $limit_payments );
Expand Down Expand Up @@ -180,7 +175,7 @@ function give_has_purchases( $user_id = null ) {
$user_id = get_current_user_id();
}

if ( give_get_users_purchases( $user_id, 1 ) ) {
if ( give_get_users_donations( $user_id, 1 ) ) {
return true; // User has at least one donation
}

Expand Down
6 changes: 3 additions & 3 deletions templates/history-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

// User's Donations
if ( is_user_logged_in() ) {
$donations = give_get_users_purchases( get_current_user_id(), 20, true, 'any' );
$donations = give_get_users_donations( get_current_user_id(), 20, true, 'any' );
} elseif ( Give()->email_access->token_exists ) {
// Email Access Token?
$donations = give_get_users_purchases( 0, 20, true, 'any' );
$donations = give_get_users_donations( 0, 20, true, 'any' );
} elseif ( Give()->session->get_session_expiration() !== false ) {
// Session active?
$email = Give()->session->get( 'give_email' );
$donations = give_get_users_purchases( $email, 20, true, 'any' );
$donations = give_get_users_donations( $email, 20, true, 'any' );
}

if ( $donations ) : ?>
Expand Down
37 changes: 26 additions & 11 deletions tests/unit-tests/tests-donors.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Give_Tests_Donors extends Give_Unit_Test_Case {

protected $_user_id = null;

protected $_customer_id = null;
protected $_donor_id = null;

/**
* Set it up
Expand Down Expand Up @@ -131,11 +131,11 @@ public function test_add_customer() {
}

/**
* Test Update Customer
* Test Update Donor
*
* @covers Give_Donor::update
*/
public function test_update_customer() {
public function test_update_donor() {

$test_email = 'testaccount2@domain.com';

Expand Down Expand Up @@ -166,6 +166,9 @@ public function test_magic_get_method() {

}

/**
* Test attach payment.
*/
public function test_attach_payment() {

$donor = new Give_Donor( 'testadmin@domain.com' );
Expand All @@ -175,26 +178,32 @@ public function test_attach_payment() {

$this->assertTrue( in_array( 5222222, $payment_ids ) );

// Verify if we don't send a payment, we get false
// Verify if we don't send a payment, we get false.
$this->assertFalse( $donor->attach_payment() );

}

/**
* Test attach duplicate payment.
*/
public function test_attach_duplicate_payment() {

// Verify that if we pass a payment that's already attached we do not change stats
// Verify that if we pass a payment that's already attached we do not change stats.
$donor = new Give_Donor( 'testadmin@domain.com' );
$payments = array_map( 'absint', explode( ',', $donor->payment_ids ) );

$expected_purcahse_count = $donor->purchase_count;
$expected_purcahse_value = $donor->purchase_value;
$expected_purchase_count = $donor->purchase_count;
$expected_purchase_value = $donor->purchase_value;

$donor->attach_payment( $payments[0] );
$this->assertEquals( $expected_purcahse_count, $donor->purchase_count );
$this->assertEquals( $expected_purcahse_value, $donor->purchase_value );
$this->assertEquals( $expected_purchase_count, $donor->purchase_count );
$this->assertEquals( $expected_purchase_value, $donor->purchase_value );

}

/**
* Test remove payment.
*/
public function test_remove_payment() {

$donor = new Give_Donor( 'testadmin@domain.com' );
Expand All @@ -209,6 +218,9 @@ public function test_remove_payment() {
$this->assertFalse( in_array( 5222223, $payment_ids ) );
}

/**
* Test increment stats.
*/
public function test_increment_stats() {

$donor = new Give_Donor( 'testadmin@domain.com' );
Expand Down Expand Up @@ -259,6 +271,9 @@ public function test_decrement_stats() {

}

/**
* Test donor notes.
*/
public function test_donor_notes() {

$donor = new Give_Donor( 'testadmin@domain.com' );
Expand Down Expand Up @@ -294,14 +309,14 @@ public function test_donor_notes() {
*/
public function test_users_purchases() {

$out = give_get_users_purchases( $this->_user_id );
$out = give_get_users_donations( $this->_user_id );

$this->assertInternalType( 'object', $out[0] );
$this->assertEquals( 'give_payment', $out[0]->post_type );
$this->assertTrue( give_has_purchases( $this->_user_id ) );
$this->assertEquals( 1, give_count_donations_of_donor( $this->_user_id ) );

$no_user = give_get_users_purchases( 0 );
$no_user = give_get_users_donations( 0 );
$this->assertFalse( $no_user );

$no_user_count = give_count_donations_of_donor();
Expand Down

0 comments on commit f6faeff

Please sign in to comment.