Ejemplo n.º 1
0
 /**
  * Constructor.
  *
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     // Handle widget options.
     $options = array_merge(array('use_empty' => true, 'empty_value' => null, 'exclude_last_slot' => false), $options);
     // Insert empty value if required.
     if ($options['use_empty']) {
         $this->values[null] = $options['empty_value'];
     }
     $ts_length = AB_BookingConfiguration::getTimeSlotLength();
     $time_start = AB_StaffScheduleItem::WORKING_START_TIME;
     $time_end = AB_StaffScheduleItem::WORKING_END_TIME;
     if ($options['exclude_last_slot']) {
         $time_end -= $ts_length;
     }
     // Run the loop.
     while ($time_start <= $time_end) {
         $this->values[AB_DateTimeUtils::buildTimeString($time_start)] = AB_DateTimeUtils::formatTime($time_start);
         $time_start += $ts_length;
     }
 }
Ejemplo n.º 2
0
 /**
  * @param string $field_name
  * @param bool $is_start
  * @return string
  */
 public function renderField($field_name = 'ab_settings_monday', $is_start = true)
 {
     $ts_length = AB_BookingConfiguration::getTimeSlotLength();
     $time_output = AB_StaffScheduleItem::WORKING_START_TIME;
     $time_end = AB_StaffScheduleItem::WORKING_END_TIME;
     $option_name = $field_name . ($is_start ? '_start' : '_end');
     $class_name = $is_start ? 'select_start' : 'select_end';
     $selected_value = get_option($option_name);
     $output = "<select class='form-control ab-auto-w {$class_name}' name={$option_name}>";
     if ($is_start) {
         $output .= "<option value=''>" . __('OFF', 'bookly') . "</option>";
         $time_end -= $ts_length;
     }
     while ($time_output <= $time_end) {
         $value = AB_DateTimeUtils::buildTimeString($time_output, false);
         $op_name = AB_DateTimeUtils::formatTime($time_output);
         $output .= "<option value='{$value}'" . selected($value, $selected_value, false) . ">{$op_name}</option>";
         $time_output += $ts_length;
     }
     $output .= '</select>';
     return $output;
 }
Ejemplo n.º 3
0
 /**
  * Get data needed for appointment form initialisation.
  */
 public function executeGetDataForAppointmentForm()
 {
     $result = array('staff' => array(), 'customers' => array(), 'custom_fields' => array(), 'time' => array(), 'time_interval' => get_option('ab_settings_time_slot_length') * 60);
     // Staff list.
     $staff_members = AB_Utils::isCurrentUserAdmin() ? AB_Staff::query()->sortBy('position')->find() : AB_Staff::query()->where('wp_user_id', get_current_user_id())->find();
     /** @var AB_Staff $staff_member */
     foreach ($staff_members as $staff_member) {
         $services = array();
         foreach ($staff_member->getStaffServices() as $staff_service) {
             $services[] = array('id' => $staff_service->service->get('id'), 'title' => sprintf('%s (%s)', $staff_service->service->get('title'), AB_Service::durationToString($staff_service->service->get('duration'))), 'duration' => $staff_service->service->get('duration'), 'capacity' => $staff_service->get('capacity'));
         }
         $result['staff'][] = array('id' => $staff_member->get('id'), 'full_name' => $staff_member->get('full_name'), 'services' => $services);
     }
     // Customers list.
     foreach (AB_Customer::query()->sortBy('name')->find() as $customer) {
         $name = $customer->get('name');
         if ($customer->get('email') != '' || $customer->get('phone') != '') {
             $name .= ' (' . trim($customer->get('email') . ', ' . $customer->get('phone'), ', ') . ')';
         }
         $result['customers'][] = array('id' => $customer->get('id'), 'name' => $name, 'custom_fields' => array(), 'number_of_persons' => 1);
     }
     // Time list.
     $ts_length = AB_BookingConfiguration::getTimeSlotLength();
     $time_start = AB_StaffScheduleItem::WORKING_START_TIME;
     $time_end = AB_StaffScheduleItem::WORKING_END_TIME;
     // Run the loop.
     while ($time_start <= $time_end) {
         $result['time'][] = array('value' => AB_DateTimeUtils::buildTimeString($time_start, false), 'title' => AB_DateTimeUtils::formatTime($time_start));
         $time_start += $ts_length;
     }
     wp_send_json($result);
 }
Ejemplo n.º 4
0
 /**
  * Fetches ids of the available days + the available time range
  * For the 1st step of the booking wizard
  *
  * @return array
  */
 public function fetchAvailableWorkDaysAndTime()
 {
     /** @var WP_Locale $wp_locale */
     global $wp_locale;
     $schedule_items = AB_StaffScheduleItem::query('ssi')->select('GROUP_CONCAT( DISTINCT ssi.day_index ORDER BY ssi.day_index ) AS available_day_ids,
             SUBSTRING_INDEX(MIN(ssi.start_time), \':\', 2) AS min_start_time,
             SUBSTRING_INDEX(MAX(ssi.end_time), \':\', 2)   AS max_end_time')->whereNot('ssi.start_time', null)->fetchArray();
     $data = current($schedule_items);
     $result = array('available_days' => array(), 'time_range' => array());
     if ($data['available_day_ids']) {
         $wp_week_start_day = (int) get_option('start_of_week');
         $available_day_ids = explode(',', $data['available_day_ids']);
         $week_days = array_values($wp_locale->weekday_abbrev);
         if ($wp_week_start_day >= $available_day_ids[0]) {
             $list_start = array_slice($week_days, $wp_week_start_day, 7, TRUE);
             $list_end = array_slice($week_days, 0, $wp_week_start_day, TRUE);
             $week_days = $list_start + $list_end;
         }
         foreach ($week_days as $day_id => $day_name) {
             if (in_array($day_id + 1, $available_day_ids)) {
                 $result['available_days'][$day_id + 1] = $day_name;
             }
         }
     }
     if ($data['min_start_time'] && $data['max_end_time']) {
         $start_timestamp = strtotime(sprintf("1970-01-01 %s", $data['min_start_time']));
         $end_timestamp = strtotime(sprintf("1970-01-01 %s", $data['max_end_time']));
         $now_timestamp = $start_timestamp;
         $now_timestamp_print = $start_timestamp;
         $end_timestamp_print = $end_timestamp;
         if ($this->client_timezone_offset !== false) {
             $now_timestamp_print -= ($this->client_timezone_offset + get_option('gmt_offset')) * 3600;
             $end_timestamp_print -= ($this->client_timezone_offset + get_option('gmt_offset')) * 3600;
         }
         while ($now_timestamp <= $end_timestamp) {
             $result['time_range'][AB_DateTimeUtils::buildTimeString($now_timestamp, false)] = AB_DateTimeUtils::formatTime($now_timestamp_print);
             // The next value will be rounded to integer number of hours, i.e. e.g. 8:00, 9:00, 10:00 and so on.
             $now_timestamp = $this->roundTime($now_timestamp + 30 * 60);
             $now_timestamp_print = $this->roundTime($now_timestamp_print + 30 * 60);
         }
         // The last value should always be the end time.
         $result['time_range'][AB_DateTimeUtils::buildTimeString($end_timestamp, false)] = AB_DateTimeUtils::formatTime($end_timestamp_print);
     }
     return $result;
 }