PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.5.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.5.2
5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / controllers / steps_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 1 month ago auth_controller.php 3 months ago booking_form_settings_controller.php 3 months ago bookings_controller.php 2 months ago calendars_controller.php 3 months ago carts_controller.php 3 months ago controller.php 3 months ago customer_cabinet_controller.php 2 months ago customers_controller.php 3 months ago dashboard_controller.php 2 months ago default_agent_controller.php 3 months ago events_controller.php 3 months ago form_fields_controller.php 3 months ago integrations_controller.php 3 months ago invoices_controller.php 2 months ago manage_booking_by_key_controller.php 3 months ago manage_order_by_key_controller.php 3 months ago notifications_controller.php 3 months ago orders_controller.php 3 months ago pro_controller.php 2 months ago process_jobs_controller.php 3 months ago processes_controller.php 3 months ago search_controller.php 3 months ago services_controller.php 3 months ago settings_controller.php 2 months ago steps_controller.php 3 months ago stripe_connect_controller.php 2 months ago support_topics_controller.php 3 months ago todos_controller.php 3 months ago transactions_controller.php 3 months ago wizard_controller.php 2 months ago
steps_controller.php
393 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 if ( ! class_exists( 'OsStepsController' ) ) :
8
9
10 class OsStepsController extends OsController {
11
12 private $booking;
13
14 function __construct() {
15 parent::__construct();
16 $this->action_access['customer'] = array_merge( $this->action_access['customer'], [] );
17 $this->action_access['public'] = array_merge(
18 $this->action_access['public'],
19 [
20 'start',
21 'start_instant',
22 'load_step',
23 'reload_booking_form_summary_panel',
24 'check_order_intent_bookable',
25 'load_datepicker_month',
26 'start_from_order_intent',
27 ]
28 );
29
30 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'steps/';
31 $this->vars['page_header'] = __( 'Appointments', 'latepoint' );
32 $this->vars['breadcrumbs'][] = array(
33 'label' => __( 'Appointments', 'latepoint' ),
34 'link' => OsRouterHelper::build_link(
35 [
36 'bookings',
37 'pending_approval',
38 ]
39 ),
40 );
41 }
42
43
44 public function start_instant() {
45 $atts = [];
46 if ( ! empty( $this->params['selected_agent'] ) ) {
47 $atts['selected_agent'] = sanitize_text_field( $this->params['selected_agent'] );
48 }
49 if ( ! empty( $this->params['selected_service'] ) ) {
50 $atts['selected_service'] = sanitize_text_field( $this->params['selected_service'] );
51 }
52 if ( ! empty( $this->params['selected_location'] ) ) {
53 $atts['selected_location'] = sanitize_text_field( $this->params['selected_location'] );
54 }
55
56 if ( ! empty( $this->params['hide_side_panel'] ) && $this->params['hide_side_panel'] == 'yes' ) {
57 $atts['hide_side_panel'] = 'yes';
58 }
59 if ( ! empty( $this->params['hide_summary'] ) && $this->params['hide_summary'] == 'yes' ) {
60 $atts['hide_summary'] = 'yes';
61 }
62 if ( ! empty( $this->params['background_pattern'] ) ) {
63 $this->vars['background_pattern'] = sanitize_text_field( $this->params['background_pattern'] );
64 }
65
66 $this->vars['atts'] = $atts;
67 $this->set_layout( 'clean' );
68 $this->format_render( __FUNCTION__ );
69 }
70
71 public function load_datepicker_month() {
72 OsStepsHelper::set_required_objects( $this->params );
73
74 $target_date = new OsWpDateTime( $this->params['target_date_string'] );
75 $calendar_settings = [
76 'layout' => $this->params['calendar_layout'] ?? 'classic',
77 'timezone_name' => $this->params['timezone_name'] ?? false,
78 ];
79
80 $calendar_settings['earliest_possible_booking'] = OsSettingsHelper::get_earliest_possible_booking_restriction( OsStepsHelper::$booking_object->service_id ?? false );
81 $calendar_settings['latest_possible_booking'] = OsSettingsHelper::get_latest_possible_booking_restriction( OsStepsHelper::$booking_object->service_id ?? false );
82
83 $this->format_render(
84 'partials/_monthly_calendar_days',
85 [
86 'target_date' => $target_date,
87 'calendar_settings' => $calendar_settings,
88 'booking_request' => \LatePoint\Misc\BookingRequest::create_from_booking_model( OsStepsHelper::$booking_object ),
89 ]
90 );
91 }
92
93
94 public function check_order_intent_bookable() {
95 OsStepsHelper::set_required_objects( $this->params );
96 if ( OsStepsHelper::$cart_object->order_id ) {
97 // already converted, so we are good
98 $this->send_json(
99 [
100 'status' => LATEPOINT_STATUS_SUCCESS,
101 'message' => __( 'Cart has already been converted to order', 'latepoint' ),
102 ]
103 );
104 }
105 $order_intent = OsOrderIntentHelper::create_or_update_order_intent( OsStepsHelper::$cart_object, OsStepsHelper::$restrictions, OsStepsHelper::$presets, '', OsStepsHelper::get_customer_object_id() );
106 if ( $order_intent->is_bookable() ) {
107 $this->send_json(
108 [
109 'status' => LATEPOINT_STATUS_SUCCESS,
110 'message' => __( 'Order intent can be converted to order', 'latepoint' ),
111 ]
112 );
113 } else {
114 $this->send_json(
115 [
116 'status' => LATEPOINT_STATUS_ERROR,
117 'message' => __( 'Selected booking slot is not available anymore. Please pick a different time slot.', 'latepoint' ),
118 ]
119 );
120 }
121 }
122
123 function generate_timeslots_for_day() {
124 OsStepsHelper::set_required_objects( $this->params );
125
126
127
128 wp_send_json(
129 [
130 'status' => LATEPOINT_STATUS_SUCCESS,
131 'message' => '',
132 ]
133 );
134 }
135
136
137 function reload_booking_form_summary_panel() {
138 OsStepsHelper::set_required_objects( $this->params );
139 $this->vars['cart'] = OsStepsHelper::$cart_object;
140
141 if ( OsStepsHelper::is_ready_for_summary() ) {
142 $this->vars['current_step_code'] = $this->params['current_step_code'] ?? '';
143 $this->vars['booking'] = OsStepsHelper::$booking_object;
144 $this->vars['customer'] = OsStepsHelper::get_customer_object();
145 $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
146
147 if ( $this->get_return_format() == 'json' ) {
148 $response_html = $this->render( $this->views_folder . 'partials/_booking_form_summary_panel', 'none' );
149 wp_send_json(
150 [
151 'status' => LATEPOINT_STATUS_SUCCESS,
152 'message' => $response_html,
153 ]
154 );
155 exit();
156 } else {
157 echo $this->render( $this->views_folder . 'partials/_booking_form_summary_panel', $this->get_layout() );
158 }
159 } else {
160 wp_send_json(
161 [
162 'status' => LATEPOINT_STATUS_SUCCESS,
163 'message' => '',
164 ]
165 );
166 }
167 }
168
169
170 public function start_from_order_intent() {
171 $order_intent = OsOrderIntentHelper::get_order_intent_by_intent_key( $this->params['order_intent_key'] );
172
173 if ( ! $order_intent->is_new_record() ) {
174 $step_codes_to_preload = [];
175 $steps = OsStepsHelper::get_steps();
176 OsStepsHelper::set_required_objects( $this->params );
177
178 if ( $order_intent->order_id ) {
179 // if order is created - load it
180 OsStepsHelper::load_order_object( $order_intent->order_id );
181 $current_step_code = 'confirmation';
182 $current_step = $steps[ $current_step_code ];
183
184 $this->vars['price_breakdown_rows'] = OsStepsHelper::$order_object->generate_price_breakdown_rows();
185
186 $steps = [ 'confirmation' => $steps['confirmation'] ];
187
188
189 } else {
190
191 OsStepsHelper::set_cart_object_from_order_intent( $order_intent );
192 $current_step_code = 'verify';
193 $current_step = $steps[ $current_step_code ];
194
195
196 foreach ( OsStepsHelper::$step_codes_in_order as $step_code ) {
197 if ( $step_code == $current_step_code ) {
198 break;
199 } else {
200 $step_codes_to_preload[] = $step_code;
201 }
202 }
203
204 $this->vars['price_breakdown_rows'] = OsStepsHelper::$cart_object->generate_price_breakdown_rows();
205 // order exists - only load confirmation step
206 $this->vars['step_codes_to_preload'] = $step_codes_to_preload;
207
208 }
209
210 $this->vars['cart'] = OsStepsHelper::$cart_object;
211 $this->vars['show_next_btn'] = OsStepsHelper::can_step_show_next_btn( $current_step_code );
212 $this->vars['show_prev_btn'] = OsStepsHelper::can_step_show_prev_btn( $current_step_code );
213 $this->vars['all_steps'] = OsStepsHelper::get_steps( true );
214 $this->vars['steps'] = $steps;
215 $this->vars['current_step'] = $current_step;
216
217 $this->vars['current_step_code'] = $current_step_code;
218 $this->vars['booking'] = OsStepsHelper::$booking_object;
219 $this->vars['customer'] = OsStepsHelper::get_customer_object();
220 $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
221 $this->vars['restrictions'] = OsStepsHelper::$restrictions;
222 $this->vars['presets'] = OsStepsHelper::$presets;
223 $this->vars['booking_element_type'] = 'lightbox';
224 $this->vars['booking_element_styles'] = [];
225
226
227
228
229
230 $this->set_layout( 'none' );
231
232 $this->format_render( 'start', array(), array( 'lightbox_class' => '' ) );
233 } else {
234 $this->send_json(
235 array(
236 'status' => LATEPOINT_STATUS_ERROR,
237 'message' => __( 'Invalid order intent key', 'latepoint' ),
238 )
239 );
240 }
241 }
242
243 public function start( array $custom_restrictions = [], array $custom_presets = [], array $booking_element_styles = [], bool $output = true, string $booking_element_type = 'lightbox' ) {
244 $merged_params = $this->params;
245
246 if ( ! empty( $custom_restrictions ) ) {
247 $merged_params['restrictions'] = $custom_restrictions;
248 }
249 if ( ! empty( $custom_presets ) ) {
250 $merged_params['presets'] = $custom_presets;
251 }
252 if ( ! empty( $this->params['booking_element_type'] ) ) {
253 $booking_element_type = $this->params['booking_element_type'];
254 }
255
256
257 if ( ! empty( $merged_params['booking_element_styles'] ) ) {
258 $booking_element_styles = array_merge( $booking_element_styles, $merged_params['booking_element_styles'] );
259 }
260
261 // set early to check if it's converted or should be emptied
262 OsStepsHelper::set_cart_object();
263 if ( ! empty( OsStepsHelper::$cart_object->order_id ) ) {
264 OsCartsHelper::reset_cart();
265 OsStepsHelper::set_cart_object();
266 }
267 // clear cart if "shopping cart" feature is not enabled
268 if ( ! OsCartsHelper::can_checkout_multiple_items() ) {
269 OsStepsHelper::$cart_object->clear();
270 }
271
272
273
274
275 OsStepsHelper::set_required_objects( $merged_params );
276
277 $steps = OsStepsHelper::get_steps();
278
279 $current_step_code = OsStepsHelper::get_step_codes_in_order()[0];
280
281 if ( OsStepsHelper::should_step_be_skipped( $current_step_code ) ) {
282 $current_step_code = OsStepsHelper::get_next_step_code( $current_step_code );
283 }
284 // check if all booking steps have to be skipped, if so - it means the booking object is ready and we can add it to the cart
285 $ready_to_add_to_cart = true;
286 if ( OsStepsHelper::$active_cart_item->is_booking() ) {
287 foreach ( $steps as $step_code => $step_object ) {
288 $step_main_parent_code = explode( '__', $step_code );
289 if ( ! empty( $step_main_parent_code[0] ) && $step_main_parent_code[0] == 'booking' ) {
290 $ready_to_add_to_cart = false;
291 break;
292 }
293 }
294 }
295 // looks like item is ready to be added to cart (because all necessary steps/presets where applied in a trigger element), add it to cart
296 if ( $ready_to_add_to_cart ) {
297 try {
298 OsStepsHelper::add_current_item_to_cart();
299 } catch ( Exception $e ) {
300 $this->vars['booking'] = OsStepsHelper::$booking_object;
301 if ( $output ) {
302 $this->format_render( 'preset_slot_not_available' );
303 return false;
304 } else {
305 return $this->format_render_return( 'preset_slot_not_available' );
306 }
307 }
308 }
309 $current_step = $steps[ $current_step_code ];
310
311 $this->vars['cart'] = OsStepsHelper::$cart_object;
312 $this->vars['show_next_btn'] = OsStepsHelper::can_step_show_next_btn( $current_step->code );
313 $this->vars['show_prev_btn'] = OsStepsHelper::can_step_show_prev_btn( $current_step->code );
314 $this->vars['all_steps'] = OsStepsHelper::get_steps( true );
315 $this->vars['steps'] = $steps;
316 $this->vars['current_step'] = $current_step;
317
318 $this->vars['current_step_code'] = $current_step->code;
319 $this->vars['booking'] = OsStepsHelper::$booking_object;
320 $this->vars['customer'] = OsStepsHelper::get_customer_object();
321 $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
322 $this->vars['restrictions'] = OsStepsHelper::$restrictions;
323 $this->vars['presets'] = OsStepsHelper::$presets;
324 $this->vars['booking_element_type'] = $booking_element_type;
325 $this->vars['booking_element_styles'] = $booking_element_styles;
326 $this->vars['timezone_name'] = OsTimeHelper::get_timezone_name_from_session();
327
328 $this->set_layout( 'none' );
329
330
331
332 if ( $output ) {
333 $this->format_render( __FUNCTION__, [], [ 'step' => $current_step->code ] );
334 } else {
335 return $this->format_render_return( __FUNCTION__, [], [ 'step' => $current_step->code ] );
336 }
337 }
338
339
340 public function load_step() {
341 OsStepsHelper::set_required_objects( $this->params );
342
343 $current_step_code = OsStepsHelper::retrieve_step_code( $this->params['current_step_code'] );
344 if ( empty( $current_step_code ) ) {
345 return false;
346 }
347
348 $step_direction = $this->params['step_direction'] ?? 'next';
349 $step_code_to_load = false;
350 switch ( $step_direction ) {
351 case 'next':
352 /**
353 * Process step by code
354 *
355 * @param {string} $step_code step code that will be processed
356 * @param {OsBookingModel} $booking booking object
357 * @param {array} $params array of params
358 *
359 * @since 5.0.0
360 * @hook latepoint_process_step
361 *
362 */
363 do_action( 'latepoint_process_step', $current_step_code, OsStepsHelper::$booking_object, $this->params );
364 $step_code_to_load = OsStepsHelper::get_next_step_code( $current_step_code );
365 break;
366 case 'prev':
367 $step_code_to_load = OsStepsHelper::get_prev_step_code( $current_step_code );
368 break;
369 case 'specific':
370 $step_code_to_load = OsStepsHelper::should_step_be_skipped( $current_step_code ) ? OsStepsHelper::get_next_step_code( $current_step_code ) : $current_step_code;
371 break;
372 }
373 if ( $step_code_to_load ) {
374
375 /**
376 * Load step by code
377 *
378 * @param {string} $step_code step code to load
379 * @param {string} $type type of return (json)
380 * @param {array} $params array of params
381 *
382 * @since 5.0.0
383 * @hook latepoint_load_step
384 *
385 */
386 do_action( 'latepoint_load_step', $step_code_to_load, 'json', $this->params );
387 }
388 }
389 }
390
391
392 endif;
393