| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Hooks\Handlers; |
| 4 |
|
| 5 |
use FluentBooking\App\Services\TimeSlotService; |
| 6 |
|
| 7 |
class TimeSlotServiceHandler |
| 8 |
{ |
| 9 |
public static function initService($calendar, $calendarEvent) |
| 10 |
{ |
| 11 |
if ($calendarEvent->isProEvent()) { |
| 12 |
if (!defined('FLUENT_BOOKING_PRO_DIR_FILE')) { |
| 13 |
return new \WP_Error('pro_plugin_required', __('Pro plugin is required for this event.', 'fluent-booking')); |
| 14 |
} |
| 15 |
|
| 16 |
if ($calendarEvent->isRoundRobin()) { |
| 17 |
return new \FluentBookingPro\App\Services\RoundRobinTimeSlotService($calendar, $calendarEvent); |
| 18 |
} |
| 19 |
|
| 20 |
if ($calendarEvent->isCollective()) { |
| 21 |
return new \FluentBookingPro\App\Services\CollectiveTimeSlotService($calendar, $calendarEvent); |
| 22 |
} |
| 23 |
|
| 24 |
if ($calendarEvent->isOneOffEvent()) { |
| 25 |
return new \FluentBookingPro\App\Modules\SingleEvent\SingleTimeSlotService($calendar, $calendarEvent); |
| 26 |
} |
| 27 |
|
| 28 |
if ($calendarEvent->allowMultiBooking()) { |
| 29 |
return new \FluentBookingPro\App\Services\MultiTimeSlotService($calendar, $calendarEvent); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
return new TimeSlotService($calendar, $calendarEvent); |
| 34 |
} |
| 35 |
|
| 36 |
public static function sendError($error, $calendarEvent, $timeZone) |
| 37 |
{ |
| 38 |
wp_send_json([ |
| 39 |
'error' => true, |
| 40 |
'message' => $error->get_error_message(), |
| 41 |
'available_slots' => [], |
| 42 |
'timezone' => $timeZone, |
| 43 |
'max_lookup_date' => $calendarEvent->getMaxLookUpDate() |
| 44 |
], 200); |
| 45 |
} |
| 46 |
} |