Skip to content

Commit

Permalink
[#618] Fixed so many bugs. (#627)
Browse files Browse the repository at this point in the history
* [#618] Fixed so many bugs.

* [#618] Found another one.

* [#618] Another one! - DJ Khaled
  • Loading branch information
bd-viget authored Mar 7, 2024
1 parent 8d882e8 commit f0395c2
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 4 deletions.
136 changes: 136 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auction.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ public function get_estimated_value(): int {
return intval( $this->get_setting( 'estimated_value' ) );
}

/**
* Get the formatted Auction Reward Estimated Value.
*
* @since 1.0.0
*
* @return string
*/
public function get_estimated_value_formatted(): string {
return wc_price( $this->get_estimated_value() );
}

/**
* Get the Auction Start Date/Time
*
Expand Down Expand Up @@ -401,6 +412,55 @@ public function get_bid_extension(): ?int {
return ( $minutes * MINUTE_IN_SECONDS ) + $seconds;
}

/**
* Get the formatted Auction Bid Extension time
*
* @since 1.0.0
*
* @return string
*/
public function get_bid_extension_formatted(): string {
$seconds = $this->get_bid_extension();

if ( is_null( $seconds ) ) {
return '';
}

if ( $seconds < MINUTE_IN_SECONDS ) {
return sprintf(
'%d %s',
$seconds,
_n( 'second', 'seconds', $seconds, 'goodbids' )
);
}

$min = floor( $seconds / MINUTE_IN_SECONDS );
$sec = $seconds % MINUTE_IN_SECONDS;

if ( $seconds < HOUR_IN_SECONDS ) {
return sprintf(
'%d %s and %d %s',
$min,
_n( 'minute', 'minutes', $min, 'goodbids' ),
$sec,
_n( 'second', 'seconds', $sec, 'goodbids' )
);
}

$hr = floor( $seconds / HOUR_IN_SECONDS );
$min = floor( ( $seconds % HOUR_IN_SECONDS ) / MINUTE_IN_SECONDS );

return sprintf(
'%d %s, %d %s, and %d %s',
$hr,
_n( 'hour', 'hours', $hr, 'goodbids' ),
$min,
_n( 'minute', 'minutes', $min, 'goodbids' ),
$sec,
_n( 'second', 'seconds', $sec, 'goodbids' )
);
}

/**
* Get the Auction Bid Increment amount
*
Expand All @@ -412,6 +472,17 @@ public function get_bid_increment(): int {
return intval( $this->get_setting( 'bid_increment' ) );
}

/**
* Get the Formatted Auction Bid Increment amount
*
* @since 1.0.0
*
* @return string
*/
public function get_bid_increment_formatted(): string {
return wc_price( $this->get_bid_increment() );
}

/**
* Get the Auction Starting Bid amount
*
Expand Down Expand Up @@ -450,6 +521,17 @@ public function get_goal(): int {
return intval( $this->get_setting( 'auction_goal' ) );
}

/**
* Get the formatted Auction Goal Amount
*
* @since 1.0.0
*
* @return string
*/
public function get_goal_formatted(): string {
return wc_price( $this->get_goal() );
}

/**
* Get the Auction Expected High Bid Amount
*
Expand All @@ -461,6 +543,17 @@ public function get_expected_high_bid(): int {
return intval( $this->get_setting( 'expected_high_bid' ) );
}

/**
* Get the formatted Auction Expected High Bid Amount
*
* @since 1.0.0
*
* @return string
*/
public function get_expected_high_bid_formatted(): string {
return wc_price( $this->get_expected_high_bid() );
}

/**
* Checks if Free Bids are allowed on Auction
*
Expand Down Expand Up @@ -559,6 +652,25 @@ public function maybe_award_free_bid( ?int $user_id = null, string $description
public function get_bid_order_ids( int $limit = -1, ?int $user_id = null ): array {
return goodbids()->auctions->get_bid_order_ids( $this->get_id(), $limit, $user_id );
}

/**
* Get the User's last bid on this Auction
*
* @since 1.0.0
*
* @param ?int $user_id
*
* @return ?WC_Order
*/
public function get_user_last_bid( ?int $user_id = null ): ?WC_Order {
$orders = $this->get_bid_order_ids( 1, $user_id );
if ( ! $orders ) {
return null;
}

return wc_get_order( $orders[0] );
}

/**
* Get Order IDs that have been placed using a Free Bid.
*
Expand Down Expand Up @@ -677,6 +789,17 @@ public function get_total_raised(): float {
return $total;
}

/**
* Get the formatted Auction Total Raised
*
* @since 1.0.0
*
* @return string
*/
public function get_total_raised_formatted(): string {
return wc_price( $this->get_total_raised() );
}

/**
* Alias get_bid_count method.
*
Expand All @@ -702,6 +825,19 @@ public function get_user_total_donated( int $user_id ): float {
->sum( fn( $order ) => $order->get_total( 'edit' ) );
}

/**
* Get the formatted Auction Total Donated by User
*
* @since 1.0.0
*
* @param int $user_id
*
* @return string
*/
public function get_user_total_donated_formatted( int $user_id ): string {
return wc_price( $this->get_user_total_donated( $user_id ) );
}

/**
* Get the last bid order for an Auction.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function ( int $order_id, int $auction_id ) {
$next = false;
$order = false;
foreach ( $bid_orders as $bid_order ) {
if ( $bid_order === $order_id ) {
if ( $bid_order->get_id() === $order_id ) {
$next = true;
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,10 @@ private function default_placeholders(): void {
$this->add_placeholder( '{reward.claim_deadline_date}', goodbids()->rewards->get_claim_deadline_date( $auction?->get_id() ) );

// User Details.
$last_bid = $auction?->get_user_last_bid( $this->user_id );
$last_bid_amount = $last_bid ? $last_bid->get_subtotal() : 0;
$user_last_bid = $auction?->get_user_last_bid( $this->user_id );
$user_last_bid_amount = $user_last_bid ? $user_last_bid->get_subtotal() : 0;
$this->add_placeholder( '{user.name}', $this->get_user_name() );
$this->add_placeholder( '{user.last_bid_amount}', wc_price( $last_bid_amount ) );
$this->add_placeholder( '{user.last_bid_amount}', wc_price( $user_last_bid_amount ) );

$user_bid_count = $this->user_id ? $auction?->get_user_bid_count( $this->user_id ) : '';
$this->add_placeholder( '{user.bid_count}', $user_bid_count );
Expand Down

0 comments on commit f0395c2

Please sign in to comment.