|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace NewfoldLabs\WP\Module\Onboarding\Services; |
| 4 | + |
| 5 | +use NewfoldLabs\WP\Module\Onboarding\Data\Services\FlowService; |
| 6 | + |
| 7 | +/** |
| 8 | + * Service for handling onboarding site information persistence and retrieval. |
| 9 | + */ |
| 10 | +class SiteInfoService { |
| 11 | + |
| 12 | + /** |
| 13 | + * Database option name for storing onboarding site information. |
| 14 | + */ |
| 15 | + const SITE_INFO_OPTION = 'nfd_module_onboarding_site_info'; |
| 16 | + |
| 17 | + /** |
| 18 | + * Save onboarding site information to database option for other modules to access. |
| 19 | + * |
| 20 | + * @return void |
| 21 | + */ |
| 22 | + public static function save_site_info(): void { |
| 23 | + $site_info = array(); |
| 24 | + |
| 25 | + // Get experience level from FlowService |
| 26 | + $experience_level = FlowService::get_experience_level(); |
| 27 | + $site_info['experience_level'] = $experience_level; |
| 28 | + |
| 29 | + // Get site type from flow data |
| 30 | + $flow_data = FlowService::read_data_from_wp_option( false ); |
| 31 | + if ( $flow_data && isset( $flow_data['data']['siteType']['primary']['value'] ) ) { |
| 32 | + $site_info['site_type'] = $flow_data['data']['siteType']['primary']['value']; |
| 33 | + } else { |
| 34 | + // Fallback to default site type |
| 35 | + $site_info['site_type'] = 'business'; |
| 36 | + } |
| 37 | + |
| 38 | + // Save to database option |
| 39 | + update_option( self::SITE_INFO_OPTION, $site_info ); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Get the stored onboarding site information. |
| 44 | + * |
| 45 | + * @return array |
| 46 | + */ |
| 47 | + public static function get_site_info(): array { |
| 48 | + return get_option( self::SITE_INFO_OPTION, array() ); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Delete the stored onboarding site information. |
| 53 | + * |
| 54 | + * @return bool |
| 55 | + */ |
| 56 | + public static function delete_site_info(): bool { |
| 57 | + return delete_option( self::SITE_INFO_OPTION ); |
| 58 | + } |
| 59 | +} |
0 commit comments