PHP Class Give_Customer, Give

This class handles customers.
Since: 1.0
Mostrar archivo Open project: wordimpress/give Class Usage Examples

Public Properties

Property Type Description
$date_created string The customer's creation date
$email string The customer's email
$id integer The customer ID
$name string The customer's name
$notes string Customer Notes
$payment_ids array The payment IDs associated with the customer
$purchase_count integer The customer's purchase count
$purchase_value integer The customer's lifetime value
$user_id integer The user ID associated with the customer

Protected Properties

Property Type Description
$db Give_DB_Customers The Database Abstraction

Public Methods

Method Description
__construct ( boolean $_id_or_email = false, boolean $by_user_id = false ) Class Constructor
__get ( $key ) Magic __get function to dispatch a call to retrieve a private property.
add_meta ( string $meta_key = '', mixed $meta_value, boolean $unique = false ) : boolean Add meta data field to a customer.
add_note ( string $note = '' ) : string | boolean Add a note for the customer.
attach_payment ( integer $payment_id, boolean $update_stats = true ) : boolean Attach Payment
create ( array $data = [] ) : mixed Creates a customer
decrease_purchase_count ( integer $count = 1 ) : mixed Decrease the customer purchase count.
decrease_value ( float $value ) : mixed Decrease a customer's lifetime value.
delete_meta ( string $meta_key = '', mixed $meta_value = '' ) : boolean Remove metadata matching criteria from a customer.
get_meta ( string $meta_key = '', boolean $single = true ) : mixed Retrieve customer meta field for a customer.
get_notes ( integer $length = 20, integer $paged = 1 ) : array Get the parsed notes for a customer as an array.
get_notes_count ( ) : integer Get the total number of notes we have after parsing.
increase_purchase_count ( integer $count = 1 ) : integer Increase the purchase count of a customer.
increase_value ( float $value ) : mixed Increase the customer's lifetime value.
remove_payment ( integer $payment_id, boolean $update_stats = true ) : boolean Remove Payment
update ( array $data = [] ) : boolean Update a customer record
update_donation_value ( float $curr_amount, float $new_amount ) : mixed Decrease/Increase a customer's lifetime value.
update_meta ( string $meta_key = '', mixed $meta_value, mixed $prev_value = '' ) : boolean Update customer meta field based on customer ID.

Private Methods

Method Description
get_raw_notes ( ) : string Get the notes column for the customer
sanitize_columns ( array $data ) : array Sanitize the data for update/create
setup_customer ( object $customer ) : boolean Setup Customer

Method Details

__construct() public method

Set up the Give Customer Class.
Since: 1.0
public __construct ( boolean $_id_or_email = false, boolean $by_user_id = false )
$_id_or_email boolean
$by_user_id boolean

__get() public method

Magic __get function to dispatch a call to retrieve a private property.
Since: 1.0
public __get ( $key )

add_meta() public method

Add meta data field to a customer.
Since: 1.6
public add_meta ( string $meta_key = '', mixed $meta_value, boolean $unique = false ) : boolean
$meta_key string Metadata name. Default is empty.
$meta_value mixed Metadata value.
$unique boolean Optional. Whether the same key should not be added. Default is false.
return boolean False for failure. True for success.

add_note() public method

Add a note for the customer.
Since: 1.0
public add_note ( string $note = '' ) : string | boolean
$note string The note to add. Default is empty.
return string | boolean The new note if added successfully, false otherwise.

attach_payment() public method

Attach payment to the customer then triggers increasing stats.
Since: 1.0
public attach_payment ( integer $payment_id, boolean $update_stats = true ) : boolean
$payment_id integer The payment ID to attach to the customer.
$update_stats boolean For backwards compatibility, if we should increase the stats or not.
return boolean If the attachment was successfuly.

create() public method

Creates a customer
Since: 1.0
public create ( array $data = [] ) : mixed
$data array Array of attributes for a customer.
return mixed False if not a valid creation, Customer ID if user is found or valid creation.

decrease_purchase_count() public method

Decrease the customer purchase count.
Since: 1.0
public decrease_purchase_count ( integer $count = 1 ) : mixed
$count integer The amount to decrease by.
return mixed If successful, the new count, otherwise false.

decrease_value() public method

Decrease a customer's lifetime value.
Since: 1.0
public decrease_value ( float $value ) : mixed
$value float The value to decrease by.
return mixed If successful, the new value, otherwise false.

delete_meta() public method

Remove metadata matching criteria from a customer.
Since: 1.6
public delete_meta ( string $meta_key = '', mixed $meta_value = '' ) : boolean
$meta_key string Metadata name. Default is empty.
$meta_value mixed Optional. Metadata value. Default is empty.
return boolean False for failure. True for success.

get_meta() public method

Retrieve customer meta field for a customer.
Since: 1.6
public get_meta ( string $meta_key = '', boolean $single = true ) : mixed
$meta_key string The meta key to retrieve. Default is empty.
$single boolean Whether to return a single value. Default is true.
return mixed Will be an array if $single is false. Will be value of meta data field if $single is true.

get_notes() public method

Get the parsed notes for a customer as an array.
Since: 1.0
public get_notes ( integer $length = 20, integer $paged = 1 ) : array
$length integer The number of notes to get.
$paged integer What note to start at.
return array The notes requested.

get_notes_count() public method

Get the total number of notes we have after parsing.
Since: 1.0
public get_notes_count ( ) : integer
return integer The number of notes for the customer.

increase_purchase_count() public method

Increase the purchase count of a customer.
Since: 1.0
public increase_purchase_count ( integer $count = 1 ) : integer
$count integer The number to increment by.
return integer The purchase count.

increase_value() public method

Increase the customer's lifetime value.
Since: 1.0
public increase_value ( float $value ) : mixed
$value float The value to increase by.
return mixed If successful, the new value, otherwise false.

remove_payment() public method

Remove a payment from this customer, then triggers reducing stats.
Since: 1.0
public remove_payment ( integer $payment_id, boolean $update_stats = true ) : boolean
$payment_id integer The Payment ID to remove.
$update_stats boolean For backwards compatibility, if we should increase the stats or not.
return boolean If the removal was successful.

update() public method

Update a customer record
Since: 1.0
public update ( array $data = [] ) : boolean
$data array Array of data attributes for a customer (checked via whitelist).
return boolean If the update was successful or not.

update_donation_value() public method

This function will update donation stat on basis of current amount and new amount donation difference. Difference value can positive or negative. Negative value will decrease user donation stat while positive value increase donation stat.
Since: 1.0
public update_donation_value ( float $curr_amount, float $new_amount ) : mixed
$curr_amount float Current Donation amount.
$new_amount float New (changed) Donation amount.
return mixed If successful, the new donation stat value, otherwise false.

update_meta() public method

Update customer meta field based on customer ID.
Since: 1.6
public update_meta ( string $meta_key = '', mixed $meta_value, mixed $prev_value = '' ) : boolean
$meta_key string Metadata key. Default is empty.
$meta_value mixed Metadata value.
$prev_value mixed Optional. Previous value to check before removing. Default is empty.
return boolean False on failure, true if success.

Property Details

$date_created public_oe property

The customer's creation date
Since: 1.0
public string $date_created
return string

$db protected_oe property

The Database Abstraction
Since: 1.0
protected Give_DB_Customers $db
return Give_DB_Customers

$email public_oe property

The customer's email
Since: 1.0
public string $email
return string

$id public_oe property

The customer ID
Since: 1.0
public int $id
return integer

$name public_oe property

The customer's name
Since: 1.0
public string $name
return string

$notes public_oe property

Customer Notes
Since: 1.0
public string $notes
return string

$payment_ids public_oe property

The payment IDs associated with the customer
Since: 1.0
public array $payment_ids
return array

$purchase_count public_oe property

The customer's purchase count
Since: 1.0
public int $purchase_count
return integer

$purchase_value public_oe property

The customer's lifetime value
Since: 1.0
public int $purchase_value
return integer

$user_id public_oe property

The user ID associated with the customer
Since: 1.0
public int $user_id
return integer