private function _map_description_post_to_worker_id($post_id) { global $appointments, $wpdb; $workers = appointments_get_workers(array('page' => $post_id)); if (!empty($workers)) { return $workers[0]->ID; } return false; }
?> </th> <th style="width:25%"><?php _e('Bio page', 'appointments'); ?> </th> </tr> <tr> <td colspan="6"><span class="description" style="font-size:11px"><?php _e('* <b>You must select at least one service, otherwise provider will not be saved!</b>', 'appointments'); ?> </span> </td> </tr> <?php $workers = appointments_get_workers(); $max_id = 0; if (is_array($workers) && ($nos = count($workers))) { foreach ($workers as $worker) { echo $appointments->add_worker(true, $worker); if ($worker->ID > $max_id) { $max_id = $worker->ID; } } } else { echo '<tr class="no_workers_defined"><td colspan="6">' . __('No service providers defined', 'appointments') . '</td></tr>'; } ?> </table>
function appointments_get_workers_by_service($service_id, $order_by = 'ID') { $workers = appointments_get_workers(array('orderby' => $order_by)); $filtered_workers = array(); foreach ($workers as $worker) { /** @var Appointments_Worker $worker */ if (in_array($service_id, $worker->services_provided)) { $filtered_workers[] = $worker; } } return $filtered_workers; }
/** * @group cache */ function test_workers_cache() { $args = $this->factory->post->generate_args(); $args['post_type'] = 'page'; $page_id = $this->factory->post->create_object($args); $service_id = appointments_insert_service(array('name' => 'My Service')); $args = $this->factory->user->generate_args(); $user_id = $this->factory->user->create_object($args); $args = $this->factory->user->generate_args(); $user_id_2 = $this->factory->user->create_object($args); $args = $this->factory->user->generate_args(); $user_id_3 = $this->factory->user->create_object($args); $args = array('ID' => $user_id, 'price' => '19.7', 'page' => $page_id, 'services_provided' => array($service_id), 'dummy' => true); appointments_insert_worker($args); $worker = wp_cache_get($user_id, 'app_workers'); $this->assertFalse($worker); // This will set the cache appointments_get_worker($user_id); $worker = wp_cache_get($user_id, 'app_workers'); $this->assertEquals($worker->ID, $user_id); appointments_delete_worker($user_id); $worker = wp_cache_get($service_id, 'app_workers'); $this->assertFalse($worker); appointments_insert_worker($args); appointments_get_worker($user_id); appointments_update_worker($user_id, array('dummy' => false)); $worker = wp_cache_get($user_id, 'app_workers'); $this->assertFalse($worker); appointments_insert_worker(array('ID' => $user_id_2, 'services_provided' => array($service_id))); $workers = appointments_get_workers(); $this->assertCount(2, $workers); $cache = wp_cache_get('app_get_workers'); $this->assertCount(1, $cache); $workers = appointments_get_workers(array('page' => 8888)); $this->assertCount(0, $workers); $cache = wp_cache_get('app_get_workers'); $this->assertCount(1, $cache); $workers = appointments_get_workers(array('page' => $page_id)); $this->assertCount(1, $workers); $cache = wp_cache_get('app_get_workers'); $this->assertCount(2, $cache); $this->assertNotEmpty(wp_cache_get($user_id, 'app_workers')); // If we insert another worker, cache sould be cleared appointments_insert_worker(array('ID' => $user_id_3, 'services_provided' => array($service_id))); $this->assertFalse(wp_cache_get('app_get_workers')); // If we select again, cache should be refreshed $workers = appointments_get_workers(); $this->assertCount(3, $workers); $cache = wp_cache_get('app_get_workers'); $this->assertCount(1, $cache); wp_cache_flush(); // If we get all workers, they should be added to workers list cache appointments_get_workers(); $worker = wp_cache_get($user_id, 'app_workers'); $this->assertEquals($worker->ID, $user_id); }
function content($instance) { $args = array(); //extract( $instance ); $args['limit'] = !empty($instance['number']) && is_numeric($instance['number']) ? (int) $instance['number'] : 5; $args['with_page'] = !empty($instance['allow_no_links']) ? false : true; global $appointments; $results = appointments_get_workers($args); if ($results) { echo '<ul>'; foreach ($results as $result) { $link_template = !empty($result->page) ? '<a href="' . get_permalink($result->page) . '">%s</a>' : '<span class="app_worker">%s</a>'; echo '<li>' . sprintf($link_template, $appointments->get_worker_name($result->ID)) . '</li>'; } echo '</ul>'; } }
function inline_edit() { global $appointments; $safe_date_format = $appointments->safe_date_format(); // Make a locale check to update locale_error flag $date_check = $appointments->to_us(date_i18n($safe_date_format, strtotime('today'))); global $wpdb; $app_id = $_POST["app_id"]; $end_datetime = ''; if ($app_id) { $app = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$appointments->app_table} WHERE ID=%d", $app_id)); $start_date_timestamp = date("Y-m-d", strtotime($app->start)); if ($appointments->locale_error) { $start_date = date($safe_date_format, strtotime($app->start)); } else { $start_date = date_i18n($safe_date_format, strtotime($app->start)); } $start_time = date_i18n($appointments->time_format, strtotime($app->start)); $end_datetime = date_i18n($appointments->datetime_format, strtotime($app->end)); // Is this a registered user? if ($app->user) { $name = get_user_meta($app->user, 'app_name', true); if ($name) { $app->name = $app->name && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->name : $name; } $email = get_user_meta($app->user, 'app_email', true); if ($email) { $app->email = $app->email && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->email : $email; } $phone = get_user_meta($app->user, 'app_phone', true); if ($phone) { $app->phone = $app->phone && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->phone : $phone; } $address = get_user_meta($app->user, 'app_address', true); if ($address) { $app->address = $app->address && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->address : $address; } $city = get_user_meta($app->user, 'app_city', true); if ($city) { $app->city = $app->city && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->city : $city; } } } else { $app = new stdClass(); // This means insert a new app object $app->ID = 0; // Set other fields to default so that we don't get notice messages $app->user = $app->location = $app->worker = 0; $app->created = $app->end = $app->name = $app->email = $app->phone = $app->address = $app->city = $app->status = $app->sent = $app->sent_worker = $app->note = ''; // Get first service and its price $app->service = $appointments->get_first_service_id(); $_REQUEST['app_service_id'] = $app->service; $_REQUEST['app_provider_id'] = 0; $app->price = $appointments->get_price(); // Select time as next 1 hour $start_time = date_i18n($appointments->time_format, intval(($appointments->local_time + 60 * $appointments->get_min_time()) / 3600) * 3600); $start_date_timestamp = date("Y-m-d", $appointments->local_time + 60 * $appointments->get_min_time()); // Set start date as now + 60 minutes. if ($appointments->locale_error) { $start_date = date($safe_date_format, $appointments->local_time + 60 * $appointments->get_min_time()); } else { $start_date = date_i18n($safe_date_format, $appointments->local_time + 60 * $appointments->get_min_time()); } } $html = ''; $html .= '<tr class="inline-edit-row inline-edit-row-post quick-edit-row-post">'; $html .= isset($_POST['col_len']) && is_numeric($_POST['col_len']) ? '<td colspan="' . (int) $_POST["col_len"] . '" class="colspanchange">' : '<td colspan="6" class="colspanchange">'; $html .= '<fieldset class="inline-edit-col-left" style="width:33%">'; $html .= '<div class="inline-edit-col">'; $html .= '<h4>' . __('CLIENT', 'appointments') . '</h4>'; /* user */ $html .= '<label>'; $html .= '<span class="title">' . __('User', 'appointments') . '</span>'; $html .= wp_dropdown_users(array('show_option_all' => __('Not registered user', 'appointments'), 'show' => 'user_login', 'echo' => 0, 'selected' => $app->user, 'name' => 'user')); $html .= '</label>'; /* Client name */ $html .= '<label>'; $html .= '<span class="title">' . $appointments->get_field_name('name') . '</span>'; $html .= '<span class="input-text-wrap">'; $html .= '<input type="text" name="cname" class="ptitle" value="' . esc_attr(stripslashes($app->name)) . '" />'; $html .= '</span>'; $html .= '</label>'; /* Client email */ $html .= '<label>'; $html .= '<span class="title">' . $appointments->get_field_name('email') . '</span>'; $html .= '<span class="input-text-wrap">'; $html .= '<input type="text" name="email" class="ptitle" value="' . esc_attr($app->email) . '" />'; $html .= '</span>'; $html .= '</label>'; /* Client Phone */ $html .= '<label>'; $html .= '<span class="title">' . $appointments->get_field_name('phone') . '</span>'; $html .= '<span class="input-text-wrap">'; $html .= '<input type="text" name="phone" class="ptitle" value="' . esc_attr(stripslashes($app->phone)) . '" />'; $html .= '</span>'; $html .= '</label>'; /* Client Address */ $html .= '<label>'; $html .= '<span class="title">' . $appointments->get_field_name('address') . '</span>'; $html .= '<span class="input-text-wrap">'; $html .= '<input type="text" name="address" class="ptitle" value="' . esc_attr(stripslashes($app->address)) . '" />'; $html .= '</span>'; $html .= '</label>'; /* Client City */ $html .= '<label>'; $html .= '<span class="title">' . $appointments->get_field_name('city') . '</span>'; $html .= '<span class="input-text-wrap">'; $html .= '<input type="text" name="city" class="ptitle" value="' . esc_attr(stripslashes($app->city)) . '" />'; $html .= '</span>'; $html .= '</label>'; $html .= apply_filters('app-appointments_list-edit-client', '', $app); $html .= '</div>'; $html .= '</fieldset>'; $html .= '<fieldset class="inline-edit-col-center" style="width:28%">'; $html .= '<div class="inline-edit-col">'; $html .= '<h4>' . __('SERVICE', 'appointments') . '</h4>'; /* Services */ $services = $appointments->get_services(); $html .= '<label>'; $html .= '<span class="title">' . __('Name', 'appointments') . '</span>'; $html .= '<select name="service">'; if ($services) { foreach ($services as $service) { if ($app->service == $service->ID) { $sel = ' selected="selected"'; } else { $sel = ''; } $html .= '<option value="' . esc_attr($service->ID) . '"' . $sel . '>' . stripslashes($service->name) . '</option>'; } } $html .= '</select>'; $html .= '</label>'; /* Workers */ $workers = appointments_get_workers(); $html .= '<label>'; $html .= '<span class="title">' . __('Provider', 'appointments') . '</span>'; $html .= '<select name="worker">'; // Always add an "Our staff" field $html .= '<option value="0">' . __('No specific provider', 'appointments') . '</option>'; if ($workers) { foreach ($workers as $worker) { if ($app->worker == $worker->ID) { $sel = ' selected="selected"'; } else { $sel = ''; } $html .= '<option value="' . esc_attr($worker->ID) . '"' . $sel . '>' . $appointments->get_worker_name($worker->ID, false) . '</option>'; } } $html .= '</select>'; $html .= '</label>'; /* Price */ $html .= '<label>'; $html .= '<span class="title">' . __('Price', 'appointments') . '</span>'; $html .= '<span class="input-text-wrap">'; $html .= '<input type="text" name="price" style="width:50%" class="ptitle" value="' . esc_attr($app->price) . '" />'; $html .= '</span>'; $html .= '</label>'; $html .= '</label>'; $html .= apply_filters('app-appointments_list-edit-services', '', $app); $html .= '</div>'; $html .= '</fieldset>'; $html .= '<fieldset class="inline-edit-col-right" style="width:38%">'; $html .= '<div class="inline-edit-col">'; $html .= '<h4>' . __('APPOINTMENT', 'appointments') . '</h4>'; /* Created - Don't show for a new app */ if ($app_id) { $html .= '<label>'; $html .= '<span class="title">' . __('Created', 'appointments') . '</span>'; $html .= '<span class="input-text-wrap" style="height:26px;padding-top:4px;">'; $html .= date_i18n($appointments->datetime_format, strtotime($app->created)); $html .= '</span>'; $html .= '</label>'; } /* Start */ $html .= '<label style="float:left;width:65%">'; $html .= '<span class="title">' . __('Start', 'appointments') . '</span>'; $html .= '<span class="input-text-wrap" >'; $html .= '<input type="text" name="date" class="datepicker" size="12" value="' . esc_attr($start_date) . '" data-timestamp="' . esc_attr($start_date_timestamp) . '" />'; $html .= '</label>'; $html .= '<label style="float:left;width:30%; padding-left:5px;">'; // Check if an admin min time (time base) is set. @since 1.0.2 if (isset($appointments->options["admin_min_time"]) && $appointments->options["admin_min_time"]) { $min_time = $appointments->options["admin_min_time"]; } else { $min_time = $appointments->get_min_time(); } $min_secs = 60 * apply_filters('app_admin_min_time', $min_time); $html .= '<select name="time" >'; for ($t = 0; $t < 3600 * 24; $t = $t + $min_secs) { $s = array(); $dhours = $appointments->secs2hours($t); // Hours in 08:30 format $s[] = $dhours == $start_time ? 'selected="selected"' : ''; $s[] = 'value="' . esc_attr($appointments->secs2hours($t, 'H:i')) . '"'; $html .= '<option ' . join(' ', array_values(array_filter($s))) . '>'; $html .= $dhours; $html .= '</option>'; } $html .= '</select>'; $html .= '</span>'; $html .= '</label>'; $html .= '<div style="clear:both; height:0"></div>'; /* End - Don't show for a new app */ if ($app_id) { $html .= '<label style="margin-top:8px">'; $html .= '<span class="title">' . __('End', 'appointments') . '</span>'; $html .= '<span class="input-text-wrap" style="height:26px;padding-top:4px;">'; $html .= $end_datetime; $html .= '</span>'; $html .= '</label>'; } /* Note */ $html .= '<label>'; $html .= '<span class="title">' . $appointments->get_field_name('note') . '</span>'; $html .= '<textarea cols="22" rows=1">'; $html .= esc_textarea(stripslashes($app->note)); $html .= '</textarea>'; $html .= '</label>'; /* Status */ //$statuses = $this->get_statuses(); $statuses = App_Template::get_status_names(); $html .= '<label>'; $html .= '<span class="title">' . __('Status', 'appointments') . '</span>'; $html .= '<span class="input-text-wrap">'; $html .= '<select name="status">'; if ($statuses) { foreach ($statuses as $status => $status_name) { if ($app->status == $status) { $sel = ' selected="selected"'; } else { $sel = ''; } $html .= '<option value="' . $status . '"' . $sel . '>' . $status_name . '</option>'; } } $html .= '</select>'; $html .= '</span>'; $html .= '</label>'; /* Confirmation email */ // Default is "checked" for a new appointment if ($app_id) { $c = ''; $text = __('(Re)send confirmation email', 'appointments'); } else { $c = ' checked="checked"'; $text = __('Send confirmation email', 'appointments'); } $html .= '<label>'; $html .= '<span class="title">' . __('Confirm', 'appointments') . '</span>'; $html .= '<span class="input-text-wrap">'; $html .= '<input type="checkbox" name="resend" value="1" ' . $c . ' /> ' . $text; $html .= '</span>'; $html .= '</label>'; $html .= '</div>'; $html .= '</fieldset>'; /* General fields required for save and cancel */ $html .= '<p class="submit inline-edit-save">'; $html .= '<a href="javascript:void(0)" title="' . _x('Cancel', 'Drop current action', 'appointments') . '" class="button-secondary cancel alignleft">' . _x('Cancel', 'Drop current action', 'appointments') . '</a>'; if ('reserved' == $app->status) { $js = 'style="display:none"'; $title = __('GCal reserved appointments cannot be edited here. Edit them in your Google calendar.', 'appointments'); } else { $js = 'href="javascript:void(0)"'; $title = __('Click to save or update', 'appointments'); } $html .= '<a ' . $js . ' title="' . esc_attr($title) . '" class="button-primary save alignright">' . __('Save / Update', 'appointments') . '</a>'; $html .= '<img class="waiting" style="display:none;" src="' . admin_url('images/wpspin_light.gif') . '" alt="">'; $html .= '<input type="hidden" name="app_id" value="' . esc_attr($app->ID) . '">'; $html .= '<span class="error" style="display:none"></span>'; $html .= '<br class="clear">'; $html .= '</p>'; $html .= '</td>'; $html .= '</tr>'; die(json_encode(array('result' => $html))); }
/** * Get all workers * @param order_by: ORDER BY clause for mysql * @return array of objects */ function get_workers($order_by = "ID") { $args = array('orderby' => $order_by); return appointments_get_workers($args); // @TODO: Some sorting: // Sorting by name requires special case if (stripos($order_by, 'name') !== false) { $workers_ = $this->db->get_results("SELECT * FROM " . $this->workers_table . " "); if (stripos($order_by, 'desc') !== false) { usort($workers_, array(&$this, 'get_workers_desc')); } else { usort($workers_, array(&$this, 'get_workers_asc')); } $workers = $workers_; } else { $workers = $this->db->get_results("SELECT * FROM " . $this->workers_table . " ORDER BY " . esc_sql($order_by) . " "); } wp_cache_set($orderby_cache_key, $order_by, 'appointments_workers'); wp_cache_set($results_cache_key, $workers, 'appointments_workers'); }