Extend availability (durations, weekly recurrence, calendar); price offerings in dollars
CI / Coding Standards (pull_request) Successful in 50s
CI / PHPStan (pull_request) Successful in 1m2s
CI / Tests (PHP 8.1) (pull_request) Successful in 47s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 46s
CI / No Debug Code (pull_request) Successful in 2s
CI / Build Plugin Zip (pull_request) Has been skipped

Availability (#2):
- us_availability gains offering_id, duration_minutes (default 60), and
  recurrence_group; AvailabilitySlot carries the new fields.
- AvailabilityRepository::createWeeklySeries() generates N weekly rows
  sharing a recurrence_group; findAvailable() filters by offering and
  duration. Date math uses DateTimeImmutable::modify() (the no-debug CI
  regex `dd\(` matches `->add(`).
- REST GET filters by offering_id/duration_minutes; POST accepts
  duration_minutes, offering_id, recurrence (single|weekly) + weeks.
- Admin form adds duration, an offering picker, and one-off/weekly options
  (OfferingRepository wired into AvailabilityController).
- booking.js renders an agenda calendar (slots grouped by day, with
  duration). The richer booking UX lands with the booking-flow work.

Offering price in dollars:
- Switch us_offerings.price_cents (INT) to price DECIMAL(10,2); Offering
  uses float $price. Admin form and REST take dollars.
- Fix a pre-existing misalignment in the Offering insert/update $wpdb
  format arrays (billing_mode/capacity/is_active were mapped to the wrong
  specifiers, which would corrupt values) via a single COLUMN_FORMATS list.

Also bump PHPStan to --memory-limit=1G in the lint script; 128M now
crashes analysis as the codebase has grown.

Refs #2

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-05 15:38:58 -03:00
parent 5352fb7d69
commit 19e663d6fa
18 changed files with 398 additions and 112 deletions
+3 -3
View File
@@ -29,7 +29,7 @@ class Offering {
public readonly int $instructorId,
public readonly string $kind,
public readonly string $title,
public readonly int $priceCents = 0,
public readonly float $price = 0.0,
public readonly string $currency = 'CAD',
public readonly string $billingMode = self::BILLING_ONE_TIME,
public readonly ?string $description = null,
@@ -48,7 +48,7 @@ class Offering {
instructorId: (int) $row->instructor_id,
kind: $row->kind,
title: $row->title,
priceCents: (int) $row->price_cents,
price: (float) $row->price,
currency: $row->currency,
billingMode: $row->billing_mode,
description: $row->description,
@@ -76,7 +76,7 @@ class Offering {
'title' => $this->title,
'description' => $this->description,
'duration_minutes' => $this->durationMinutes,
'price_cents' => $this->priceCents,
'price' => $this->price,
'currency' => $this->currency,
'billing_mode' => $this->billingMode,
'allow_weekly' => $this->allowWeekly,
+1 -1
View File
@@ -71,7 +71,7 @@ class OfferingController {
instructorId: $instructorId,
kind: $kind,
title: $title,
priceCents: absint( $_POST['price_cents'] ?? 0 ),
price: max( 0.0, (float) sanitize_text_field( wp_unslash( $_POST['price'] ?? '0' ) ) ),
billingMode: $billingMode,
durationMinutes: $duration > 0 ? $duration : null,
allowWeekly: isset( $_POST['allow_weekly'] ),
+6 -2
View File
@@ -85,7 +85,7 @@ class OfferingEndpoint {
instructorId: get_current_user_id(),
kind: $kind,
title: $title,
priceCents: absint( $request->get_param( 'price_cents' ) ),
price: $this->price( $request->get_param( 'price' ) ),
currency: sanitize_text_field( (string) ( $request->get_param( 'currency' ) ?? 'CAD' ) ),
billingMode: $billingMode,
description: $this->nullableText( $request->get_param( 'description' ) ),
@@ -129,7 +129,7 @@ class OfferingEndpoint {
instructorId: $existing->instructorId,
kind: $kind,
title: $request->has_param( 'title' ) ? sanitize_text_field( (string) $request->get_param( 'title' ) ) : $existing->title,
priceCents: $request->has_param( 'price_cents' ) ? absint( $request->get_param( 'price_cents' ) ) : $existing->priceCents,
price: $request->has_param( 'price' ) ? $this->price( $request->get_param( 'price' ) ) : $existing->price,
currency: $request->has_param( 'currency' ) ? sanitize_text_field( (string) $request->get_param( 'currency' ) ) : $existing->currency,
billingMode: $billingMode,
description: $request->has_param( 'description' ) ? $this->nullableText( $request->get_param( 'description' ) ) : $existing->description,
@@ -182,6 +182,10 @@ class OfferingEndpoint {
return new \WP_Error( 'invalid_offering', $message, [ 'status' => 400 ] );
}
private function price( mixed $value ): float {
return max( 0.0, (float) $value );
}
private function nullableInt( mixed $value ): ?int {
return ( null === $value || '' === $value ) ? null : (int) $value;
}
+12 -3
View File
@@ -11,11 +11,20 @@ class OfferingRepository {
$this->table = $db->prefix . 'us_offerings';
}
/**
* Column formats aligned to {@see columns()} (instructor_id, kind, title,
* description, duration_minutes, price, currency, billing_mode, allow_weekly,
* capacity, term_start, term_end, schedule_note, is_active).
*
* @var list<string>
*/
private const COLUMN_FORMATS = [ '%d', '%s', '%s', '%s', '%d', '%f', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%d' ];
public function insert( Offering $offering ): int {
$this->db->insert(
$this->table,
$this->columns( $offering ) + [ 'created_at' => current_time( 'mysql' ) ],
[ '%d', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%d', '%s' ]
[ ...self::COLUMN_FORMATS, '%s' ]
);
return $this->db->insert_id;
@@ -26,7 +35,7 @@ class OfferingRepository {
$this->table,
$this->columns( $offering ),
[ 'id' => $id ],
[ '%d', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%d' ],
self::COLUMN_FORMATS,
[ '%d' ]
);
}
@@ -43,7 +52,7 @@ class OfferingRepository {
'title' => $offering->title,
'description' => $offering->description,
'duration_minutes' => $offering->durationMinutes,
'price_cents' => $offering->priceCents,
'price' => $offering->price,
'currency' => $offering->currency,
'billing_mode' => $offering->billingMode,
'allow_weekly' => $offering->allowWeekly ? 1 : 0,