Refactor booking list data to use typed model instead of raw array round-trip - #33
Open
datengraben wants to merge 3 commits into
Open
Refactor booking list data to use typed model instead of raw array round-trip#33datengraben wants to merge 3 commits into
datengraben wants to merge 3 commits into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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