function appointments_count_services($args = array()) { $args['count'] = true; return appointments_get_services($args); }
/** * @group cache */ function test_services_cache() { $args = $this->factory->post->generate_args(); $args['post_type'] = 'page'; $page_id = $this->factory->post->create_object($args); $args = array('name' => 'My Service 1'); $service_id = appointments_insert_service($args); $service = wp_cache_get($service_id, 'app_services'); $this->assertFalse($service); // This will set the cache appointments_get_service($service_id); $service = wp_cache_get($service_id, 'app_services'); $this->assertEquals($service->name, 'My Service 1'); appointments_delete_service($service_id); $service = wp_cache_get($service_id, 'app_services'); $this->assertFalse($service); $service_id = appointments_insert_service($args); appointments_get_service($service_id); appointments_update_service($service_id, array('name' => 'New name')); $service = wp_cache_get($service_id, 'app_services'); $this->assertFalse($service); $service_id = appointments_insert_service(array('name' => 'Service 1')); appointments_insert_service(array('name' => 'Service 2', 'page' => $page_id)); $services = appointments_get_services(); $this->assertCount(4, $services); $cache = wp_cache_get('app_get_services'); $this->assertCount(1, $cache); $services = appointments_get_services(array('page' => 8888)); $this->assertCount(0, $services); $cache = wp_cache_get('app_get_services'); $this->assertCount(1, $cache); $services = appointments_get_services(array('page' => $page_id)); $this->assertCount(1, $services); $cache = wp_cache_get('app_get_services'); $this->assertCount(2, $cache); $this->assertNotEmpty(wp_cache_get($service_id, 'app_services')); // If we insert another service, cache sould be cleared appointments_insert_service(array('name' => 'Service 3')); $this->assertFalse(wp_cache_get('app_get_services')); // If we select again, cache should be refreshed $services = appointments_get_services(); $this->assertCount(5, $services); $cache = wp_cache_get('app_get_services'); $this->assertCount(1, $cache); }
/** * Warn admin if no services defined or duration is wrong */ function admin_notices() { global $appointments; $this->dismiss(); global $current_user; $r = false; $results = appointments_get_services(); if (!$results) { echo '<div class="error"><p>' . __('<b>[Appointments+]</b> You must define at least once service.', 'appointments') . '</p></div>'; $r = true; } else { foreach ($results as $result) { if ($result->duration < $appointments->get_min_time()) { echo '<div class="error"><p>' . __('<b>[Appointments+]</b> One of your services has a duration smaller than time base. Please visit Services tab and after making your corrections save new settings.', 'appointments') . '</p></div>'; $r = true; break; } if ($result->duration % $appointments->get_min_time() != 0) { echo '<div class="error"><p>' . __('<b>[Appointments+]</b> One of your services is not divisible by the time base. Please visit Services tab and after making your corrections save new settings.', 'appointments') . '</p></div>'; $r = true; break; } if ($result->duration > 1440) { echo '<div class="error"><p>' . __('<b>[Appointments+]</b> One of your services has a duration greater than 24 hours. Appointments+ does not support services exceeding 1440 minutes (24 hours). ', 'appointments') . '</p></div>'; $r = true; break; } $dismissed = false; $dismiss_id = get_user_meta($current_user->ID, 'app_dismiss', true); if ($dismiss_id) { $dismissed = true; } if ($appointments->get_workers() && !$appointments->get_workers_by_service($result->ID) && !$dismissed) { echo '<div class="error"><p>' . __('<b>[Appointments+]</b> One of your services does not have a service provider assigned. Delete services you are not using.', 'appointments') . ' <a title="' . __('Dismiss this notice for this session', 'appointments') . '" href="' . $_SERVER['REQUEST_URI'] . '&app_dismiss=1"><small>' . __('Dismiss', 'appointments') . '</small></a>' . '</p></div>'; $r = true; break; } } } if (!$appointments->db_version || version_compare($appointments->db_version, '1.2.2', '<')) { echo '<div class="error"><p>' . __('<b>[Appointments+]</b> Appointments+ database tables need to be updated. Please deactivate and reactivate the plugin (DO NOT DELETE the plugin). You will not lose any saved information.', 'appointments') . '</p></div>'; $r = true; } // Warn if Openid is not loaded $dismissed_g = false; $dismiss_id_g = get_user_meta($current_user->ID, 'app_dismiss_google', true); if ($dismiss_id_g) { $dismissed_g = true; } if (@$appointments->options['accept_api_logins'] && !@$appointments->openid && !$dismissed_g) { echo '<div class="error"><p>' . __('<b>[Appointments+]</b> Either php curl is not installed or HTTPS wrappers are not enabled. Login with Google+ will not work.', 'appointments') . ' <a title="' . __('Dismiss this notice for this session', 'appointments') . '" href="' . $_SERVER['REQUEST_URI'] . '&app_dismiss_google=1"><small>' . __('Dismiss', 'appointments') . '</small></a>' . '</p></div>'; $r = true; } // Check for duplicate shortcodes for a visited page if (isset($_GET['post']) && $_GET['post'] && $appointments->has_duplicate_shortcode($_GET['post'])) { echo '<div class="error"><p>' . __('<b>[Appointments+]</b> More than one instance of services, service providers, confirmation, Paypal or login shortcodes on the same page may cause problems.</p>', 'appointments') . '</div>'; } // Check for missing confirmation shortcode $dismissed_c = false; $dismiss_id_c = get_user_meta($current_user->ID, 'app_dismiss_confirmation_lacking', true); if ($dismiss_id_c) { $dismissed_c = true; } if (!$dismissed_c && isset($_GET['post']) && $_GET['post'] && $appointments->confirmation_shortcode_missing($_GET['post'])) { echo '<div class="error"><p>' . __('<b>[Appointments+]</b> Confirmation shortcode [app_confirmation] is always required to complete an appointment.', 'appointments') . ' <a title="' . __('Dismiss this notice for this session', 'appointments') . '" href="' . $_SERVER['REQUEST_URI'] . '&app_dismiss_confirmation_lacking=1"><small>' . __('Dismiss', 'appointments') . '</small></a>' . '</p></div>'; $r = true; } return $r; }
private function _map_description_post_to_service_id($post_id) { $services = appointments_get_services(array('page' => $post_id, 'fields' => 'ID')); if (!empty($services)) { return $services[0]; } return ''; }
/** * Get all services * @param order_by: ORDER BY clause for mysql * @return array of objects */ function get_services($order_by = "ID") { $args = array('orderby' => $order_by); return appointments_get_services($args); }