| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | |
| 12 | 12 | var $steps_info, $steps_in_order; |
| 13 | 13 | |
| 14 | 14 | protected $show_next_btn = false, |
| 15 | - $show_prev_btn = false; | |
| 15 | + $show_prev_btn = false; | |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | function __construct() { |
| 19 | 19 | parent::__construct(); |
| @@ -24,40 +24,24 @@ | ||
| 24 | 24 | $this->set_layout( 'wizard' ); |
| 25 | 25 | $this->steps_info = array( |
| 26 | 26 | 'default_agent' => array( |
| 27 | 27 | 'show_in_sidemenu' => true, |
| 28 | - 'name' => __( 'Setup Notifications', 'latepoint' ), | |
| 28 | + 'name' => __( 'Setup Notifications', 'latepoint' ) | |
| 29 | 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 | - ), | |
| 30 | + 'agents' => array( 'show_in_sidemenu' => true, 'name' => __( 'Create Agents', 'latepoint' ) ), | |
| 31 | + 'intro' => array( 'show_in_sidemenu' => false, 'name' => __( 'Intro', 'latepoint' ) ), | |
| 32 | + 'services' => array( 'show_in_sidemenu' => true, 'name' => __( 'Add Services', 'latepoint' ) ), | |
| 42 | 33 | 'work_periods' => array( |
| 43 | 34 | 'show_in_sidemenu' => true, |
| 44 | - 'name' => __( 'Set Working Hours', 'latepoint' ), | |
| 35 | + 'name' => __( 'Set Working Hours', 'latepoint' ) | |
| 45 | 36 | ), |
| 46 | 37 | 'info' => array( |
| 47 | 38 | 'show_in_sidemenu' => true, |
| 48 | - 'name' => __( 'Fill Business Info', 'latepoint' ), | |
| 39 | + 'name' => __( 'Fill Business Info', 'latepoint' ) | |
| 49 | 40 | ), |
| 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 | - ), | |
| 41 | + 'complete' => array( 'show_in_sidemenu' => true, 'name' => __( 'Setup Complete', 'latepoint' ) ), | |
| 58 | 42 | ); |
| 59 | - $this->steps_in_order = array( 'intro', 'default_agent', 'services', 'work_periods', 'personal_info', 'complete' ); | |
| 43 | + $this->steps_in_order = array( 'intro', 'default_agent', 'services', 'work_periods', 'complete' ); | |
| 60 | 44 | |
| 61 | 45 | $this->vars['steps_in_order'] = $this->steps_in_order; |
| 62 | 46 | $this->vars['steps_info'] = $this->steps_info; |
| 63 | 47 | } |
| @@ -62,9 +46,8 @@ | ||
| 62 | 46 | $this->vars['steps_info'] = $this->steps_info; |
| 63 | 47 | } |
| 64 | 48 | |
| 65 | 49 | function save_service() { |
| 66 | - $this->check_nonce( 'save_service' ); | |
| 67 | 50 | $service = new OsServiceModel(); |
| 68 | 51 | $service->set_data( $this->params['service'] ); |
| 69 | 52 | |
| 70 | 53 | if ( $service->save() && $service->save_agents_and_locations( $this->params['service']['agents'] ) ) { |
| @@ -76,21 +59,17 @@ | ||
| 76 | 59 | $response_html = $service->get_error_messages(); |
| 77 | 60 | $status = LATEPOINT_STATUS_ERROR; |
| 78 | 61 | } |
| 79 | 62 | 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 | - ); | |
| 63 | + $this->send_json( array( 'status' => $status, | |
| 64 | + 'message' => $response_html, | |
| 65 | + 'show_prev_btn' => true, | |
| 66 | + 'show_next_btn' => $this->show_next_btn | |
| 67 | + ) ); | |
| 88 | 68 | } |
| 89 | 69 | } |
| 90 | 70 | |
| 91 | 71 | function save_agent() { |
| 92 | - $this->check_nonce( 'save_agent' ); | |
| 93 | 72 | $agent = new OsAgentModel(); |
| 94 | 73 | $agent->set_data( $this->params['agent'] ); |
| 95 | 74 | if ( $agent->save() ) { |
| 96 | 75 | $this->vars['current_step_code'] = 'agents'; |
| @@ -101,16 +80,13 @@ | ||
| 101 | 80 | $response_html = $agent->get_error_messages(); |
| 102 | 81 | $status = LATEPOINT_STATUS_ERROR; |
| 103 | 82 | } |
| 104 | 83 | 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 | - ); | |
| 84 | + $this->send_json( array( 'status' => $status, | |
| 85 | + 'message' => $response_html, | |
| 86 | + 'show_prev_btn' => $this->show_prev_btn, | |
| 87 | + 'show_next_btn' => $this->show_next_btn | |
| 88 | + ) ); | |
| 113 | 89 | } |
| 114 | 90 | } |
| 115 | 91 | |
| 116 | 92 | |
| @@ -120,10 +96,8 @@ | ||
| 120 | 96 | self::$step_function_name(); |
| 121 | 97 | |
| 122 | 98 | add_option( 'latepoint_wizard_visited', true ); |
| 123 | 99 | |
| 124 | - do_action( 'latepoint_onboarding_started' ); | |
| 125 | - | |
| 126 | 100 | $this->vars['current_step_code'] = $current_step_code; |
| 127 | 101 | $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order ); |
| 128 | 102 | $this->vars['step_file_to_include'] = 'steps/_' . $current_step_code . '.php'; |
| 129 | 103 | |
| @@ -145,17 +119,8 @@ | ||
| 145 | 119 | $process_step_function_name = 'process_step_' . $current_step_code; |
| 146 | 120 | self::$process_step_function_name(); |
| 147 | 121 | |
| 148 | 122 | $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 | 123 | if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) { |
| 159 | 124 | $this->show_prev_btn = false; |
| 160 | 125 | } |
| 161 | 126 | |
| @@ -163,25 +128,16 @@ | ||
| 163 | 128 | self::$step_function_name(); |
| 164 | 129 | |
| 165 | 130 | $this->vars['current_step_code'] = $new_current_step_code; |
| 166 | 131 | $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 | - ); | |
| 132 | + $this->format_render( 'steps/_' . $new_current_step_code, array(), array( 'step_code' => $new_current_step_code, | |
| 133 | + 'show_prev_btn' => $this->show_prev_btn, | |
| 134 | + 'show_next_btn' => $this->show_next_btn | |
| 135 | + ) ); | |
| 176 | 136 | } |
| 177 | 137 | |
| 178 | 138 | 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. | |
| 139 | + // Check if a valid step_code name | |
| 184 | 140 | if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) { |
| 185 | 141 | $current_step_code = $this->params['current_step_code']; |
| 186 | 142 | } else { |
| 187 | 143 | $current_step_code = $this->steps_in_order[0]; |
| @@ -198,17 +154,12 @@ | ||
| 198 | 154 | self::$step_function_name(); |
| 199 | 155 | |
| 200 | 156 | $this->vars['current_step_code'] = $new_current_step_code; |
| 201 | 157 | $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 | - ); | |
| 158 | + $this->format_render( 'steps/_' . $new_current_step_code, array(), array( 'step_code' => $new_current_step_code, | |
| 159 | + 'show_prev_btn' => $this->show_prev_btn, | |
| 160 | + 'show_next_btn' => $this->show_next_btn | |
| 161 | + ) ); | |
| 211 | 162 | } |
| 212 | 163 | |
| 213 | 164 | function load_step() { |
| 214 | 165 | // Check if a valid step_code name |
| @@ -263,10 +214,10 @@ | ||
| 263 | 214 | $services = $services->get_results_as_models(); |
| 264 | 215 | $this->show_prev_btn = false; |
| 265 | 216 | $this->vars['services'] = $services; |
| 266 | 217 | $this->vars['location'] = OsLocationHelper::get_default_location(); |
| 267 | - $agents = new OsAgentModel(); | |
| 268 | - $this->vars['agents'] = $agents->get_results_as_models(); | |
| 218 | + $agents = new OsAgentModel(); | |
| 219 | + $this->vars['agents'] = $agents->get_results_as_models(); | |
| 269 | 220 | if ( ! $services ) { |
| 270 | 221 | $service = new OsServiceModel(); |
| 271 | 222 | $this->vars['service'] = $service; |
| 272 | 223 | $this->show_next_btn = false; |
| @@ -290,13 +241,13 @@ | ||
| 290 | 241 | } |
| 291 | 242 | } |
| 292 | 243 | |
| 293 | 244 | |
| 294 | - function step_default_agent() { | |
| 245 | + function step_default_agent(){ | |
| 295 | 246 | |
| 296 | 247 | $this->vars['agent'] = OsAgentHelper::get_default_agent(); |
| 297 | 248 | $this->show_next_btn = true; |
| 298 | - } | |
| 249 | + } | |
| 299 | 250 | |
| 300 | 251 | function step_work_periods() { |
| 301 | 252 | $work_periods = OsWorkPeriodsHelper::get_work_periods( new \LatePoint\Misc\Filter() ); |
| 302 | 253 | $working_periods_with_weekdays = array(); |
| @@ -313,37 +264,9 @@ | ||
| 313 | 264 | } |
| 314 | 265 | |
| 315 | 266 | |
| 316 | 267 | function step_settings() { |
| 317 | - } | |
| 318 | 268 | |
| 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 | 269 | } |
| 347 | 270 | |
| 348 | 271 | function step_complete() { |
| 349 | 272 | $this->show_next_btn = false; |
| @@ -351,14 +274,17 @@ | ||
| 351 | 274 | } |
| 352 | 275 | |
| 353 | 276 | |
| 354 | 277 | function process_step_agents() { |
| 278 | + | |
| 355 | 279 | } |
| 356 | 280 | |
| 357 | 281 | function process_step_services() { |
| 282 | + | |
| 358 | 283 | } |
| 359 | 284 | |
| 360 | 285 | function process_step_intro() { |
| 286 | + | |
| 361 | 287 | } |
| 362 | 288 | |
| 363 | 289 | function process_step_default_agent() { |
| 364 | 290 | |
| @@ -366,8 +292,9 @@ | ||
| 366 | 292 | if ( ! $default_agent->is_new_record() ) { |
| 367 | 293 | $default_agent->set_data( $this->params['agent'] ); |
| 368 | 294 | $default_agent->save(); |
| 369 | 295 | } |
| 296 | + | |
| 370 | 297 | } |
| 371 | 298 | |
| 372 | 299 | function process_step_work_periods() { |
| 373 | 300 | $work_periods_form_data = $this->params['work_periods']; |
| @@ -374,80 +301,12 @@ | ||
| 374 | 301 | OsWorkPeriodsHelper::save_work_periods( $work_periods_form_data ); |
| 375 | 302 | } |
| 376 | 303 | |
| 377 | 304 | function process_step_info() { |
| 378 | - } | |
| 379 | 305 | |
| 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 | 306 | } |
| 397 | 307 | |
| 398 | - function skip_setup() { | |
| 399 | - $current_step = isset( $this->params['current_step_code'] ) ? sanitize_text_field( $this->params['current_step_code'] ) : 'unknown'; | |
| 400 | 308 | |
| 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 | 309 | } |
| 451 | 310 | |
| 452 | 311 | |
| 453 | 312 | endif; |