public function process_shortcode($args = array(), $content = '') { global $appointments; $args = wp_parse_args($args, $this->_defaults_to_args()); $workers = $appointments->get_workers($args['order_by']); $model = App_Locations_Model::get_instance(); $locations = array(); foreach ($workers as $wrk) { if (empty($wrk->ID)) { continue; } $location_id = App_Locations_WorkerLocations::worker_to_location_id($wrk->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_provider_locations">'; $ret .= '<div class="app_provider_locations_dropdown">'; $ret .= '<div class="app_provider_locations_dropdown_title">'; $ret .= $args['select']; $ret .= '</div>'; $ret .= '<div class="app_provider_locations_dropdown_select">'; $ret .= '<select name="app_provider_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_provider_locations_button" value="' . esc_attr($args['show']) . '">'; } $ret .= '</div>'; $ret .= '</div>'; $href = add_query_arg('app_provider_location', '::apl::', remove_query_arg(array('app_provider_location', 'app_service_id'))); $script = <<<EO_SELECTION_JAVASCRIPT function app_provider_locations_redirect () { \tvar selected = \$(".app_provider_locations_dropdown_select select").first().val(); \twindow.location = '{$href}'.replace(/::apl::/, selected); } \$(".app_provider_locations_button").click(app_provider_locations_redirect); EO_SELECTION_JAVASCRIPT; if (!empty($args['autorefresh'])) { $script .= '$(".app_provider_locations_dropdown_select select").change(app_provider_locations_redirect);'; } $appointments->add2footer($script); return $ret; }
public static function serve() { $me = new App_Locations_WorkerLocations(); $me->_add_hooks(); }