Default lessons to a week view on the booking page and in wp-admin
CI / Tests (PHP 8.2) (pull_request) Successful in 1m15s
CI / Tests (PHP 8.1) (pull_request) Successful in 1m16s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 3m15s
CI / PHPStan (pull_request) Successful in 3m14s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m37s
CI / Build Plugin Zip (pull_request) Skipped
CI / Tests (PHP 8.2) (pull_request) Successful in 1m15s
CI / Tests (PHP 8.1) (pull_request) Successful in 1m16s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 3m15s
CI / PHPStan (pull_request) Successful in 3m14s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m37s
CI / Build Plugin Zip (pull_request) Skipped
The front-end booking calendar now opens in the Week view (anchored to the week of the earliest open slot) with List still available. The Scheduler and My Lessons admin pages gain a week calendar (usc_view/usc_week, bucketed via a new generic WeekCalendar::bucket()) and open in it by default; the original table remains as the List view since it carries the HST / e-transfer forms. Closes #76 Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
@@ -49,6 +49,36 @@ class WeekCalendar {
|
||||
return $days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bucket arbitrary items into the seven days of the week starting at
|
||||
* `$weekStart` (`Y-m-d`), using `$dayOf` to extract each item's `Y-m-d` day.
|
||||
* Every day is present, empty or not, in calendar order.
|
||||
*
|
||||
* @template T
|
||||
* @param list<T> $items
|
||||
* @param callable(T): string $dayOf
|
||||
* @return list<array{date: string, items: list<T>}>
|
||||
*/
|
||||
public static function bucket( string $weekStart, array $items, callable $dayOf ): array {
|
||||
$start = self::parseDay( $weekStart ) ?? new \DateTimeImmutable( 'today' );
|
||||
|
||||
$byDay = [];
|
||||
foreach ( $items as $item ) {
|
||||
$byDay[ $dayOf( $item ) ][] = $item;
|
||||
}
|
||||
|
||||
$days = [];
|
||||
for ( $i = 0; $i < 7; $i++ ) {
|
||||
$date = $start->modify( '+' . $i . ' days' )->format( 'Y-m-d' );
|
||||
$days[] = [
|
||||
'date' => $date,
|
||||
'items' => $byDay[ $date ] ?? [],
|
||||
];
|
||||
}
|
||||
|
||||
return $days;
|
||||
}
|
||||
|
||||
private static function parseDay( string $value ): ?\DateTimeImmutable {
|
||||
$day = \DateTimeImmutable::createFromFormat( '!Y-m-d', $value );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user