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 / wizard_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
wizard_controller.php
454 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 if ( ! class_exists( 'OsWizardController' ) ) :
8
9
10 class OsWizardController extends OsController {
11
12 var $steps_info, $steps_in_order;
13
14 protected $show_next_btn = false,
15 $show_prev_btn = false;
16
17
18 function __construct() {
19 parent::__construct();
20
21 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'wizard/';
22 $this->vars['page_header'] = __( 'Wizard', 'latepoint' );
23
24 $this->set_layout( 'wizard' );
25 $this->steps_info = array(
26 'default_agent' => array(
27 'show_in_sidemenu' => true,
28 'name' => __( 'Setup Notifications', 'latepoint' ),
29 ),
30 'agents' => array(
31 'show_in_sidemenu' => true,
32 'name' => __( 'Create Agents', 'latepoint' ),
33 ),
34 'intro' => array(
35 'show_in_sidemenu' => false,
36 'name' => __( 'Intro', 'latepoint' ),
37 ),
38 'services' => array(
39 'show_in_sidemenu' => true,
40 'name' => __( 'Add Services', 'latepoint' ),
41 ),
42 'work_periods' => array(
43 'show_in_sidemenu' => true,
44 'name' => __( 'Set Working Hours', 'latepoint' ),
45 ),
46 'info' => array(
47 'show_in_sidemenu' => true,
48 'name' => __( 'Fill Business Info', 'latepoint' ),
49 ),
50 'complete' => array(
51 'show_in_sidemenu' => true,
52 'name' => __( 'Setup Complete', 'latepoint' ),
53 ),
54 'personal_info' => array(
55 'show_in_sidemenu' => true,
56 'name' => __( 'Personal Info', 'latepoint' ),
57 ),
58 );
59 $this->steps_in_order = array( 'intro', 'default_agent', 'services', 'work_periods', 'personal_info', 'complete' );
60
61 $this->vars['steps_in_order'] = $this->steps_in_order;
62 $this->vars['steps_info'] = $this->steps_info;
63 }
64
65 function save_service() {
66 $this->check_nonce( 'save_service' );
67 $service = new OsServiceModel();
68 $service->set_data( $this->params['service'] );
69
70 if ( $service->save() && $service->save_agents_and_locations( $this->params['service']['agents'] ) ) {
71 $this->vars['current_step_code'] = 'agents';
72 $this->step_services();
73 $response_html = $this->render( $this->get_view_uri( 'steps/_list_services' ) );
74 $status = LATEPOINT_STATUS_SUCCESS;
75 } else {
76 $response_html = $service->get_error_messages();
77 $status = LATEPOINT_STATUS_ERROR;
78 }
79 if ( $this->get_return_format() == 'json' ) {
80 $this->send_json(
81 array(
82 'status' => $status,
83 'message' => $response_html,
84 'show_prev_btn' => true,
85 'show_next_btn' => $this->show_next_btn,
86 )
87 );
88 }
89 }
90
91 function save_agent() {
92 $this->check_nonce( 'save_agent' );
93 $agent = new OsAgentModel();
94 $agent->set_data( $this->params['agent'] );
95 if ( $agent->save() ) {
96 $this->vars['current_step_code'] = 'agents';
97 $this->step_agents();
98 $response_html = $this->render( $this->get_view_uri( 'steps/_list_agents' ) );
99 $status = LATEPOINT_STATUS_SUCCESS;
100 } else {
101 $response_html = $agent->get_error_messages();
102 $status = LATEPOINT_STATUS_ERROR;
103 }
104 if ( $this->get_return_format() == 'json' ) {
105 $this->send_json(
106 array(
107 'status' => $status,
108 'message' => $response_html,
109 'show_prev_btn' => $this->show_prev_btn,
110 'show_next_btn' => $this->show_next_btn,
111 )
112 );
113 }
114 }
115
116
117 function setup() {
118 $current_step_code = $this->steps_in_order[0];
119 $step_function_name = 'step_' . $current_step_code;
120 self::$step_function_name();
121
122 add_option( 'latepoint_wizard_visited', true );
123
124 do_action( 'latepoint_onboarding_started' );
125
126 $this->vars['current_step_code'] = $current_step_code;
127 $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order );
128 $this->vars['step_file_to_include'] = 'steps/_' . $current_step_code . '.php';
129
130 $this->format_render( __FUNCTION__ );
131 }
132
133 function next_step() {
134 $this->show_prev_btn = true;
135 $this->show_next_btn = true;
136
137 // Check if a valid step_code name
138 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
139 $current_step_code = $this->params['current_step_code'];
140 } else {
141 $current_step_code = $this->steps_in_order[0];
142 }
143
144
145 $process_step_function_name = 'process_step_' . $current_step_code;
146 self::$process_step_function_name();
147
148 $new_current_step_code = $this->steps_in_order[ array_search( $current_step_code, $this->steps_in_order ) + 1 ];
149
150 // Wizard step completed.
151 $this->on_step_completed( $current_step_code, $new_current_step_code );
152
153 // Wizard is complete.
154 if ( 'complete' === $new_current_step_code ) {
155 do_action( 'latepoint_onboarding_completed' );
156 }
157
158 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
159 $this->show_prev_btn = false;
160 }
161
162 $step_function_name = 'step_' . $new_current_step_code;
163 self::$step_function_name();
164
165 $this->vars['current_step_code'] = $new_current_step_code;
166 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
167 $this->format_render(
168 'steps/_' . $new_current_step_code,
169 array(),
170 array(
171 'step_code' => $new_current_step_code,
172 'show_prev_btn' => $this->show_prev_btn,
173 'show_next_btn' => $this->show_next_btn,
174 )
175 );
176 }
177
178 function prev_step() {
179
180 // For every back step there is next step.
181 $this->show_next_btn = true;
182
183 // Check if a valid step_code name.
184 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
185 $current_step_code = $this->params['current_step_code'];
186 } else {
187 $current_step_code = $this->steps_in_order[0];
188 }
189
190 $new_current_step_code = ( array_search( $current_step_code, $this->steps_in_order ) > 0 ) ? $this->steps_in_order[ array_search( $current_step_code, $this->steps_in_order ) - 1 ] : $this->steps_in_order[0];
191 $this->show_prev_btn = array_search( $new_current_step_code, $this->steps_in_order ) > 0;
192
193 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
194 $this->show_prev_btn = false;
195 }
196
197 $step_function_name = 'step_' . $new_current_step_code;
198 self::$step_function_name();
199
200 $this->vars['current_step_code'] = $new_current_step_code;
201 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
202 $this->format_render(
203 'steps/_' . $new_current_step_code,
204 array(),
205 array(
206 'step_code' => $new_current_step_code,
207 'show_prev_btn' => $this->show_prev_btn,
208 'show_next_btn' => $this->show_next_btn,
209 )
210 );
211 }
212
213 function load_step() {
214 // Check if a valid step_code name
215 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
216 $current_step_code = $this->params['current_step_code'];
217 } else {
218 $current_step_code = $this->steps_in_order[0];
219 }
220
221 $step_function_name = 'step_' . $current_step_code;
222 self::$step_function_name();
223
224 $this->vars['current_step_code'] = $current_step_code;
225 $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order );
226 $this->format_render( 'steps/_' . $current_step_code, array(), array( 'step_code' => $current_step_code ) );
227 }
228
229 function add_or_edit_agent() {
230 $agents = new OsAgentModel();
231 $this->vars['agents'] = $agents->get_results_as_models();
232
233 $agent = new OsAgentModel();
234 if ( ! empty( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
235 $agent->load_by_id( $this->params['id'] );
236 }
237 $this->vars['agent'] = $agent;
238 $this->format_render( 'steps/_form_agent', array(), array() );
239 }
240
241 function add_or_edit_service() {
242 $services = new OsServiceModel();
243 $this->vars['services'] = $services->get_results_as_models();
244
245 $service = new OsServiceModel();
246 if ( isset( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
247 $service->load_by_id( $this->params['id'] );
248 }
249 $agents = new OsAgentModel();
250 $service_categories = new OsServiceCategoryModel();
251
252 $this->vars['service_categories_for_select'] = $service_categories->index_for_select();
253 $this->vars['agents'] = $agents->get_results_as_models();
254 $this->vars['location'] = OsLocationHelper::get_default_location();
255
256 $this->vars['service'] = $service;
257 $this->format_render( 'steps/_form_service', array(), array() );
258 }
259
260
261 function step_services() {
262 $services = new OsServiceModel();
263 $services = $services->get_results_as_models();
264 $this->show_prev_btn = false;
265 $this->vars['services'] = $services;
266 $this->vars['location'] = OsLocationHelper::get_default_location();
267 $agents = new OsAgentModel();
268 $this->vars['agents'] = $agents->get_results_as_models();
269 if ( ! $services ) {
270 $service = new OsServiceModel();
271 $this->vars['service'] = $service;
272 $this->show_next_btn = false;
273 } else {
274 $this->show_next_btn = true;
275 $this->show_prev_btn = true;
276 }
277 }
278
279 function step_agents() {
280 $agents = new OsAgentModel();
281 $agents = $agents->get_results_as_models();
282 $this->vars['agents'] = $agents;
283 $this->show_prev_btn = false;
284 if ( ! $agents ) {
285 $agent = new OsAgentModel();
286 $this->vars['agent'] = $agent;
287 $this->show_next_btn = false;
288 } else {
289 $this->show_next_btn = true;
290 }
291 }
292
293
294 function step_default_agent() {
295
296 $this->vars['agent'] = OsAgentHelper::get_default_agent();
297 $this->show_next_btn = true;
298 }
299
300 function step_work_periods() {
301 $work_periods = OsWorkPeriodsHelper::get_work_periods( new \LatePoint\Misc\Filter() );
302 $working_periods_with_weekdays = array();
303 if ( $work_periods ) {
304 foreach ( $work_periods as $work_period ) {
305 $working_periods_with_weekdays[ 'day_' . $work_period->week_day ][] = $work_period;
306 }
307 }
308 $this->vars['working_periods_with_weekdays'] = $working_periods_with_weekdays;
309 }
310
311 function step_intro() {
312 $this->show_next_btn = true;
313 }
314
315
316 function step_settings() {
317 }
318
319 function step_personal_info() {
320 $current_user = wp_get_current_user();
321
322 $wizard_first_name = OsSettingsHelper::get_settings_value( 'wizard_first_name', '' );
323 $wizard_last_name = OsSettingsHelper::get_settings_value( 'wizard_last_name', '' );
324 $wizard_email = OsSettingsHelper::get_settings_value( 'wizard_email', '' );
325
326 if ( $current_user->exists() ) {
327 if ( empty( $wizard_first_name ) ) {
328 $wizard_first_name = $current_user->first_name;
329 }
330
331 if ( empty( $wizard_last_name ) ) {
332 $wizard_last_name = $current_user->last_name;
333 }
334
335 if ( empty( $wizard_email ) ) {
336 $wizard_email = $current_user->user_email;
337 }
338 }
339
340 $this->vars['wizard_first_name'] = $wizard_first_name;
341 $this->vars['wizard_last_name'] = $wizard_last_name;
342 $this->vars['wizard_email'] = $wizard_email;
343
344 $this->vars['wizard_email_optin'] = OsSettingsHelper::get_settings_value( 'wizard_email_optin', 'on' );
345 $this->show_next_btn = true;
346 }
347
348 function step_complete() {
349 $this->show_next_btn = false;
350 $this->show_prev_btn = false;
351 }
352
353
354 function process_step_agents() {
355 }
356
357 function process_step_services() {
358 }
359
360 function process_step_intro() {
361 }
362
363 function process_step_default_agent() {
364
365 $default_agent = OsAgentHelper::get_default_agent();
366 if ( ! $default_agent->is_new_record() ) {
367 $default_agent->set_data( $this->params['agent'] );
368 $default_agent->save();
369 }
370 }
371
372 function process_step_work_periods() {
373 $work_periods_form_data = $this->params['work_periods'];
374 OsWorkPeriodsHelper::save_work_periods( $work_periods_form_data );
375 }
376
377 function process_step_info() {
378 }
379
380 function process_step_personal_info() {
381 $first_name = isset( $this->params['personal_info']['first_name'] ) ? sanitize_text_field( $this->params['personal_info']['first_name'] ) : '';
382 $last_name = isset( $this->params['personal_info']['last_name'] ) ? sanitize_text_field( $this->params['personal_info']['last_name'] ) : '';
383 $email = isset( $this->params['personal_info']['email'] ) ? sanitize_email( $this->params['personal_info']['email'] ) : '';
384 $email_optin = isset( $this->params['personal_info']['email_optin'] ) && $this->params['personal_info']['email_optin'] === 'on' ? 'on' : 'off';
385
386 OsSettingsHelper::save_setting_by_name( 'wizard_first_name', $first_name );
387 OsSettingsHelper::save_setting_by_name( 'wizard_last_name', $last_name );
388 OsSettingsHelper::save_setting_by_name( 'wizard_email', $email );
389 OsSettingsHelper::save_setting_by_name( 'wizard_email_optin', $email_optin );
390
391 if ( $email_optin === 'on' ) {
392 update_option( 'latepoint_usage_optin', 'yes' );
393
394 $this->send_registration_data( $first_name, $last_name, $email, $email_optin );
395 }
396 }
397
398 function skip_setup() {
399 $current_step = isset( $this->params['current_step_code'] ) ? sanitize_text_field( $this->params['current_step_code'] ) : 'unknown';
400
401 $analytics = get_option( 'latepoint_onboarding_analytics', [] );
402 $analytics['exited_early'] = true;
403 $analytics['current_step'] = $current_step;
404 update_option( 'latepoint_onboarding_analytics', $analytics );
405
406 do_action( 'latepoint_onboarding_skipped', $current_step );
407
408 if ( $this->get_return_format() === 'json' ) {
409 $this->send_json(
410 [
411 'status' => LATEPOINT_STATUS_SUCCESS,
412 'redirect' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'dashboard', 'index' ) ),
413 ]
414 );
415 }
416 }
417
418 private function on_step_completed( $step_code, $new_current_step ) {
419 // Save step completion to structured option.
420 $analytics = get_option( 'latepoint_onboarding_analytics', [] );
421 if ( ! isset( $analytics['completed_steps'] ) || ! is_array( $analytics['completed_steps'] ) ) {
422 $analytics['completed_steps'] = [];
423 }
424 if ( ! in_array( $step_code, $analytics['completed_steps'], true ) ) {
425 $analytics['completed_steps'][] = $step_code;
426 }
427 $analytics['current_step'] = $new_current_step;
428
429 update_option( 'latepoint_onboarding_analytics', $analytics );
430 }
431
432 private function send_registration_data( $first_name, $last_name, $email, $email_optin ) {
433 $subscribe_api_url = LATEPOINT_APP_CONNECT_URL . '/api/wp/v1/subscribe';
434
435 wp_remote_post(
436 $subscribe_api_url,
437 array(
438 'body' => array(
439 'first_name' => $first_name,
440 'last_name' => $last_name,
441 'email' => $email,
442 'optin' => $email_optin,
443 'site_url' => get_site_url(),
444 ),
445 'timeout' => 30,
446 'blocking' => false,
447 )
448 );
449 }
450 }
451
452
453 endif;
454