Skip to content

Commit

Permalink
[#666] My Account - Closed Auctions 😈 (#685)
Browse files Browse the repository at this point in the history
* [#666] updating clear transients

* [#666] Reorganizing auction array in My account
Pulling bid auctions  from get_user_participating_auctions
  • Loading branch information
nathan-schmidt-viget authored Mar 12, 2024
1 parent 80a270a commit 2f02126
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions client-mu-plugins/goodbids/src/classes/Network/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ function ( int $post_id ): void {
*/
public function clear_all_site_transients(): void {
$this->loop(
fn () => delete_transient( self::ALL_AUCTIONS_TRANSIENT ),
fn () => goodbids()->auctions->clear_transients(),
);
}

Expand Down Expand Up @@ -1070,27 +1070,10 @@ public function get_watched_bid_auctions_by_user( ?int $user_id = null ): array
if ( is_null( $user_id ) ) {
$user_id = get_current_user_id();
}

$goodbids_orders = goodbids()->sites->get_user_bid_orders();
$auctions = [];
$auctions = [];

// Get user Bids from all sites
foreach ( $goodbids_orders as $goodbids_order ) {
$auction_id = goodbids()->sites->swap(
fn () => goodbids()->woocommerce->orders->get_auction_id( $goodbids_order['order_id'] ),
$goodbids_order['site_id']
);

if ( 'publish' !== get_post_status( $auction_id ) ) {
continue;
}

$bid_auction = [
'site_id' => $goodbids_order['site_id'],
'post_id' => $auction_id,
];
$auctions[] = $bid_auction;
}
$auctions = $this->get_user_participating_auctions( $user_id );

// Get all Watchers for user from all sites
goodbids()->sites->loop(
Expand All @@ -1108,40 +1091,43 @@ function ( $site_id ) use ( &$auctions, $user_id ) {
continue;
}

$watched_auction = [
'site_id' => $site_id,
'post_id' => $auction_id,
$auctions[] = [
'site_id' => $site_id,
'auction_id' => $auction_id,
];
$auctions[] = $watched_auction;
}
}
);

// Filter by started and not ended and sort by end date
return collect( $auctions )
->unique(
function ( $auction_data ) {
return $auction_data['site_id'] . '|' . $auction_data['post_id'];
}
)
->filter(
fn ( array $auction_data ) => goodbids()->sites->swap(
function () use ( $auction_data ) {
$auction = goodbids()->auctions->get( $auction_data['post_id'] );
return $auction->has_started() && ! $auction->has_ended();
fn ( array $item ) => $this->swap(
function () use ( &$item ) {
$auction = goodbids()->auctions->get( $item['auction_id'] );
return Auction::STATUS_LIVE === $auction->get_status();
},
$auction_data['site_id']
$item['site_id']
)
)
->unique(
fn ( $auction_data ) => $auction_data['site_id'] . '|' . $auction_data['auction_id']
)
->sortBy(
fn ( array $auction_data ) => goodbids()->sites->swap(
function () use ( $auction_data ) {
$auction = goodbids()->auctions->get( $auction_data['post_id'] );
$auction = goodbids()->auctions->get( $auction_data['auction_id'] );
return $auction->get_end_date_time();
},
$auction_data['site_id']
)
)
// Using WP default post_id in view
->map(
fn ( array $auction_data ) => [
'post_id' => $auction_data['auction_id'],
'site_id' => $auction_data['site_id'],
]
)
->all();
}

Expand Down

0 comments on commit 2f02126

Please sign in to comment.