public function executeRenderNextTime() { $response = null; $userData = new AB_UserBookingData($this->getParameter('form_id')); if ($userData->load()) { $availableTime = new AB_AvailableTime($userData); $availableTime->setLastFetchedDay($this->getParameter('start_date')); $availableTime->load(); if (count($availableTime->getTime())) { // check, if there are available time $html = ''; foreach ($availableTime->getTime() as $client_timestamp => $slot) { if ($slot['is_day']) { $button = sprintf('<button class="ab-available-day" value="%s">%s</button>', esc_attr(date($availableTime->isWholeDayService() ? 'Y-m' : 'Y-m-d', -$client_timestamp)), date_i18n($availableTime->isWholeDayService() ? 'M' : 'D, M d', -$client_timestamp)); } else { $button = sprintf('<button %s data-date="%s" data-staff_id="%s" class="ab-available-hour ladda-button %s" value="%s" data-style="zoom-in" data-spinner-color="#333"><span class="ladda-label"><i class="ab-hour-icon"><span></span></i>%s</span></button>', disabled($slot['booked'], true, false), esc_attr(date($availableTime->isWholeDayService() ? 'Y-m' : 'Y-m-d', $client_timestamp)), $slot['staff_id'], $slot['booked'] ? 'booked' : '', esc_attr(date($availableTime->isWholeDayService() ? 'Y-m' : 'Y-m-d H:i:s', $slot['timestamp'])), date_i18n(!$availableTime->isWholeDayService() ? get_option('time_format') : 'D, M d', $client_timestamp)); } $html .= $button; } // Set response. $response = array('success' => true, 'html' => $html, 'has_slots' => true, 'has_more_slots' => $availableTime->hasMoreSlots()); } else { $response = array('success' => true, 'has_slots' => false); } } else { $response = array('success' => false, 'error' => __('Session error.', 'bookly')); } // Output JSON response. wp_send_json($response); }
public function executeRenderNextTime() { $form_id = $this->getParameter('form_id'); $response = null; if ($form_id) { $userData = new AB_UserBookingData($form_id); $userData->load(); if ($userData->hasData()) { $availableTime = new AB_AvailableTime($userData); $availableTime->setStartDate($this->getParameter('start_date')); $availableTime->load(); if (count($availableTime->getTime())) { // check, if there are available time $html = ''; foreach ($availableTime->getTime() as $date => $hours) { foreach ($hours as $object) { $button = sprintf('<button data-date="%s" data-staff_id="%s" class="%s" value="%s">', $object->is_day ? '' : $object->clean_date, $object->staff_id, $object->is_day ? 'ab-available-day' : 'ab-available-hour ladda-button zoom-in', $object->value); if (!$object->is_day) { $button .= '<span class="ab_label"><i class="ab-hour-icon"><span></span></i>' . $object->label . '</span><span class="spinner"></span>'; } else { $button .= $object->label . '</button>'; } $html .= $button; } } // Set response. $response = array('status' => 'success', 'html' => $html); } else { // Set response. $response = array('status' => 'error', 'html' => sprintf('<h3>%s</h3>', __('The selected time is not available anymore. Please, choose another time slot.', 'ab'))); } } } // Output JSON response. if ($response === null) { $response = array('status' => 'no-data'); } header('Content-Type: application/json'); echo json_encode($response); exit(0); }