Skip to content

Commit

Permalink
[#910] Auction Ending Time Bug (Attempt 2) (#914)
Browse files Browse the repository at this point in the history
* [#910] Disable Main Site All Auctions Transients

* [#910] Simpler use of Auction template part, detailed Time Remaining

* [#910] Debugging info

* [#910] A bit more debugging info
  • Loading branch information
bd-viget authored Apr 17, 2024
1 parent 65668ca commit e448053
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 25 deletions.
19 changes: 19 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auction.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,25 @@ public function get_end_date_time( string $format = '' ): string {
return goodbids()->utilities->format_date_time( $end, $format );
}

/**
* Get the Original Auction End Date/Time
*
* @since 1.0.1
*
* @param string $format
*
* @return string
*/
public function get_original_end_date_time( string $format = '' ): string {
$end = get_post_meta( $this->get_id(), 'auction_end', true );

if ( ! $end ) {
return '';
}

return goodbids()->utilities->format_date_time( $end, $format );
}

/**
* Check if an Auction has started.
*
Expand Down
16 changes: 8 additions & 8 deletions client-mu-plugins/goodbids/src/classes/Network/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,11 @@ function (): string {
* @return array
*/
public function get_all_auctions( array $query_args = [] ): array {
$auctions = empty( $query_args ) ? get_transient( self::ALL_AUCTIONS_TRANSIENT ) : false;

if ( $auctions ) {
return $auctions;
}
// $auctions = empty( $query_args ) ? get_transient( self::ALL_AUCTIONS_TRANSIENT ) : false;
//
// if ( $auctions ) {
// return $auctions;
// }

$auctions = $this->loop(
fn ( int $site_id ) => collect( ( goodbids()->auctions->get_all( $query_args ) )->posts )
Expand All @@ -783,9 +783,9 @@ function () {
->all()
);

if ( empty( $query_args ) ) {
set_transient( self::ALL_AUCTIONS_TRANSIENT, $auctions, DAY_IN_SECONDS );
}
// if ( empty( $query_args ) ) {
// set_transient( self::ALL_AUCTIONS_TRANSIENT, $auctions, DAY_IN_SECONDS );
// }

return $auctions;
}
Expand Down
48 changes: 38 additions & 10 deletions client-mu-plugins/goodbids/views/parts/auction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
*
* Used inside of auction loop.
*
* @global int $auction_id
*
* @since 1.0.0
* @package GoodBids
*/

use GoodBids\Auctions\Auctions;
use GoodBids\Utilities\Log;

global $post;

if ( ! empty( $auction_id ) ) {
$post = get_post( $auction_id ); // phpcs:ignore
setup_postdata( $post );
}

$auction = goodbids()->auctions->get();
$url = is_admin() ? '#' : $auction->get_url();
$time_class = '';
Expand All @@ -26,6 +36,7 @@
Log::error( $e->getMessage() );
$end_date = $auction->get_end_date_time();
}

$remaining_time = $current_date->diff( $end_date );

$time = sprintf(
Expand All @@ -35,14 +46,21 @@
__( 'if nobody else bids', 'goodbids' )
);

if ( $remaining_time->d < 1 && $remaining_time->h >= 1 ) {
$clock_svg = true;
$time = $remaining_time->format( '%hh %im' );
}
if ( $remaining_time->d < 1 && $remaining_time->h < 1 ) {
$time_class .= 'text-gb-red-500';
$clock_svg = true;
$time = $remaining_time->format( '%im' );
if ( $remaining_time->d < 1 ) { // Less than 1 day remaining.
if ( $remaining_time->h >= 1 ) {
$time = $remaining_time->format( '%hh %im' );
$clock_svg = true;
} elseif ( $remaining_time->h <= 0 && $remaining_time->i >= 1 ) { // Less than 1 hour remaining.
$time_class .= 'text-gb-red-500';
$time = $remaining_time->format( '%im' );
$clock_svg = true;
} elseif ( $remaining_time->i <= 0 && $remaining_time->s >= 1 ) { // Less than 1 minute remaining.
$time_class .= 'text-gb-red-500';
$time = $remaining_time->format( '%ss' );
$clock_svg = true;
} else { // Auction has ended.
$time = __( 'Ended', 'goodbids' );
}
}
} else {
try {
Expand Down Expand Up @@ -89,9 +107,9 @@
</a>

<a href="<?php echo esc_url( $url ); ?>" class="no-underline hover:underline">
<?php if ( get_the_title() ) : ?>
<?php if ( $auction->get_title() ) : ?>
<h2 class="mt-4 mb-0 normal-case wp-block-post-title has-large-font-size line-clamp-3">
<?php the_title(); ?>
<?php echo esc_html( $auction->get_title() ); ?>
</h2>
<?php endif; ?>
</a>
Expand All @@ -113,4 +131,14 @@
<?php echo esc_html( $auction->get_watch_count() ); ?>
</div>
</div>
<div style="font-size:11px">
<div>End Date/Time: <?php echo esc_html( $auction->get_end_date_time() ); ?></div>
<div>End Date/Time (Original): <?php echo esc_html( $auction->get_original_end_date_time() ); ?></div>
<div>Close Date/Time: <?php echo esc_html( get_post_meta( $auction->get_id(), Auctions::AUCTION_CLOSE_META_KEY, true ) ); ?></div>
<div>Extensions: <?php echo esc_html( $auction->get_extensions() ); ?></div>
<div>Extension Window: <?php echo esc_html( $auction->get_bid_extension_formatted() ); ?></div>
<div>Site ID: <?php echo esc_html( get_current_blog_id() ); ?></div>
</div>
</li>
<?php
wp_reset_postdata();
8 changes: 1 addition & 7 deletions client-mu-plugins/goodbids/views/parts/auctions-grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
foreach ( $auctions as $auction ) :
goodbids()->sites->swap(
function () use ( $auction ) {
global $post;
$og_post = $post;
$post = get_post( $auction['post_id'] ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited

goodbids()->load_view( 'parts/auction.php', compact( 'post' ) );

$post = $og_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
goodbids()->load_view( 'parts/auction.php', [ 'auction_id' => $auction['post_id'] ] );
},
$auction['site_id']
);
Expand Down

0 comments on commit e448053

Please sign in to comment.