/** * Constructor. * * @param array $options */ public function __construct(array $options = array()) { // Handle widget options. $options = array_merge(array('use_empty' => true, 'empty_value' => null), $options); // Insert empty value if required. if ($options['use_empty']) { $this->values[null] = $options['empty_value']; } $tf = get_option('time_format'); $ts_length = get_option('ab_settings_time_slot_length'); $time_start = new AB_DateTime(AB_StaffScheduleItem::WORKING_START_TIME, new DateTimeZone('UTC')); $time_end = new AB_DateTime(AB_StaffScheduleItem::WORKING_END_TIME, new DateTimeZone('UTC')); // Run the loop. while ($time_start->format('U') <= $time_end->format('U')) { $this->values[$time_start->format('H:i:s')] = $time_start->format($tf); $time_start->modify('+' . $ts_length . ' min'); } $this->values[$time_end->format('H:i:s')] = $time_end->format($tf); }
/** * Get data needed for appointment form initialisation. */ public function executeGetDataForAppointmentForm() { $wpdb = $this->getWpdb(); $result = array('staff' => array(), 'customers' => array(), 'time' => array(), 'time_interval' => get_option('ab_settings_time_slot_length') * 60); // Staff list. if (is_super_admin()) { $staff = $wpdb->get_results('SELECT `id`, `full_name` FROM `ab_staff`', ARRAY_A); } else { $staff = $wpdb->get_results($wpdb->prepare('SELECT `id`, `full_name` FROM `ab_staff` WHERE `wp_user_id` = %d', array(get_current_user_id())), ARRAY_A); } foreach ($staff as $st) { $services = $wpdb->get_results($wpdb->prepare('SELECT `service`.`id`, `service`.`title`, `service`.`duration` FROM `ab_service` `service` LEFT JOIN `ab_staff_service` `ss` ON `ss`.`service_id` = `service`.`id` LEFT JOIN `ab_staff` `staff` ON `ss`.`staff_id` = `staff`.`id` WHERE `staff`.`id` = %d', $st['id']), ARRAY_A); array_walk($services, create_function('&$a', '$a[\'title\'] = sprintf(\'%s (%s)\', $a[\'title\'], AB_Service::durationToString($a[\'duration\']));')); $result['staff'][] = array('id' => $st['id'], 'full_name' => $st['full_name'], 'services' => $services); } // Customers list. $customers = $this->getWpdb()->get_results('SELECT * FROM `ab_customer` WHERE name <> "" OR phone <> "" OR email <> "" ORDER BY name', ARRAY_A); $customer = new AB_Customer(); foreach ($customers as $customer_data) { $customer->setData($customer_data); $name = $customer->get('name'); if ($customer->get('email') && $customer->get('phone')) { $name .= ' (' . $customer->get('email') . ', ' . $customer->get('phone') . ')'; } elseif ($customer->get('email')) { $name .= ' (' . $customer->get('email') . ')'; } elseif ($customer->get('phone')) { $name .= ' (' . $customer->get('phone') . ')'; } $result['customers'][] = array('id' => $customer->get('id'), 'name' => $name); } // Time list. $tf = get_option('time_format'); $ts_length = get_option('ab_settings_time_slot_length'); $time_start = new AB_DateTime(AB_StaffScheduleItem::WORKING_START_TIME, new DateTimeZone('UTC')); $time_end = new AB_DateTime(AB_StaffScheduleItem::WORKING_END_TIME, new DateTimeZone('UTC')); // Run the loop. while ($time_start->format('U') <= $time_end->format('U')) { $result['time'][] = array('value' => $time_start->format('H:i'), 'title' => date_i18n($tf, $time_start->format('U'))); $time_start->modify('+' . $ts_length . ' min'); } echo json_encode($result); exit(0); }