Skip to content

Refactor booking list data to use typed model instead of raw array round-trip - #33

Open
datengraben wants to merge 3 commits into
masterfrom
claude/booking-data-typing-m29o9l
Open

Refactor booking list data to use typed model instead of raw array round-trip#33
datengraben wants to merge 3 commits into
masterfrom
claude/booking-data-typing-m29o9l

Conversation

@datengraben

Copy link
Copy Markdown
Owner

getBookingListiCal() previously re-fetched the Booking model by ID from the
plain assoc array produced by getBookingListData(), even though that model
was already available when the array was built. Introduce
CommonsBooking\Model\BookingListEntry to pair each row's rendered array data
with its originating Booking model, so internal consumers can use the typed
model directly. The plain array form (still required by the
commonsbooking_booking_filter hook and consumers) is now only produced at
the webservice boundary, in getTemplateData()'s AJAX JSON response.

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_013tGSVYGXS2qFtR3rnUC9tz

claude added 3 commits July 11, 2026 15:26
…und-trip

getBookingListiCal() previously re-fetched the Booking model by ID from the
plain assoc array produced by getBookingListData(), even though that model
was already available when the array was built. Introduce
CommonsBooking\Model\BookingListEntry to pair each row's rendered array data
with its originating Booking model, so internal consumers can use the typed
model directly. The plain array form (still required by the
commonsbooking_booking_filter hook and consumers) is now only produced at
the webservice boundary, in getTemplateData()'s AJAX JSON response.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013tGSVYGXS2qFtR3rnUC9tz
… webservice boundary

Row data now stays a typed BookingListEntry object all the way through, including
across the commonsbooking_booking_filter hook, instead of being unwrapped back to
a plain array beforehand. BookingListEntry implements ArrayAccess/IteratorAggregate/
Countable so existing filter callbacks written against the old plain array
($rowData['postID'], foreach, count, returning null to drop a row) keep working
unchanged; callbacks returning a plain array are still accepted and re-wrapped.

getTemplateData() no longer manually converts entries to arrays before JSON
encoding - BookingListEntry implements JsonSerializable, so wp_json_encode()
reduces each entry to its row array only at that point, which is the actual
webservice boundary.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013tGSVYGXS2qFtR3rnUC9tz
Turn the previously untyped $rowData array inside BookingListEntry into real
typed properties (postID: int, item: string, content: array, ...) for the
fixed set of fields the booking list view always produces. Fields outside
that schema -- which commonsbooking_booking_filter callbacks are free to add
-- still land in an untyped overflow array, since the hook's contract allows
arbitrary extension and a fixed set of properties can't accept that.

toArray()/jsonSerialize() reassemble the known typed fields plus the overflow
bag into a plain array, keeping 'bookingCode' entirely absent (not present as
null) when a booking has no code, to match the original array's exact shape
and avoid false positives in the WP_DEBUG absent-key diff log.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013tGSVYGXS2qFtR3rnUC9tz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants