PluginProbe
Bookit — Booking & Appointment Calendar / 2.6.0.5
Bookit — Booking & Appointment Calendar v2.6.0.5
2.6.0.5 2.6.0.4 2.6.0.3 2.6.0.2 2.6.0.1 2.6.0 trunk 1.2 1.2.2 1.2.3 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 All 62 releases
bookit / includes / classes / database / Staff_Services.php

Staff_Services.php in Bookit — Booking & Appointment Calendar 2.6.0.5, at includes/classes/database/Staff_Services.php

73 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Bookit\Classes\Database;
4
5 use Bookit\Classes\Vendor\DatabaseModel;
6
7 class Staff_Services extends DatabaseModel {
8
9 /**
10 * Create Table
11 */
12 public static function create_table() {
13 global $wpdb;
14 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
15 $table_name = self::_table();
16 $primary_key = self::$primary_key;
17
18 $sql = "CREATE TABLE {$table_name} (
19 id INT UNSIGNED NOT NULL AUTO_INCREMENT,
20 staff_id INT UNSIGNED NOT NULL,
21 service_id INT UNSIGNED NOT NULL,
22 price DECIMAL(10,2) NOT NULL DEFAULT 0.00,
23 PRIMARY KEY ({$primary_key}),
24 INDEX `idx_staff_id` (`staff_id`),
25 INDEX `idx_service_id` (`service_id`)
26 ) {$wpdb->get_charset_collate()};";
27
28 maybe_create_table( $table_name, $sql );
29 }
30
31 public static function get_staff_services( $staffIds ) {
32 global $wpdb;
33
34 return $wpdb->get_results(
35 sprintf(
36 'SELECT `%1$s`.staff_id,
37 `%2$s`.id as serviceId,
38 `%1$s`.price,
39 `%2$s`.title
40 FROM `%1$s`
41 LEFT JOIN `%2$s` ON `%1$s`.service_id = `%2$s`.id
42 WHERE `%1$s`.staff_id IN ( %3$s )
43 ORDER BY `%1$s`.staff_id',
44 esc_sql( self::_table() ), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
45 esc_sql( Services::_table() ), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
46 esc_sql( implode( ',', $staffIds ) ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
47 ),
48 ARRAY_A
49 );
50 }
51
52 /**
53 * Get Service price for choosen Staff
54 */
55 public static function get_service_price_by_staff( $service_id, $staff_id ) {
56 global $wpdb;
57 $sql = sprintf(
58 'SELECT `%1$s`.price
59 FROM `%1$s`
60 WHERE `%1$s`.staff_id = %%d
61 AND `%1$s`.service_id = %%d',
62 esc_sql( self::_table() )
63 );
64 return $wpdb->get_var(
65 $wpdb->prepare(
66 $sql, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
67 intval( $staff_id ),
68 intval( $service_id )
69 )
70 );
71 }
72 }
73