AddAppointmentController.php
1 month ago
AddBookingController.php
2 weeks ago
ApproveBookingRemotelyController.php
1 month ago
CancelBookingController.php
1 month ago
CancelBookingRemotelyController.php
1 month ago
DeleteAppointmentController.php
1 month ago
DeleteBookingController.php
1 month ago
DeleteBookingRemotelyController.php
1 month ago
GetAppointmentBookingsController.php
1 month ago
GetAppointmentController.php
1 month ago
GetAppointmentsController.php
1 month ago
GetIcsController.php
1 month ago
GetTimeSlotsController.php
1 month ago
ReassignBookingController.php
1 month ago
RejectBookingRemotelyController.php
1 month ago
SuccessfulBookingController.php
1 month ago
UpdateAppointmentController.php
1 month ago
UpdateAppointmentNoteController.php
1 month ago
UpdateAppointmentStatusController.php
1 month ago
UpdateAppointmentTimeController.php
1 month ago
UpdateBookingStatusController.php
1 month ago
GetTimeSlotsController.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Controller\Booking\Appointment; |
| 4 | |
| 5 | use AmeliaBooking\Application\Commands\Booking\Appointment\GetTimeSlotsCommand; |
| 6 | use AmeliaBooking\Application\Controller\Controller; |
| 7 | use AmeliaVendor\Psr\Http\Message\ServerRequestInterface as Request; |
| 8 | |
| 9 | /** |
| 10 | * Class GetTimeSlotsController |
| 11 | * |
| 12 | * @package AmeliaBooking\Application\Controller\Booking\Appointment |
| 13 | */ |
| 14 | class GetTimeSlotsController extends Controller |
| 15 | { |
| 16 | /** |
| 17 | * Fields for calendar service that can be received from front-end |
| 18 | * |
| 19 | * @var array |
| 20 | */ |
| 21 | protected $allowedFields = [ |
| 22 | 'serviceId', |
| 23 | 'serviceDuration', |
| 24 | 'weekDays', |
| 25 | 'startDateTime', |
| 26 | 'providerIds', |
| 27 | 'extras', |
| 28 | 'excludeAppointmentId', |
| 29 | 'persons', |
| 30 | 'group', |
| 31 | 'page', |
| 32 | 'monthsLoad', |
| 33 | 'queryTimeZone', |
| 34 | 'timeZone', |
| 35 | 'allowAdminBookAtAnyTime', |
| 36 | 'allowBookingIfPending', |
| 37 | 'allowBookingIfNotMin', |
| 38 | 'timeSlotLength', |
| 39 | 'serviceDurationAsSlot', |
| 40 | 'bufferTimeInSlot', |
| 41 | 'structured', |
| 42 | ]; |
| 43 | |
| 44 | /** |
| 45 | * Instantiates the Get Time Slots command to hand it over to the Command Handler |
| 46 | * |
| 47 | * @param Request $request |
| 48 | * @param $args |
| 49 | * |
| 50 | * @return mixed |
| 51 | * @throws \RuntimeException |
| 52 | */ |
| 53 | protected function instantiateCommand(Request $request, $args) |
| 54 | { |
| 55 | $command = new GetTimeSlotsCommand($args); |
| 56 | |
| 57 | $params = (array)$request->getQueryParams(); |
| 58 | |
| 59 | if (!empty($params['extras'])) { |
| 60 | if (($arrayExtras = json_decode($params['extras'], true)) !== null) { |
| 61 | $params['extras'] = $arrayExtras; |
| 62 | } else { |
| 63 | $arrayExtras = []; |
| 64 | |
| 65 | foreach (explode(',', $params['extras']) as $item) { |
| 66 | $extrasData = explode('-', $item); |
| 67 | |
| 68 | $arrayExtras[] = ['id' => $extrasData[0], 'quantity' => $extrasData[1]]; |
| 69 | } |
| 70 | |
| 71 | $params['extras'] = $arrayExtras; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | $this->setArrayParams($params); |
| 76 | |
| 77 | $command->setField('serviceId', (int)self::getParam($request, 'serviceId', 0)); |
| 78 | $command->setField('locationId', (int)self::getParam($request, 'locationId', 0)); |
| 79 | $command->setField('locationIds', !empty($params['locationIds']) ? $params['locationIds'] : []); |
| 80 | $command->setField('serviceDuration', (int)self::getParam($request, 'serviceDuration', 0)); |
| 81 | $command->setField('weekDays', (array)self::getParam($request, 'weekDays', [1, 2, 3, 4, 5, 6, 7])); |
| 82 | $command->setField('startDateTime', (string)self::getParam($request, 'startDateTime', '')); |
| 83 | $command->setField('endDateTime', (string)self::getParam($request, 'endDateTime', '')); |
| 84 | $command->setField('providerIds', !empty($params['providerIds']) ? $params['providerIds'] : []); |
| 85 | $command->setField('extras', !empty($params['extras']) ? $params['extras'] : []); |
| 86 | $command->setField('excludeAppointmentId', (int)self::getParam($request, 'excludeAppointmentId', [])); |
| 87 | $command->setField('persons', (int)self::getParam($request, 'persons', 1)); |
| 88 | $command->setField('group', (int)self::getParam($request, 'group', 0)); |
| 89 | $command->setField('page', (string)self::getParam($request, 'page', '')); |
| 90 | $command->setField('monthsLoad', (int)self::getParam($request, 'monthsLoad', 0)); |
| 91 | $command->setField('queryTimeZone', (string)self::getParam($request, 'queryTimeZone', '')); |
| 92 | $command->setField('timeZone', (string)self::getParam($request, 'timeZone', '')); |
| 93 | |
| 94 | $command->setField('allowAdminBookAtAnyTime', self::getParam($request, 'allowAdminBookAtAnyTime')); |
| 95 | $command->setField('allowBookingIfPending', self::getParam($request, 'allowBookingIfPending')); |
| 96 | $command->setField('allowBookingIfNotMin', self::getParam($request, 'allowBookingIfNotMin')); |
| 97 | $command->setField('timeSlotLength', self::getParam($request, 'timeSlotLength')); |
| 98 | $command->setField('serviceDurationAsSlot', self::getParam($request, 'serviceDurationAsSlot')); |
| 99 | $command->setField('bufferTimeInSlot', self::getParam($request, 'bufferTimeInSlot')); |
| 100 | $command->setField('structured', self::getParam($request, 'structured')); |
| 101 | |
| 102 | $requestBody = $request->getParsedBody(); |
| 103 | $this->setCommandFields($command, $requestBody); |
| 104 | |
| 105 | return $command; |
| 106 | } |
| 107 | } |
| 108 |