cb-transactions-functions.php
Table of Contents
Functions
- cb_activity_bits() : mixed
- CB Activity Bits
- cb_transactions_get_total_sent_today() : int
- CB Transactions Get Total Sent Today
- cb_transactions_get_request_balance() : int
- CB Transactions Get Request Balance
- cb_transactions_get_transfer_balance() : int
- CB Transactions Get Transfer Balance
- cb_transactions_check_activity_bits() : mixed
- CB Transactions Check Activity Bits
- cb_transactions_get_activity_posts() : array<string|int, mixed>
- CB Transactions Get Activity Posts
- cb_transactions_get_activity_transactions() : array<string|int, mixed>
- CB Transactions Get Activity Transactions
- cb_transactions_calculate_activity_bits() : array<string|int, mixed>
- CB Transactions Calculate Activity Bits
- cb_transactions_has_bits() : bool
- CB Transactions Has Bits
- cb_transactions_birthday_bits() : mixed
- CB Transactions Birthday Bits
- cb_transactions_anniversary_bits() : mixed
- CB Transactions Anniversary Bits
- cb_transactions_get_amount_from_anniversary() : int
- CB Transactions Get Amount From Anniversary
- cb_transactions_get_leaderboard() : array<string|int, mixed>
- CB Transactions Get Leaderboard
- cb_transactions_delete_transaction() : int
- CB Transactions Delete Transaction
- cb_transactions_new_transaction() : mixed
- CB Transactions New Transaction
- cb_transactions_remove_bits() : mixed
- CB Transactions Remove Bits
- cb_transactions_new_events_transaction() : int|bool|string
- A supplemental helper function that will let us process event-based transactions without modifying existing API stuff too much.
- cb_transactions_new_contests_transaction() : int|bool|string
- A supplemental helper function that will let us process contest-based transactions without modifying existing API stuff too much.
Functions
cb_activity_bits()
CB Activity Bits
cb_activity_bits(string $content, int $user_id, int $activity_id) : mixed
This hooks onto the BP Activity Posted Update action to give someone Confetti Bits when they post an update.
Parameters
- $content : string
-
The content of the activity post.
- $user_id : int
-
The id of the user associated with the activity post.
- $activity_id : int
-
The id of the activity post.
Tags
cb_transactions_get_total_sent_today()
CB Transactions Get Total Sent Today
cb_transactions_get_total_sent_today() : int
This function gets the total number of Confetti Bits that have been sent for the current day.
Tags
Return values
int —$total The total number of Confetti Bits sent for the current day.
cb_transactions_get_request_balance()
CB Transactions Get Request Balance
cb_transactions_get_request_balance([int $user_id = 0 ]) : int
Get the balance available to a user for the current spending cycle. The request balance resets 1 month after users are done earning for the year.
So the balance that is returned is a calculation based on the following timeline:
- When the earning cycle starts, the available balance for requests is accrued for one year. They may then spend those for an additional month after that.
- date_sent >= $cb->earn_start, date_sent <= earn_end, amount > 0
- date_sent >= $cb->earn_start, date_sent <= spend_end, amount < 0
Parameters
- $user_id : int = 0
-
The ID for the user whose balance we want.
Tags
Return values
int —The calculated balance available for requests.
cb_transactions_get_transfer_balance()
CB Transactions Get Transfer Balance
cb_transactions_get_transfer_balance([int $user_id = 0 ]) : int
Get the balance available to a user for the current earning cycle.
Parameters
- $user_id : int = 0
-
The ID for the user whose balance we want.
Tags
Return values
int —The calculated balance available for transfers.
cb_transactions_check_activity_bits()
CB Transactions Check Activity Bits
cb_transactions_check_activity_bits([int $user_id = 0 ]) : mixed
Checks to see if there were any days throughout the cycle where the user might have posted on the BuddyBoss activity feed, and didn't receive any points for it. Helps cover our tail if we accidentally push some breaking changes or do something silly with how activity bits are registered.
Parameters
- $user_id : int = 0
-
The ID for the user we want to check.
Tags
cb_transactions_get_activity_posts()
CB Transactions Get Activity Posts
cb_transactions_get_activity_posts([int $user_id = 0 ]) : array<string|int, mixed>
Returns an array of activity posts for the given user. Uses BuddyBoss's global value for the activities table name.
Parameters
- $user_id : int = 0
-
The ID of the user whose posts we want.
Tags
Return values
array<string|int, mixed> —An array of activity posts, if any.
cb_transactions_get_activity_transactions()
CB Transactions Get Activity Transactions
cb_transactions_get_activity_transactions([int $user_id = 0 ]) : array<string|int, mixed>
Retrieves a list of all transactions from the current earning cycle that were registered by a user posting on the BuddyBoss activity feed.
Parameters
- $user_id : int = 0
-
The user's ID. Default current user ID.
Tags
Return values
array<string|int, mixed> —An array of transactions, if there are any.
cb_transactions_calculate_activity_bits()
CB Transactions Calculate Activity Bits
cb_transactions_calculate_activity_bits([array<string|int, mixed> $activities = array() ][, array<string|int, mixed> $transactions = array() ]) : array<string|int, mixed>
Calculates how many points a user should receive according to the number of unaccounted for activity posts they've sent out, that don't have an accompanying Confetti Bits transaction on that same day.
Parameters
- $activities : array<string|int, mixed> = array()
-
An array of activity posts
- $transactions : array<string|int, mixed> = array()
-
An array of transactions
Tags
Return values
array<string|int, mixed> —An array of activity posts that are missing an accompanying transaction on a given day.
cb_transactions_has_bits()
CB Transactions Has Bits
cb_transactions_has_bits([string $action = '' ]) : bool
Checks whether the user has gotten Confetti Bits for a specific action this year.
Parameters
- $action : string = ''
-
The action to check the database for. Usually either "birthday" or "anniversary".
Tags
Return values
bool —Whether we found an entry for the given action within the past year.
cb_transactions_birthday_bits()
CB Transactions Birthday Bits
cb_transactions_birthday_bits() : mixed
Gives the user Confetti Bits on their birthday.
Tags
cb_transactions_anniversary_bits()
CB Transactions Anniversary Bits
cb_transactions_anniversary_bits() : mixed
Gives the user Confetti Bits on their anniversary.
Tags
cb_transactions_get_amount_from_anniversary()
CB Transactions Get Amount From Anniversary
cb_transactions_get_amount_from_anniversary(DateTime $date) : int
Parameters
- $date : DateTime
Tags
Return values
int —The transaction amount appropriate for the anniversary date
cb_transactions_get_leaderboard()
CB Transactions Get Leaderboard
cb_transactions_get_leaderboard([mixed $limit = true ][, mixed $previous = false ]) : array<string|int, mixed>
Queries the database for the top 15 users by Confetti Bits balance Also includes the current user if they aren't in the top 15
Parameters
- $limit : mixed = true
- $previous : mixed = false
Tags
Return values
array<string|int, mixed> —$results The top 15 users by Confetti Bits balance, or the top 15 users by Confetti Bits balance with the current user included
cb_transactions_delete_transaction()
CB Transactions Delete Transaction
cb_transactions_delete_transaction([array<string|int, mixed> $args = [] ]) : int
Delete a transaction from the database. Do this at your own risk, you cannot undo this action.
Parameters
- $args : array<string|int, mixed> = []
-
{ An associative array of keys and values to check the database for. Accepts any property of a CB_Transactions_Transaction object. Example: ['recipient_id' => 5, 'component_action' => 'cb_activity_bits'] Passing the above will delete all transactions where the recipient_id is 5, and the component_action is cb_activity_bits. }
Tags
Return values
int —The number of rows affected. @see $wpdb::delete()
cb_transactions_new_transaction()
CB Transactions New Transaction
cb_transactions_new_transaction([array<string|int, mixed> $args = [] ]) : mixed
Manages sending bits between users. Yikes.
Parameters
- $args : array<string|int, mixed> = []
-
An array of arguments that get merged into a set of default values. {
@var int $item_id The item ID associated with the transaction. Used with BuddyBoss's Notifications API to help format some dynamic information in the notifications. We use the sender_id for this.
@var int $secondary_item_id The secondary item ID associated with the transaction. Used with BuddyBoss's Notifications API to help format some dynamic information in the notifications. We use the recipient_id for this.
@var int $sender_id The ID of the user sending the bits.
@var int $recipient_id The ID of the user recieving the bits.
@var datetime $date_sent The date and time of the transaction.
@var string $log_entry A note that usually references the purpose for the transaction.
@TODO: Make log entries optional?
@var string $component_name The name associated with the component that is sending the bits. Used with BuddyBoss's Notifications API. This will almost always just be 'confetti_bits'.
@var string $component_action The action associated with the transaction. We use this to differentiate transaction types to easily categorize them and run calculations. It is also used with BuddyBoss's Notifications API to send certain notifications that are associated with certain actions. }
Tags
cb_transactions_remove_bits()
CB Transactions Remove Bits
cb_transactions_remove_bits(mixed $id, mixed $reassign, mixed $user) : mixed
This is hooked into the delete_user action, so that transactions get deleted whenever a user is.
Parameters
- $id : mixed
- $reassign : mixed
- $user : mixed
Tags
cb_transactions_new_events_transaction()
A supplemental helper function that will let us process event-based transactions without modifying existing API stuff too much.
cb_transactions_new_events_transaction([array<string|int, mixed> $args = [] ]) : int|bool|string
We'll likely add more robust error handling later on. It's just getting down to the wire and we gotta push this out ASAP.
Parameters
- $args : array<string|int, mixed> = []
-
{ An array of arguments. All required.
@type int $event_id The ID of the event object. @type int $recipient_id The ID of the recipient user.
}
Tags
Return values
int|bool|string —Transaction ID on full success, false if something is missing, an error message if something when wrong.
cb_transactions_new_contests_transaction()
A supplemental helper function that will let us process contest-based transactions without modifying existing API stuff too much.
cb_transactions_new_contests_transaction([array<string|int, mixed> $args = [] ]) : int|bool|string
We'll likely add more robust error handling later on. It's just getting down to the wire and we gotta push this out ASAP.
Parameters
- $args : array<string|int, mixed> = []
-
{ An array of arguments. All required.
@type int $event_id The ID of the event object. @type int $recipient_id The ID of the recipient user.
}
Tags
Return values
int|bool|string —Transaction ID on full success, false if something is missing, an error message if something when wrong.