PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / 1.1.35
OttoKit: All-in-One Automation Platform v1.1.35
1.1.37 1.1.36 1.1.35 1.1.34 1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Integrations / jet-appointments-booking / jet-appointments-booking.php
suretriggers / src / Integrations / jet-appointments-booking Last commit date
actions 7 months ago triggers 7 months ago jet-appointments-booking.php 7 months ago
jet-appointments-booking.php
159 lines
1 <?php
2 /**
3 * Jet Appointments Booking core integrations file
4 *
5 * @since 1.0.0
6 * @package SureTrigger
7 */
8
9 namespace SureTriggers\Integrations\JetAppointmentsBooking;
10
11 use SureTriggers\Controllers\IntegrationsController;
12 use SureTriggers\Integrations\Integrations;
13 use SureTriggers\Traits\SingletonLoader;
14
15 /**
16 * Class JetAppointmentsBooking
17 *
18 * @package SureTriggers\Integrations\JetAppointmentsBooking
19 */
20 class JetAppointmentsBooking extends Integrations {
21
22 use SingletonLoader;
23
24 /**
25 * ID
26 *
27 * @var string
28 */
29 protected $id = 'JetAppointmentsBooking';
30
31 /**
32 * SureTrigger constructor.
33 */
34 public function __construct() {
35 $this->name = __( 'Jet Appointments Booking', 'suretriggers' );
36 $this->description = __( 'A WordPress plugin for creating appointment booking forms and managing appointments with JetEngine.', 'suretriggers' );
37 $this->icon_url = SURE_TRIGGERS_URL . 'assets/icons/jet-appointments-booking.svg';
38 parent::__construct();
39 }
40
41 /**
42 * Is Plugin depended plugin is installed or not.
43 *
44 * @return bool
45 */
46 public function is_plugin_installed() {
47 return class_exists( '\JET_APB\Plugin' );
48 }
49
50 /**
51 * Get appointment meta data.
52 *
53 * @param int $appointment_id The appointment ID.
54 * @return array The appointment meta data.
55 */
56 public static function get_appointment_meta( $appointment_id ) {
57 if ( ! class_exists( '\JET_APB\Plugin' ) ) {
58 return [];
59 }
60
61 global $wpdb;
62
63 // Get and sanitize table name.
64 $meta_table = \JET_APB\Plugin::instance()->db->appointments_meta->table();
65 if ( empty( $meta_table ) || ! is_string( $meta_table ) ) {
66 return [];
67 }
68 $meta_table = esc_sql( $meta_table );
69
70 // Prepare and execute the query using a placeholder for the appointment ID only.
71 $results = $wpdb->get_results(
72 $wpdb->prepare(
73 'SELECT meta_key, meta_value FROM ' . esc_sql( $meta_table ) . ' WHERE appointment_id = %d',
74 $appointment_id
75 ),
76 ARRAY_A
77 );
78
79 $meta = [];
80 if ( ! empty( $results ) ) {
81 foreach ( $results as $row ) {
82 $meta[ $row['meta_key'] ] = $row['meta_value'];
83 }
84 }
85
86 return $meta;
87 }
88
89 /**
90 * Get appointment context data.
91 *
92 * @param int $appointment_id The appointment ID.
93 * @param string $new_status New appointment status (optional).
94 * @param string $old_status Old appointment status (optional).
95 * @return array The appointment context data.
96 */
97 public static function get_appointment_context( $appointment_id, $new_status = null, $old_status = null ) {
98 if ( ! class_exists( '\JET_APB\Plugin' ) ) {
99 return [];
100 }
101
102 $appointment_data = \JET_APB\Plugin::instance()->db->appointments->query( [ 'ID' => $appointment_id ], 1 );
103 if ( empty( $appointment_data ) ) {
104 return [];
105 }
106 $appointment_data = $appointment_data[0];
107
108 $appointment_meta = self::get_appointment_meta( $appointment_id );
109
110 $context = array_merge( $appointment_data, $appointment_meta );
111
112 // Add status information if provided.
113 if ( null !== $old_status ) {
114 $context['old_status'] = $old_status;
115 }
116 if ( null !== $new_status ) {
117 $context['new_status'] = $new_status;
118 }
119
120 // Add service title.
121 if ( ! empty( $context['service'] ) ) {
122 $service_post = get_post( $context['service'] );
123 if ( $service_post ) {
124 $context['service_title'] = $service_post->post_title;
125 }
126 }
127
128 // Add provider title.
129 if ( ! empty( $context['provider'] ) && $context['provider'] > 0 ) {
130 $provider_post = get_post( $context['provider'] );
131 if ( $provider_post ) {
132 $context['provider_title'] = $provider_post->post_title;
133 }
134 }
135
136 // Add user information.
137 if ( ! empty( $context['user_id'] ) ) {
138 $user = get_user_by( 'ID', $context['user_id'] );
139 if ( $user ) {
140 $context['user_login'] = $user->user_login;
141 $context['user_email'] = $user->user_email;
142 $context['user_display_name'] = $user->display_name;
143 }
144 }
145
146 // Format dates.
147 $date_format = get_option( 'date_format' );
148 $time_format = get_option( 'time_format' );
149 $context['date_formatted'] = is_string( $date_format ) ? date_i18n( $date_format, $context['date'] ) : '';
150 $context['slot_formatted'] = is_string( $time_format ) ? date_i18n( $time_format, $context['slot'] ) : '';
151 $context['slot_end_formatted'] = is_string( $time_format ) ? date_i18n( $time_format, $context['slot_end'] ) : '';
152
153 return $context;
154 }
155
156 }
157
158 IntegrationsController::register( JetAppointmentsBooking::class );
159