Add booking statistics tracking and admin dashboard - #22
Open
datengraben wants to merge 1 commit into
Open
Conversation
Introduces a custom `cb_booking_stats` DB table that pre-aggregates confirmed booking counts and total booked days per day per entity (global / per-item / per-location). This replaces on-the-fly full post-meta scans for any aggregate stats query. - Repository\BookingStats – table init (dbDelta), upsert/decrement rows, recomputeAll(), getAggregated() with date-range + entity filter - Service\BookingStats – period helpers (day/week/month/year, current vs previous), diff % calculation, transition_post_status hook handler - View\Stats – admin page render + "Recompute Statistics" POST handler - templates/stats-index.php – four stat cards (Today/Week/Month/Year) with item/location filter dropdowns and maintenance recompute button - Wordpress\Shortcode\BookingStats – [cb_booking_stats] shortcode with period, compare, item, location, show attributes - Plugin.php – wires activation init, lifecycle hook, admin submenu, admin_post handler, and shortcode registration https://claude.ai/code/session_01893WfsffpRupUqYoStyKaG
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.
Summary
This PR introduces a comprehensive booking statistics system for Commons Booking, including a pre-aggregated stats table, service layer for querying statistics, an admin dashboard page, and a shortcode for displaying stats on the frontend.
Key Changes
New Database Table & Repository
BookingStatsRepository (src/Repository/BookingStats.php): Manages thecb_booking_statstable with pre-aggregated booking counts and durations per day per entity (global/item/location)recordBooking()andremoveBooking()to keep stats in sync when bookings are confirmed/cancelledgetAggregated()for efficient range queriesrecomputeAll()for rebuilding stats from scratchINSERT ... ON DUPLICATE KEY UPDATEfor safe concurrent updatesService Layer
BookingStatsService (src/Service/BookingStats.php): High-level API for statistics queriesgetDayStats(),getWeekStats(),getMonthStats(),getYearStats()getPeriodStats()method for flexible period selectiontransition_post_statusto automatically sync stats when booking status changesAdmin Dashboard
StatsView (src/View/Stats.php): Admin page controllerStats Template (
templates/stats-index.php): Admin UIFrontend Shortcode
BookingStatsShortcode (src/Wordpress/Shortcode/BookingStats.php):[cb_booking_stats]period(day/week/month/year),compare(true/false),item/location(ID or "all"),show(count/days/both)Plugin Integration
Plugin.php:BookingStatsService::handleStatusTransition()totransition_post_statusImplementation Details
ON DUPLICATE KEY UPDATEto handle race conditionsdbDelta()for safe schema initialization on existing installshttps://claude.ai/code/session_01893WfsffpRupUqYoStyKaG