| @@ -87,13 +87,15 @@ | ||
| 87 | 87 | |
| 88 | 88 | $locationType = Arr::get($postedData, 'location_type'); |
| 89 | 89 | |
| 90 | 90 | if ($calendarEvent->isPhoneRequired()) { |
| 91 | - $rules['location_description'] = 'required'; | |
| 91 | + $rules['location_description'] = ['required', $this->validPhoneNumberRule()]; | |
| 92 | 92 | $messages['location_description.required'] = __('Please provide attendee\'s phone number', 'fluent-booking'); |
| 93 | 93 | } else if ($calendarEvent->isAddressRequired()) { |
| 94 | 94 | $rules['location_description'] = 'required'; |
| 95 | 95 | $messages['location_description.required'] = __('Please provide attendee\'s address', 'fluent-booking'); |
| 96 | + } else if ($locationType === 'phone_guest') { | |
| 97 | + $rules['location_description'] = [$this->validPhoneNumberRule()]; | |
| 96 | 98 | } |
| 97 | 99 | |
| 98 | 100 | $additionalGuests = Arr::get($postedData, 'guests', []); |
| 99 | 101 | if (!empty($additionalGuests)) { |
| @@ -194,9 +196,17 @@ | ||
| 194 | 196 | $bookingData['source_url'] = sanitize_url($sourceUrl); |
| 195 | 197 | } |
| 196 | 198 | |
| 197 | 199 | if ($hostUserId = Arr::get($postedData, 'host_user_id', null)) { |
| 198 | - $bookingData['host_user_id'] = (int) $hostUserId; | |
| 200 | + $hostUserId = (int) $hostUserId; | |
| 201 | + | |
| 202 | + if (!in_array($hostUserId, array_map('intval', $calendarEvent->getHostIds()), true)) { | |
| 203 | + return $this->sendError([ | |
| 204 | + 'message' => __('The selected host is not a host of this event', 'fluent-booking') | |
| 205 | + ], 422); | |
| 206 | + } | |
| 207 | + | |
| 208 | + $bookingData['host_user_id'] = $hostUserId; | |
| 199 | 209 | } |
| 200 | 210 | |
| 201 | 211 | $hostIds = null; |
| 202 | 212 | if ($calendarEvent->isRoundRobin() && !$hostUserId) { |
| @@ -252,8 +262,20 @@ | ||
| 252 | 262 | 'message' => __('Booking has been created', 'fluent-booking'), |
| 253 | 263 | ]; |
| 254 | 264 | } |
| 255 | 265 | |
| 266 | + /** | |
| 267 | + * @return \Closure | |
| 268 | + */ | |
| 269 | + private function validPhoneNumberRule() | |
| 270 | + { | |
| 271 | + return function ($attribute, $value) { | |
| 272 | + if (!empty($value) && !Helper::isValidPhoneNumber($value)) { | |
| 273 | + return __('Please provide a valid phone number', 'fluent-booking'); | |
| 274 | + } | |
| 275 | + }; | |
| 276 | + } | |
| 277 | + | |
| 256 | 278 | public function getEvent(Request $request, $eventId) |
| 257 | 279 | { |
| 258 | 280 | $calendarEvent = CalendarSlot::find($eventId); |
| 259 | 281 | |
| @@ -291,9 +313,19 @@ | ||
| 291 | 313 | |
| 292 | 314 | $duration = $calendarEvent->getDuration($request->get('duration')); |
| 293 | 315 | |
| 294 | 316 | $hostId = $request->get('host_id', null); |
| 295 | - | |
| 317 | + | |
| 318 | + if ($hostId) { | |
| 319 | + $hostId = (int) $hostId; | |
| 320 | + | |
| 321 | + if (!in_array($hostId, array_map('intval', $calendarEvent->getHostIds()), true)) { | |
| 322 | + wp_send_json([ | |
| 323 | + 'message' => __('The selected host is not a host of this event', 'fluent-booking') | |
| 324 | + ], 422); | |
| 325 | + } | |
| 326 | + } | |
| 327 | + | |
| 296 | 328 | $timeSlotService = TimeSlotServiceHandler::initService($calendar, $calendarEvent); |
| 297 | 329 | |
| 298 | 330 | if (is_wp_error($timeSlotService)) { |
| 299 | 331 | return TimeSlotServiceHandler::sendError($timeSlotService, $calendarEvent, $timeZone); |