PluginProbe
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.2
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.2
5.6.11 5.6.10 5.6.9 5.6.8 5.6.7 5.6.6 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 All 48 releases
← All changes | lib/controllers/steps_controller.php +88 -133 trunk5.2.2 View file →
@@ -12,32 +12,27 @@
12 12 private $booking;
13 13
14 14 function __construct() {
15 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 - );
16 + $this->action_access['customer'] = array_merge( $this->action_access['customer'], [ ] );
17 + $this->action_access['public'] = array_merge( $this->action_access['public'], [
18 + 'start',
19 + 'start_instant',
20 + 'load_step',
21 + 'reload_booking_form_summary_panel',
22 + 'check_order_intent_bookable',
23 + 'load_datepicker_month',
24 + 'start_from_order_intent'
25 + ] );
29 26
30 27 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'steps/';
31 28 $this->vars['page_header'] = __( 'Appointments', 'latepoint' );
32 29 $this->vars['breadcrumbs'][] = array(
33 30 'label' => __( 'Appointments', 'latepoint' ),
34 - 'link' => OsRouterHelper::build_link(
35 - [
36 - 'bookings',
37 - 'pending_approval',
38 - ]
39 - ),
31 + 'link' => OsRouterHelper::build_link( [
32 + 'bookings',
33 + 'pending_approval'
34 + ] )
40 35 );
41 36 }
42 37
43 38
@@ -42,27 +37,15 @@
42 37
43 38
44 39 public function start_instant() {
45 40 $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 - }
41 + if(!empty($this->params['selected_agent'])) $atts['selected_agent'] = sanitize_text_field($this->params['selected_agent']);
42 + if(!empty($this->params['selected_service'])) $atts['selected_service'] = sanitize_text_field($this->params['selected_service']);
43 + if(!empty($this->params['selected_location'])) $atts['selected_location'] = sanitize_text_field($this->params['selected_location']);
55 44
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 - }
45 + if(!empty($this->params['hide_side_panel']) && $this->params['hide_side_panel'] == 'yes') $atts['hide_side_panel'] = 'yes';
46 + if(!empty($this->params['hide_summary']) && $this->params['hide_summary'] == 'yes') $atts['hide_summary'] = 'yes';
47 + if(!empty($this->params['background_pattern'])) $this->vars['background_pattern'] = sanitize_text_field($this->params['background_pattern']);
65 48
66 49 $this->vars['atts'] = $atts;
67 50 $this->set_layout( 'clean' );
68 51 $this->format_render( __FUNCTION__ );
@@ -72,67 +55,52 @@
72 55 OsStepsHelper::set_required_objects( $this->params );
73 56
74 57 $target_date = new OsWpDateTime( $this->params['target_date_string'] );
75 58 $calendar_settings = [
76 - 'layout' => $this->params['calendar_layout'] ?? 'classic',
77 - 'timezone_name' => $this->params['timezone_name'] ?? false,
59 + 'layout' => $this->params['calendar_layout'] ?? 'classic',
60 + 'timezone_name' => $this->params['timezone_name'] ?? false,
78 61 ];
79 62
80 63 $calendar_settings['earliest_possible_booking'] = OsSettingsHelper::get_earliest_possible_booking_restriction( OsStepsHelper::$booking_object->service_id ?? false );
81 64 $calendar_settings['latest_possible_booking'] = OsSettingsHelper::get_latest_possible_booking_restriction( OsStepsHelper::$booking_object->service_id ?? false );
82 - $calendar_settings['consider_cart_items'] = true;
83 65
84 - $this->format_render(
85 - 'partials/_monthly_calendar_days',
86 - [
87 - 'target_date' => $target_date,
88 - 'calendar_settings' => $calendar_settings,
89 - 'booking_request' => \LatePoint\Misc\BookingRequest::create_from_booking_model( OsStepsHelper::$booking_object ),
90 - ]
91 - );
66 + $this->format_render( 'partials/_monthly_calendar_days', [
67 + 'target_date' => $target_date,
68 + 'calendar_settings' => $calendar_settings,
69 + 'booking_request' => \LatePoint\Misc\BookingRequest::create_from_booking_model( OsStepsHelper::$booking_object )
70 + ] );
92 71 }
93 72
94 73
95 74 public function check_order_intent_bookable() {
96 75 OsStepsHelper::set_required_objects( $this->params );
97 - if ( OsStepsHelper::$cart_object->order_id ) {
76 + if(OsStepsHelper::$cart_object->order_id){
98 77 // already converted, so we are good
99 - $this->send_json(
100 - [
101 - 'status' => LATEPOINT_STATUS_SUCCESS,
102 - 'message' => __( 'Cart has already been converted to order', 'latepoint' ),
103 - ]
104 - );
78 + $this->send_json( [
79 + 'status' => LATEPOINT_STATUS_SUCCESS,
80 + 'message' => __( 'Cart has already been converted to order', 'latepoint' )
81 + ] );
105 82 }
106 83 $order_intent = OsOrderIntentHelper::create_or_update_order_intent( OsStepsHelper::$cart_object, OsStepsHelper::$restrictions, OsStepsHelper::$presets, '', OsStepsHelper::get_customer_object_id() );
107 84 if ( $order_intent->is_bookable() ) {
108 - $this->send_json(
109 - [
110 - 'status' => LATEPOINT_STATUS_SUCCESS,
111 - 'message' => __( 'Order intent can be converted to order', 'latepoint' ),
112 - ]
113 - );
85 + $this->send_json( [
86 + 'status' => LATEPOINT_STATUS_SUCCESS,
87 + 'message' => __( 'Order intent can be converted to order', 'latepoint' )
88 + ] );
114 89 } else {
115 - $this->send_json(
116 - [
117 - 'status' => LATEPOINT_STATUS_ERROR,
118 - 'message' => __( 'Selected booking slot is not available anymore. Please pick a different time slot.', 'latepoint' ),
119 - ]
120 - );
90 + $this->send_json( [
91 + 'status' => LATEPOINT_STATUS_ERROR,
92 + 'message' => __( 'Selected booking slot is not available anymore. Please pick a different time slot.', 'latepoint' )
93 + ] );
121 94 }
122 95 }
123 96
124 - function generate_timeslots_for_day() {
97 + function generate_timeslots_for_day(){
125 98 OsStepsHelper::set_required_objects( $this->params );
126 99
127 100
128 101
129 - wp_send_json(
130 - [
131 - 'status' => LATEPOINT_STATUS_SUCCESS,
132 - 'message' => '',
133 - ]
134 - );
102 + wp_send_json( [ 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => '' ] );
135 103 }
136 104
137 105
138 106 function reload_booking_form_summary_panel() {
@@ -140,42 +108,33 @@
140 108 $this->vars['cart'] = OsStepsHelper::$cart_object;
141 109
142 110 if ( OsStepsHelper::is_ready_for_summary() ) {
143 111 $this->vars['current_step_code'] = $this->params['current_step_code'] ?? '';
144 - $this->vars['booking'] = OsStepsHelper::$booking_object;
112 + $this->vars['booking'] = OsStepsHelper::$booking_object;
145 113 $this->vars['customer'] = OsStepsHelper::get_customer_object();
146 - $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
114 + $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
147 115
148 116 if ( $this->get_return_format() == 'json' ) {
149 117 $response_html = $this->render( $this->views_folder . 'partials/_booking_form_summary_panel', 'none' );
150 - wp_send_json(
151 - [
152 - 'status' => LATEPOINT_STATUS_SUCCESS,
153 - 'message' => $response_html,
154 - ]
155 - );
118 + wp_send_json( [ 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => $response_html ] );
156 119 exit();
157 120 } else {
158 121 echo $this->render( $this->views_folder . 'partials/_booking_form_summary_panel', $this->get_layout() );
159 122 }
160 123 } else {
161 - wp_send_json(
162 - [
163 - 'status' => LATEPOINT_STATUS_SUCCESS,
164 - 'message' => '',
165 - ]
166 - );
124 + wp_send_json( [ 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => '' ] );
167 125 }
126 +
168 127 }
169 128
170 129
171 130 public function start_from_order_intent() {
172 - $order_intent = OsOrderIntentHelper::get_order_intent_by_intent_key( $this->params['order_intent_key'] );
131 + $order_intent = OsOrderIntentHelper::get_order_intent_by_intent_key($this->params['order_intent_key']);
173 132
174 - if ( ! $order_intent->is_new_record() ) {
133 + if ( !$order_intent->is_new_record() ) {
175 134 $step_codes_to_preload = [];
176 - $steps = OsStepsHelper::get_steps();
177 - OsStepsHelper::set_required_objects( $this->params );
135 + $steps = OsStepsHelper::get_steps();
136 + OsStepsHelper::set_required_objects($this->params);
178 137
179 138 if ( $order_intent->order_id ) {
180 139 // if order is created - load it
181 140 OsStepsHelper::load_order_object( $order_intent->order_id );
@@ -207,9 +166,9 @@
207 166 $this->vars['step_codes_to_preload'] = $step_codes_to_preload;
208 167
209 168 }
210 169
211 - $this->vars['cart'] = OsStepsHelper::$cart_object;
170 + $this->vars['cart'] = OsStepsHelper::$cart_object;
212 171 $this->vars['show_next_btn'] = OsStepsHelper::can_step_show_next_btn( $current_step_code );
213 172 $this->vars['show_prev_btn'] = OsStepsHelper::can_step_show_prev_btn( $current_step_code );
214 173 $this->vars['all_steps'] = OsStepsHelper::get_steps( true );
215 174 $this->vars['steps'] = $steps;
@@ -214,15 +173,15 @@
214 173 $this->vars['all_steps'] = OsStepsHelper::get_steps( true );
215 174 $this->vars['steps'] = $steps;
216 175 $this->vars['current_step'] = $current_step;
217 176
218 - $this->vars['current_step_code'] = $current_step_code;
219 - $this->vars['booking'] = OsStepsHelper::$booking_object;
220 - $this->vars['customer'] = OsStepsHelper::get_customer_object();
221 - $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
222 - $this->vars['restrictions'] = OsStepsHelper::$restrictions;
223 - $this->vars['presets'] = OsStepsHelper::$presets;
224 - $this->vars['booking_element_type'] = 'lightbox';
177 + $this->vars['current_step_code'] = $current_step_code;
178 + $this->vars['booking'] = OsStepsHelper::$booking_object;
179 + $this->vars['customer'] = OsStepsHelper::get_customer_object();
180 + $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
181 + $this->vars['restrictions'] = OsStepsHelper::$restrictions;
182 + $this->vars['presets'] = OsStepsHelper::$presets;
183 + $this->vars['booking_element_type'] = 'lightbox';
225 184 $this->vars['booking_element_styles'] = [];
226 185
227 186
228 187
@@ -231,15 +190,14 @@
231 190 $this->set_layout( 'none' );
232 191
233 192 $this->format_render( 'start', array(), array( 'lightbox_class' => '' ) );
234 193 } else {
235 - $this->send_json(
236 - array(
237 - 'status' => LATEPOINT_STATUS_ERROR,
238 - 'message' => __( 'Invalid order intent key', 'latepoint' ),
239 - )
240 - );
194 + $this->send_json( array(
195 + 'status' => LATEPOINT_STATUS_ERROR,
196 + 'message' => __( 'Invalid order intent key', 'latepoint' )
197 + ) );
241 198 }
199 +
242 200 }
243 201
244 202 public function start( array $custom_restrictions = [], array $custom_presets = [], array $booking_element_styles = [], bool $output = true, string $booking_element_type = 'lightbox' ) {
245 203 $merged_params = $this->params;
@@ -249,27 +207,25 @@
249 207 }
250 208 if ( ! empty( $custom_presets ) ) {
251 209 $merged_params['presets'] = $custom_presets;
252 210 }
253 - if ( ! empty( $this->params['booking_element_type'] ) ) {
211 + if( ! empty( $this->params['booking_element_type'] ) ) {
254 212 $booking_element_type = $this->params['booking_element_type'];
255 213 }
256 214
257 215
258 - if ( ! empty( $merged_params['booking_element_styles'] ) ) {
216 + if(!empty($merged_params['booking_element_styles'])){
259 217 $booking_element_styles = array_merge( $booking_element_styles, $merged_params['booking_element_styles'] );
260 218 }
261 219
262 220 // set early to check if it's converted or should be emptied
263 221 OsStepsHelper::set_cart_object();
264 - if ( ! empty( OsStepsHelper::$cart_object->order_id ) ) {
222 + if(!empty(OsStepsHelper::$cart_object->order_id)){
265 223 OsCartsHelper::reset_cart();
266 224 OsStepsHelper::set_cart_object();
267 225 }
268 226 // clear cart if "shopping cart" feature is not enabled
269 - if ( ! OsCartsHelper::can_checkout_multiple_items() ) {
270 - OsStepsHelper::$cart_object->clear();
271 - }
227 + if ( ! OsCartsHelper::can_checkout_multiple_items() ) OsStepsHelper::$cart_object->clear();
272 228
273 229
274 230
275 231
@@ -276,9 +232,9 @@
276 232 OsStepsHelper::set_required_objects( $merged_params );
277 233
278 234 $steps = OsStepsHelper::get_steps();
279 235
280 - $current_step_code = OsStepsHelper::get_step_codes_in_order()[0];
236 + $current_step_code = OsStepsHelper::get_step_codes_in_order()[0];
281 237
282 238 if ( OsStepsHelper::should_step_be_skipped( $current_step_code ) ) {
283 239 $current_step_code = OsStepsHelper::get_next_step_code( $current_step_code );
284 240 }
@@ -283,12 +239,12 @@
283 239 $current_step_code = OsStepsHelper::get_next_step_code( $current_step_code );
284 240 }
285 241 // 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
286 242 $ready_to_add_to_cart = true;
287 - if ( OsStepsHelper::$active_cart_item->is_booking() ) {
288 - foreach ( $steps as $step_code => $step_object ) {
289 - $step_main_parent_code = explode( '__', $step_code );
290 - if ( ! empty( $step_main_parent_code[0] ) && $step_main_parent_code[0] == 'booking' ) {
243 + if(OsStepsHelper::$active_cart_item->is_booking()){
244 + foreach($steps as $step_code => $step_object) {
245 + $step_main_parent_code = explode('__', $step_code);
246 + if(!empty($step_main_parent_code[0]) && $step_main_parent_code[0] == 'booking'){
291 247 $ready_to_add_to_cart = false;
292 248 break;
293 249 }
294 250 }
@@ -293,13 +249,13 @@
293 249 }
294 250 }
295 251 }
296 252 // 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
297 - if ( $ready_to_add_to_cart ) {
298 - try {
253 + if($ready_to_add_to_cart){
254 + try{
299 255 OsStepsHelper::add_current_item_to_cart();
300 - } catch ( Exception $e ) {
301 - $this->vars['booking'] = OsStepsHelper::$booking_object;
256 + }catch(Exception $e){
257 + $this->vars['booking'] = OsStepsHelper::$booking_object;
302 258 if ( $output ) {
303 259 $this->format_render( 'preset_slot_not_available' );
304 260 return false;
305 261 } else {
@@ -308,9 +264,9 @@
308 264 }
309 265 }
310 266 $current_step = $steps[ $current_step_code ];
311 267
312 - $this->vars['cart'] = OsStepsHelper::$cart_object;
268 + $this->vars['cart'] = OsStepsHelper::$cart_object;
313 269 $this->vars['show_next_btn'] = OsStepsHelper::can_step_show_next_btn( $current_step->code );
314 270 $this->vars['show_prev_btn'] = OsStepsHelper::can_step_show_prev_btn( $current_step->code );
315 271 $this->vars['all_steps'] = OsStepsHelper::get_steps( true );
316 272 $this->vars['steps'] = $steps;
@@ -315,17 +271,17 @@
315 271 $this->vars['all_steps'] = OsStepsHelper::get_steps( true );
316 272 $this->vars['steps'] = $steps;
317 273 $this->vars['current_step'] = $current_step;
318 274
319 - $this->vars['current_step_code'] = $current_step->code;
320 - $this->vars['booking'] = OsStepsHelper::$booking_object;
321 - $this->vars['customer'] = OsStepsHelper::get_customer_object();
322 - $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
323 - $this->vars['restrictions'] = OsStepsHelper::$restrictions;
324 - $this->vars['presets'] = OsStepsHelper::$presets;
325 - $this->vars['booking_element_type'] = $booking_element_type;
275 + $this->vars['current_step_code'] = $current_step->code;
276 + $this->vars['booking'] = OsStepsHelper::$booking_object;
277 + $this->vars['customer'] = OsStepsHelper::get_customer_object();
278 + $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
279 + $this->vars['restrictions'] = OsStepsHelper::$restrictions;
280 + $this->vars['presets'] = OsStepsHelper::$presets;
281 + $this->vars['booking_element_type'] = $booking_element_type;
326 282 $this->vars['booking_element_styles'] = $booking_element_styles;
327 - $this->vars['timezone_name'] = OsTimeHelper::get_timezone_name_from_session();
283 + $this->vars['timezone_name'] = OsTimeHelper::get_timezone_name_from_session();
328 284
329 285 $this->set_layout( 'none' );
330 286
331 287
@@ -368,11 +324,8 @@
368 324 $step_code_to_load = OsStepsHelper::get_prev_step_code( $current_step_code );
369 325 break;
370 326 case 'specific':
371 327 $step_code_to_load = OsStepsHelper::should_step_be_skipped( $current_step_code ) ? OsStepsHelper::get_next_step_code( $current_step_code ) : $current_step_code;
372 - if ( $step_code_to_load && OsSettingsHelper::is_on( 'reset_presets_when_adding_new_item' ) ) {
373 - $step_code_to_load = OsStepsHelper::check_booking_step_access( $step_code_to_load );
374 - }
375 328 break;
376 329 }
377 330 if ( $step_code_to_load ) {
378 331
@@ -389,8 +342,10 @@
389 342 */
390 343 do_action( 'latepoint_load_step', $step_code_to_load, 'json', $this->params );
391 344 }
392 345 }
346 +
347 +
393 348 }
394 349
395 350
396 351 endif;