← All changes
|
app/Services/Integrations/FluentBooking/BookingAvailabilityHelper.php
+12
-25
2.3.2
→
2.4.5
View file →
| @@ -7,13 +7,10 @@ | ||
| 7 | 7 | |
| 8 | 8 | class BookingAvailabilityHelper |
| 9 | 9 | { |
| 10 | 10 | /** |
| 11 | - * Validates and returns an IANA timezone string, falling back to $fallback then to the WordPress site timezone. | |
| 11 | + * Return a valid IANA timezone, falling back to $fallback, then the site timezone. | |
| 12 | 12 | * |
| 13 | - * Delegates validation to DateTimeHelper::getValidatedTimeZone() which uses a static per-request cache and | |
| 14 | - * applies the fluent_booking/fallback_timezone filter, avoiding repeated scans of DateTimeZone::listIdentifiers(). | |
| 15 | - * | |
| 16 | 13 | * @param string $timezone |
| 17 | 14 | * @param string $fallback |
| 18 | 15 | * @return string |
| 19 | 16 | */ |
| @@ -39,13 +36,10 @@ | ||
| 39 | 36 | return \FluentBooking\App\Services\DateTimeHelper::getTimeZone(); |
| 40 | 37 | } |
| 41 | 38 | |
| 42 | 39 | /** |
| 43 | - * Builds the start/end date window for an availability query. | |
| 40 | + * Start/end window for an availability query: a named range, specific dates, or a calendar month. | |
| 44 | 41 | * |
| 45 | - * Handles named ranges (next_3_days, this_week, next_week, next_14_days), specific date lists, | |
| 46 | - * and calendar-month requests. | |
| 47 | - * | |
| 48 | 42 | * @param string $range |
| 49 | 43 | * @param string $timezone |
| 50 | 44 | * @param array $selectedDates |
| 51 | 45 | * @param string $calendarMonth |
| @@ -110,13 +104,10 @@ | ||
| 110 | 104 | ]; |
| 111 | 105 | } |
| 112 | 106 | |
| 113 | 107 | /** |
| 114 | - * Initialises the FluentBooking time-slot service, fetches available spots, and returns formatted day/slot arrays. | |
| 108 | + * Fetch available spots from FluentBooking and format them as day/slot arrays. | |
| 115 | 109 | * |
| 116 | - * Applies the fluent_booking/available_slots_for_view filter before formatting. | |
| 117 | - * Throws on service init failure so callers can handle it at the appropriate level. | |
| 118 | - * | |
| 119 | 110 | * @param object $event |
| 120 | 111 | * @param array $rangeData |
| 121 | 112 | * @param string $timezone |
| 122 | 113 | * @param Ticket|null $ticket |
| @@ -150,12 +141,10 @@ | ||
| 150 | 141 | return $this->formatDays($availableSpots, $rangeData, $timezone, $event, $ticket, $duration); |
| 151 | 142 | } |
| 152 | 143 | |
| 153 | 144 | /** |
| 154 | - * Validates user-submitted slot start times against live FluentBooking availability. | |
| 145 | + * Keep only the submitted slots that are still bookable. | |
| 155 | 146 | * |
| 156 | - * Returns only slots that are still bookable. | |
| 157 | - * | |
| 158 | 147 | * @param array $selectedSlots |
| 159 | 148 | * @param object $event |
| 160 | 149 | * @param Ticket $ticket |
| 161 | 150 | * @param int|null $duration |
| @@ -237,9 +226,9 @@ | ||
| 237 | 226 | return $slots; |
| 238 | 227 | } |
| 239 | 228 | |
| 240 | 229 | /** |
| 241 | - * Appends the link token to the booking_url of each slot so individual slot links are traceable back to this send. | |
| 230 | + * Tag each slot's booking_url with the link token so bookings trace back to this send. | |
| 242 | 231 | * |
| 243 | 232 | * @param array $selectedSlots |
| 244 | 233 | * @param string $linkToken |
| 245 | 234 | * @return array |
| @@ -259,9 +248,9 @@ | ||
| 259 | 248 | }, $selectedSlots); |
| 260 | 249 | } |
| 261 | 250 | |
| 262 | 251 | /** |
| 263 | - * Builds the HTML block of grouped time-slot links for insertion into an agent reply. | |
| 252 | + * HTML block of time-slot links, grouped by day, for an agent reply. | |
| 264 | 253 | * |
| 265 | 254 | * @param array $selectedSlots |
| 266 | 255 | * @param object $event |
| 267 | 256 | * @param string $timezone |
| @@ -352,9 +341,9 @@ | ||
| 352 | 341 | return $html; |
| 353 | 342 | } |
| 354 | 343 | |
| 355 | 344 | /** |
| 356 | - * Builds the plain-text equivalent of the booking suggestion for clipboard copy. | |
| 345 | + * Plain-text version of the booking suggestion, for clipboard copy. | |
| 357 | 346 | * |
| 358 | 347 | * @param string $message |
| 359 | 348 | * @param array $selectedSlots |
| 360 | 349 | * @param string $bookingUrl |
| @@ -389,12 +378,10 @@ | ||
| 389 | 378 | return implode("\n\n", $parts); |
| 390 | 379 | } |
| 391 | 380 | |
| 392 | 381 | /** |
| 393 | - * Maps raw FluentBooking spot data into the day-grouped slot structure returned to the frontend. | |
| 382 | + * Group raw FluentBooking spots by day, limited to the requested range. | |
| 394 | 383 | * |
| 395 | - * Filters results to the requested date range. | |
| 396 | - * | |
| 397 | 384 | * @param array $availableSpots |
| 398 | 385 | * @param array $rangeData |
| 399 | 386 | * @param string $timezone |
| 400 | 387 | * @param object $event |
| @@ -472,9 +459,9 @@ | ||
| 472 | 459 | return array_slice(array_values($days), 0, $maxDays); |
| 473 | 460 | } |
| 474 | 461 | |
| 475 | 462 | /** |
| 476 | - * Validates, deduplicates, and sorts an array of Y-m-d date strings, capping at 7 entries. | |
| 463 | + * Valid, unique, sorted Y-m-d dates, at most 7. | |
| 477 | 464 | * |
| 478 | 465 | * @param array $selectedDates |
| 479 | 466 | * @param \DateTimeZone $timezoneObject |
| 480 | 467 | * @return array |
| @@ -509,9 +496,9 @@ | ||
| 509 | 496 | return $dates; |
| 510 | 497 | } |
| 511 | 498 | |
| 512 | 499 | /** |
| 513 | - * Validates a Y-m month string against the given timezone, returning an empty string if invalid. | |
| 500 | + * Return the Y-m month string, or '' if invalid. | |
| 514 | 501 | * |
| 515 | 502 | * @param string $calendarMonth |
| 516 | 503 | * @param \DateTimeZone $timezoneObject |
| 517 | 504 | * @return string |
| @@ -533,9 +520,9 @@ | ||
| 533 | 520 | return $calendarMonth; |
| 534 | 521 | } |
| 535 | 522 | |
| 536 | 523 | /** |
| 537 | - * Builds a booking URL pre-selecting a specific date, time, duration, and timezone. | |
| 524 | + * Booking URL with the date, time, duration and timezone preselected. | |
| 538 | 525 | * |
| 539 | 526 | * @param object $event |
| 540 | 527 | * @param Ticket|null $ticket |
| 541 | 528 | * @param \DateTime $start |
| @@ -556,9 +543,9 @@ | ||
| 556 | 543 | return esc_url_raw(add_query_arg(array_filter($queryArgs), FluentBookingService::getEventUrl($event, $ticket))); |
| 557 | 544 | } |
| 558 | 545 | |
| 559 | 546 | /** |
| 560 | - * Returns a localised "%d min" string, or an empty string for zero/negative durations. | |
| 547 | + * Localised "%d min", or '' for non-positive durations. | |
| 561 | 548 | * |
| 562 | 549 | * @param int $duration |
| 563 | 550 | * @return string |
| 564 | 551 | */ |