[], 'total' => 0, 'page' => 1, 'pages' => 0]; } $page = max(1, (int) $page); $offset = ($page - 1) * self::PER_PAGE; $rows = []; $total = 0; foreach ($providers as $id => $provider) { $total += $provider->count_bookings($search); $bookings = $provider->list_bookings(self::PER_PAGE, $offset, $search); if (!$bookings) { continue; } // One store query for the whole page rather than one per booking. $keys = []; foreach ($bookings as $booking) { $keys[] = $id . ':' . $booking['booking_id']; } $passes = ATW_Bookly_Pass_Store::get_many($keys); foreach ($bookings as $booking) { $key = $id . ':' . $booking['booking_id']; $booking['provider'] = $provider->label(); $stored = isset($passes[$key]) ? $passes[$key] : null; $booking['pass'] = $stored && !empty($stored['share_url']) ? $stored : null; $booking['failure'] = $stored && empty($stored['share_url']) && !empty($stored['create_error']) ? $stored['create_error'] : null; $rows[] = $booking; } } return [ 'rows' => $rows, 'total' => $total, 'page' => $page, 'pages' => (int) ceil($total / self::PER_PAGE), ]; } /** * 'Y-m-d H:i:s' in the booking's zone to something readable, or a dash when absent. * The zone is named alongside the time, because it can be the customer's zone (when * Bookly shows customers their own) and need not be the site's. */ private static function when($value, $timezone = '') { if (empty($value)) { return '—'; } try { $zone = $timezone !== '' ? new DateTimeZone($timezone) : wp_timezone(); $date = new DateTimeImmutable($value, $zone); } catch (Exception $e) { return '—'; } $text = wp_date('D, j M Y', $date->getTimestamp(), $zone) . ' · ' . $date->format('H:i'); return $timezone !== '' ? $text . ' (' . $zone->getName() . ')' : $text; } /** * The wallet pass cell: a status pill, then the pass id and a link to it. */ private static function pass_cell(array $row, $allowed) { $pass = $row['pass']; if ($pass) { $expired = !empty($pass['expired']); echo '' . esc_html($expired ? __('Expired', 'addtowallet-for-bookly') : __('Issued', 'addtowallet-for-bookly')) . ''; echo ''; echo ''; if (!empty($pass['card_id'])) { echo '' . esc_html($pass['card_id']) . ' '; } echo esc_html__('Open', 'addtowallet-for-bookly') . ' ↗'; if ($expired) { echo ''; /* translators: %s: when the pass was expired */ echo esc_html(sprintf(__('Expired %s', 'addtowallet-for-bookly'), $pass['expired'])); echo ''; } elseif (!empty($pass['expire_error']['message'])) { echo ''; /* translators: 1: when expiring was attempted, 2: the error */ echo esc_html(sprintf(__('Expiring failed %1$s: %2$s', 'addtowallet-for-bookly'), $pass['expire_error']['at'], $pass['expire_error']['message'])); echo ''; } if (empty($pass['expired']) && !empty($pass['update_error']['message'])) { echo ''; /* translators: 1: when updating was attempted, 2: the error */ echo esc_html(sprintf(__('Updating after a reschedule failed %1$s: %2$s', 'addtowallet-for-bookly'), $pass['update_error']['at'], $pass['update_error']['message'])); echo ''; } elseif (empty($pass['expired']) && !empty($pass['updated'])) { echo ''; /* translators: %s: when the pass was last updated */ echo esc_html(sprintf(__('Updated %s', 'addtowallet-for-bookly'), $pass['updated'])); echo ''; } return; } if (!empty($row['failure']['message'])) { echo '' . esc_html__('Failed', 'addtowallet-for-bookly') . ''; echo ''; /* translators: 1: when the pass was attempted, 2: the error from AddToWallet */ echo esc_html(sprintf(__('Not issued %1$s: %2$s', 'addtowallet-for-bookly'), $row['failure']['at'], $row['failure']['message'])); echo ''; return; } echo '' . esc_html__('Not issued', 'addtowallet-for-bookly') . ''; if (!$allowed) { echo ''; /* translators: %s: booking status, e.g. Cancelled */ echo esc_html(sprintf(__('Status is %s', 'addtowallet-for-bookly'), ATW_Bookly_Template::status_label($row['status']))); echo ''; } } public static function render() { $settings = ATW_Bookly_Settings::get(); if (!ATW_Bookly_Providers::available()) { echo '

' . esc_html__('Bookly is not active, so there are no bookings to show.', 'addtowallet-for-bookly') . '

'; return; } // phpcs:disable WordPress.Security.NonceVerification.Recommended -- read-only filter $search = isset($_GET['s']) ? sanitize_text_field(wp_unslash($_GET['s'])) : ''; $paged = isset($_GET['paged']) ? absint($_GET['paged']) : 1; // phpcs:enable WordPress.Security.NonceVerification.Recommended $data = self::page($paged, $search); $with_pass = 0; foreach ($data['rows'] as $row) { if (!empty($row['pass'])) { $with_pass++; } } $base = ATW_Bookly_Admin::url('passes'); ?>

#
1) : ?>
esc_url_raw(add_query_arg(['paged' => '%#%', 's' => $search !== '' ? rawurlencode($search) : false], $base)), 'format' => '', 'prev_text' => '«', 'next_text' => '»', 'total' => (int) $data['pages'], 'current' => (int) $data['page'], ])); ?>