public function process_shortcode($args = array(), $content = '') { global $appointments; $args = wp_parse_args($args, $this->_defaults_to_args()); $services = $appointments->get_services($args['order_by']); $model = App_Locations_Model::get_instance(); $locations = array(); foreach ($services as $srv) { if (empty($srv->ID)) { continue; } $location_id = App_Locations_ServiceLocations::service_to_location_id($srv->ID); if (!empty($location_id)) { $locations[$location_id] = $model->find_by('id', $location_id); } } $locations = array_values(array_filter($locations)); if (empty($locations)) { return $content; } $ret = ''; $ret .= '<div class="app_service_locations">'; $ret .= '<div class="app_service_locations_dropdown">'; $ret .= '<div class="app_service_locations_dropdown_title">'; $ret .= $args['select']; $ret .= '</div>'; $ret .= '<div class="app_service_locations_dropdown_select">'; $ret .= '<select name="app_service_location">'; foreach ($locations as $location) { /** @var App_Locations_DefaultLocation $location */ $ret .= '<option value="' . esc_attr($location->get_id()) . '" ' . selected($this->_requested_location_id, $location->get_id(), false) . '>' . esc_html($location->get_display_markup(false)) . '</option>'; } $ret .= '</select>'; if (empty($args['autorefresh'])) { $ret .= '<input type="button" class="app_service_locations_button" value="' . esc_attr($args['show']) . '">'; } $ret .= '</div>'; $ret .= '</div>'; $href = add_query_arg('app_service_location', '::asl::', remove_query_arg(array('app_provider_location', 'app_provider_id'))); $script = <<<EO_SELECTION_JAVASCRIPT function app_service_locations_redirect () { \tvar selected = \$(".app_service_locations_dropdown_select select").first().val(); \twindow.location = '{$href}'.replace(/::asl::/, selected); } \$(".app_service_locations_button").click(app_service_locations_redirect); EO_SELECTION_JAVASCRIPT; if (!empty($args['autorefresh'])) { $script .= '$(".app_service_locations_dropdown_select select").change(app_service_locations_redirect);'; } $appointments->add2footer($script); return $ret; }
public static function serve() { $me = new App_Locations_ServiceLocations(); $me->_add_hooks(); }