/** * Validates the data entered for the edit reservation. * * @access public * @param array $arrData * @return array * @since v1.0.0 */ public static function validateEditReservationData($arrData) { //array to store response $arrResponse = array(); if ($arrData['reservationType'] == 'alacarte') { //validating that user has not selected blocked date $returnResult = VendorLocationBlockedSchedules::isDateBlocked($arrData['vendorLocationID'], $arrData['reservationDate']); if ($returnResult) { $arrResponse['status'] = Config::get('constants.API_ERROR'); $arrResponse['msg'] = 'You cannot make any reservation on the selected date.'; return $arrResponse; } //reading details of the existing reservation from tables $arrCurrentReservation = ReservationDetails::getActiveReservationDetail($arrData['reservationID']); //checking the availability for the booking $arrTimeRangeLimits = VendorLocationBookingTimeRangeLimit::checkBookingTimeRangeLimits($arrData); $existingReservationCount = ReservationDetails::getReservationCount($arrData); if ($arrData['vendorLocationID'] == $arrCurrentReservation['vendorLocationID']) { //removing the existing number with max number $existingReservationCount = $existingReservationCount - $arrCurrentReservation['numOfPersons']; } //converting the reservation time $reservationTime = strtotime($arrData['reservationTime']); if (!empty($arrTimeRangeLimits)) { foreach ($arrTimeRangeLimits as $key => $value) { $maxCount = $value['max_covers_limit'] == 0 ? $value['max_tables_limit'] : $value['max_covers_limit']; if ($maxCount == $existingReservationCount) { $arrResponse['status'] = Config::get('constants.API_ERROR'); $arrResponse['msg'] = 'Sorry. Currently the place is full. Please try another day.'; return $arrResponse; } else { if ($maxCount > $existingReservationCount) { if ($maxCount - ($existingReservationCount + $arrData['partySize']) < 0) { $arrResponse['status'] = Config::get('constants.API_ERROR'); $arrResponse['msg'] = "Sorry. We have only " . $maxCount - $arrReservationCount . ' seats available.'; return $arrResponse; } } } } } $arrResponse['status'] = Config::get('constants.API_SUCCESS'); return $arrResponse; } else { if ($arrData['reservationType'] == 'experience') { //validating that user has not selected blocked date $returnResult = ProductVendorLocationBlockedSchedule::isDateBlocked($arrData['vendorLocationID'], $arrData['reservationDate']); if ($returnResult) { $arrResponse['status'] = Config::get('constants.API_ERROR'); $arrResponse['msg'] = 'You cannot make any reservation on the selected date.'; return $arrResponse; } //reading details of the existing reservation from tables $arrCurrentReservation = ReservationDetails::getActiveReservationDetail($arrData['reservationID']); //checking the availability for the booking $arrTimeRangeLimits = ProductVendorLocationBookingTimeRangeLimit::checkBookingTimeRangeLimits($arrData); $existingReservationCount = ReservationDetails::getReservationCount($arrData); if ($arrData['vendorLocationID'] == $arrCurrentReservation['vendorLocationID']) { //removing the existing number with max number $existingReservationCount = $existingReservationCount - $arrCurrentReservation['numOfPersons']; } //converting the reservation time $reservationTime = strtotime($arrData['reservationTime']); if (!empty($arrTimeRangeLimits)) { foreach ($arrTimeRangeLimits as $key => $value) { $maxCount = $value['max_covers_limit'] == 0 ? $value['max_tables_limit'] : $value['max_covers_limit']; $startTime = strtotime($value['start_time']); $endTime = strtotime($value['end_time']); if ($startTime <= $reservationTime && $endTime >= $reservationTime) { if ($maxCount == $existingReservationCount) { $arrResponse['status'] = Config::get('constants.API_ERROR'); $arrResponse['msg'] = 'Sorry. Currently the place is full. Please try another day.'; return $arrResponse; } else { if ($maxCount > $existingReservationCount) { if ($maxCount - ($existingReservationCount + $arrData['partySize']) < 0) { $arrResponse['status'] = Config::get('constants.API_ERROR'); $arrResponse['msg'] = "Sorry. We have only " . abs($maxCount - $existingReservationCount) . ' seats available.'; return $arrResponse; } } } } } } $arrResponse['status'] = Config::get('constants.API_SUCCESS'); return $arrResponse; } } return -1; }