PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / trunk
LatePoint – Calendar Booking Plugin for Appointments and Events vtrunk
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 12 hours ago calendars_controller.php 3 months ago carts_controller.php 12 hours ago controller.php 3 months ago customer_cabinet_controller.php 2 months ago customers_controller.php 12 hours ago dashboard_controller.php 2 months ago default_agent_controller.php 3 months ago events_controller.php 3 months ago form_fields_controller.php 1 week ago integrations_controller.php 3 months ago invoices_controller.php 12 hours 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 12 hours ago pro_controller.php 2 weeks ago process_jobs_controller.php 3 months ago processes_controller.php 1 month ago razorpay_connect_controller.php 1 week ago search_controller.php 3 months ago services_controller.php 3 months ago settings_controller.php 2 months ago steps_controller.php 2 weeks ago stripe_connect_controller.php 1 week ago support_topics_controller.php 3 months ago todos_controller.php 3 months ago transactions_controller.php 12 hours ago wizard_controller.php 1 week ago
wizard_controller.php
457 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->check_nonce( 'wizard_step' );
135 $this->show_prev_btn = true;
136 $this->show_next_btn = true;
137
138 // Check if a valid step_code name
139 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
140 $current_step_code = $this->params['current_step_code'];
141 } else {
142 $current_step_code = $this->steps_in_order[0];
143 }
144
145
146 $process_step_function_name = 'process_step_' . $current_step_code;
147 self::$process_step_function_name();
148
149 $new_current_step_code = $this->steps_in_order[ array_search( $current_step_code, $this->steps_in_order ) + 1 ];
150
151 // Wizard step completed.
152 $this->on_step_completed( $current_step_code, $new_current_step_code );
153
154 // Wizard is complete.
155 if ( 'complete' === $new_current_step_code ) {
156 do_action( 'latepoint_onboarding_completed' );
157 }
158
159 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
160 $this->show_prev_btn = false;
161 }
162
163 $step_function_name = 'step_' . $new_current_step_code;
164 self::$step_function_name();
165
166 $this->vars['current_step_code'] = $new_current_step_code;
167 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
168 $this->format_render(
169 'steps/_' . $new_current_step_code,
170 array(),
171 array(
172 'step_code' => $new_current_step_code,
173 'show_prev_btn' => $this->show_prev_btn,
174 'show_next_btn' => $this->show_next_btn,
175 )
176 );
177 }
178
179 function prev_step() {
180 $this->check_nonce( 'wizard_step' );
181
182 // For every back step there is next step.
183 $this->show_next_btn = true;
184
185 // Check if a valid step_code name.
186 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
187 $current_step_code = $this->params['current_step_code'];
188 } else {
189 $current_step_code = $this->steps_in_order[0];
190 }
191
192 $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];
193 $this->show_prev_btn = array_search( $new_current_step_code, $this->steps_in_order ) > 0;
194
195 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
196 $this->show_prev_btn = false;
197 }
198
199 $step_function_name = 'step_' . $new_current_step_code;
200 self::$step_function_name();
201
202 $this->vars['current_step_code'] = $new_current_step_code;
203 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
204 $this->format_render(
205 'steps/_' . $new_current_step_code,
206 array(),
207 array(
208 'step_code' => $new_current_step_code,
209 'show_prev_btn' => $this->show_prev_btn,
210 'show_next_btn' => $this->show_next_btn,
211 )
212 );
213 }
214
215 function load_step() {
216 // Check if a valid step_code name
217 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
218 $current_step_code = $this->params['current_step_code'];
219 } else {
220 $current_step_code = $this->steps_in_order[0];
221 }
222
223 $step_function_name = 'step_' . $current_step_code;
224 self::$step_function_name();
225
226 $this->vars['current_step_code'] = $current_step_code;
227 $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order );
228 $this->format_render( 'steps/_' . $current_step_code, array(), array( 'step_code' => $current_step_code ) );
229 }
230
231 function add_or_edit_agent() {
232 $agents = new OsAgentModel();
233 $this->vars['agents'] = $agents->get_results_as_models();
234
235 $agent = new OsAgentModel();
236 if ( ! empty( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
237 $agent->load_by_id( $this->params['id'] );
238 }
239 $this->vars['agent'] = $agent;
240 $this->format_render( 'steps/_form_agent', array(), array() );
241 }
242
243 function add_or_edit_service() {
244 $services = new OsServiceModel();
245 $this->vars['services'] = $services->get_results_as_models();
246
247 $service = new OsServiceModel();
248 if ( isset( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
249 $service->load_by_id( $this->params['id'] );
250 }
251 $agents = new OsAgentModel();
252 $service_categories = new OsServiceCategoryModel();
253
254 $this->vars['service_categories_for_select'] = $service_categories->index_for_select();
255 $this->vars['agents'] = $agents->get_results_as_models();
256 $this->vars['location'] = OsLocationHelper::get_default_location();
257
258 $this->vars['service'] = $service;
259 $this->format_render( 'steps/_form_service', array(), array() );
260 }
261
262
263 function step_services() {
264 $services = new OsServiceModel();
265 $services = $services->get_results_as_models();
266 $this->show_prev_btn = false;
267 $this->vars['services'] = $services;
268 $this->vars['location'] = OsLocationHelper::get_default_location();
269 $agents = new OsAgentModel();
270 $this->vars['agents'] = $agents->get_results_as_models();
271 if ( ! $services ) {
272 $service = new OsServiceModel();
273 $this->vars['service'] = $service;
274 $this->show_next_btn = false;
275 } else {
276 $this->show_next_btn = true;
277 $this->show_prev_btn = true;
278 }
279 }
280
281 function step_agents() {
282 $agents = new OsAgentModel();
283 $agents = $agents->get_results_as_models();
284 $this->vars['agents'] = $agents;
285 $this->show_prev_btn = false;
286 if ( ! $agents ) {
287 $agent = new OsAgentModel();
288 $this->vars['agent'] = $agent;
289 $this->show_next_btn = false;
290 } else {
291 $this->show_next_btn = true;
292 }
293 }
294
295
296 function step_default_agent() {
297
298 $this->vars['agent'] = OsAgentHelper::get_default_agent();
299 $this->show_next_btn = true;
300 }
301
302 function step_work_periods() {
303 $work_periods = OsWorkPeriodsHelper::get_work_periods( new \LatePoint\Misc\Filter() );
304 $working_periods_with_weekdays = array();
305 if ( $work_periods ) {
306 foreach ( $work_periods as $work_period ) {
307 $working_periods_with_weekdays[ 'day_' . $work_period->week_day ][] = $work_period;
308 }
309 }
310 $this->vars['working_periods_with_weekdays'] = $working_periods_with_weekdays;
311 }
312
313 function step_intro() {
314 $this->show_next_btn = true;
315 }
316
317
318 function step_settings() {
319 }
320
321 function step_personal_info() {
322 $current_user = wp_get_current_user();
323
324 $wizard_first_name = OsSettingsHelper::get_settings_value( 'wizard_first_name', '' );
325 $wizard_last_name = OsSettingsHelper::get_settings_value( 'wizard_last_name', '' );
326 $wizard_email = OsSettingsHelper::get_settings_value( 'wizard_email', '' );
327
328 if ( $current_user->exists() ) {
329 if ( empty( $wizard_first_name ) ) {
330 $wizard_first_name = $current_user->first_name;
331 }
332
333 if ( empty( $wizard_last_name ) ) {
334 $wizard_last_name = $current_user->last_name;
335 }
336
337 if ( empty( $wizard_email ) ) {
338 $wizard_email = $current_user->user_email;
339 }
340 }
341
342 $this->vars['wizard_first_name'] = $wizard_first_name;
343 $this->vars['wizard_last_name'] = $wizard_last_name;
344 $this->vars['wizard_email'] = $wizard_email;
345
346 $this->vars['wizard_email_optin'] = OsSettingsHelper::get_settings_value( 'wizard_email_optin', 'on' );
347 $this->show_next_btn = true;
348 }
349
350 function step_complete() {
351 $this->show_next_btn = false;
352 $this->show_prev_btn = false;
353 }
354
355
356 function process_step_agents() {
357 }
358
359 function process_step_services() {
360 }
361
362 function process_step_intro() {
363 }
364
365 function process_step_default_agent() {
366
367 $default_agent = OsAgentHelper::get_default_agent();
368 if ( ! $default_agent->is_new_record() ) {
369 $default_agent->set_data( $this->params['agent'] );
370 $default_agent->save();
371 }
372 }
373
374 function process_step_work_periods() {
375 $work_periods_form_data = $this->params['work_periods'];
376 OsWorkPeriodsHelper::save_work_periods( $work_periods_form_data );
377 }
378
379 function process_step_info() {
380 }
381
382 function process_step_personal_info() {
383 $first_name = isset( $this->params['personal_info']['first_name'] ) ? sanitize_text_field( $this->params['personal_info']['first_name'] ) : '';
384 $last_name = isset( $this->params['personal_info']['last_name'] ) ? sanitize_text_field( $this->params['personal_info']['last_name'] ) : '';
385 $email = isset( $this->params['personal_info']['email'] ) ? sanitize_email( $this->params['personal_info']['email'] ) : '';
386 $email_optin = isset( $this->params['personal_info']['email_optin'] ) && $this->params['personal_info']['email_optin'] === 'on' ? 'on' : 'off';
387
388 OsSettingsHelper::save_setting_by_name( 'wizard_first_name', $first_name );
389 OsSettingsHelper::save_setting_by_name( 'wizard_last_name', $last_name );
390 OsSettingsHelper::save_setting_by_name( 'wizard_email', $email );
391 OsSettingsHelper::save_setting_by_name( 'wizard_email_optin', $email_optin );
392
393 if ( $email_optin === 'on' ) {
394 update_option( 'latepoint_usage_optin', 'yes' );
395
396 $this->send_registration_data( $first_name, $last_name, $email, $email_optin );
397 }
398 }
399
400 function skip_setup() {
401 $this->check_nonce( 'wizard_step' );
402 $current_step = isset( $this->params['current_step_code'] ) ? sanitize_text_field( $this->params['current_step_code'] ) : 'unknown';
403
404 $analytics = get_option( 'latepoint_onboarding_analytics', [] );
405 $analytics['exited_early'] = true;
406 $analytics['current_step'] = $current_step;
407 update_option( 'latepoint_onboarding_analytics', $analytics );
408
409 do_action( 'latepoint_onboarding_skipped', $current_step );
410
411 if ( $this->get_return_format() === 'json' ) {
412 $this->send_json(
413 [
414 'status' => LATEPOINT_STATUS_SUCCESS,
415 'redirect' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'dashboard', 'index' ) ),
416 ]
417 );
418 }
419 }
420
421 private function on_step_completed( $step_code, $new_current_step ) {
422 // Save step completion to structured option.
423 $analytics = get_option( 'latepoint_onboarding_analytics', [] );
424 if ( ! isset( $analytics['completed_steps'] ) || ! is_array( $analytics['completed_steps'] ) ) {
425 $analytics['completed_steps'] = [];
426 }
427 if ( ! in_array( $step_code, $analytics['completed_steps'], true ) ) {
428 $analytics['completed_steps'][] = $step_code;
429 }
430 $analytics['current_step'] = $new_current_step;
431
432 update_option( 'latepoint_onboarding_analytics', $analytics );
433 }
434
435 private function send_registration_data( $first_name, $last_name, $email, $email_optin ) {
436 $subscribe_api_url = LATEPOINT_APP_CONNECT_URL . '/api/wp/v1/subscribe';
437
438 wp_remote_post(
439 $subscribe_api_url,
440 array(
441 'body' => array(
442 'first_name' => $first_name,
443 'last_name' => $last_name,
444 'email' => $email,
445 'optin' => $email_optin,
446 'site_url' => get_site_url(),
447 ),
448 'timeout' => 30,
449 'blocking' => false,
450 )
451 );
452 }
453 }
454
455
456 endif;
457