| @@ -1,83 +1,83 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Manage onboarding | |
| 4 | - * | |
| 5 | - * @package Booktics/Onboard | |
| 6 | - */ | |
| 7 | - | |
| 8 | -namespace Booktics\Onboard; | |
| 9 | - | |
| 10 | -use Booktics\Services\Schedule_Manager; | |
| 11 | -use Booktics\Settings\Settings; | |
| 12 | -use WP_Error; | |
| 13 | - | |
| 14 | -/** | |
| 15 | - * Class Onboarding | |
| 16 | - */ | |
| 17 | -class Onboarding { | |
| 18 | - /** | |
| 19 | - * Store onboarding fields | |
| 20 | - * | |
| 21 | - * @var [] | |
| 22 | - */ | |
| 23 | - protected static $fields = array( | |
| 24 | - 'business_email' => '', | |
| 25 | - 'business_name' => '', | |
| 26 | - 'business_type' => '', | |
| 27 | - 'business_timezone' => '', | |
| 28 | - 'schedule' => '', | |
| 29 | - 'custom' => '', | |
| 30 | - 'holiday' => '', | |
| 31 | - 'onboard_setup' => '', | |
| 32 | - ); | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * Setup onboarding profile | |
| 36 | - * | |
| 37 | - * @param array $data Onboarding data | |
| 38 | - * | |
| 39 | - * @return bool | WP_Error | |
| 40 | - */ | |
| 41 | - public static function update( $data = array() ) { | |
| 42 | - if ( $data ) { | |
| 43 | - foreach ( $data as $key => $value ) { | |
| 44 | - if ( ! array_key_exists( $key, self::$fields ) ) { | |
| 45 | - return new WP_Error( | |
| 46 | - 'invalid_field', | |
| 47 | - // translators: %s is the name of the invalid field. | |
| 48 | - sprintf( __( 'Invalid field %s', 'booktics' ), $key ), | |
| 49 | - array( 'status' => 422 ) | |
| 50 | - ); | |
| 51 | - } | |
| 52 | - } | |
| 53 | - } | |
| 54 | - | |
| 55 | - if ( isset( $data['schedule'] ) || isset( $data['custom'] ) || isset( $data['holiday'] ) ) { | |
| 56 | - $schedule_manager = Schedule_Manager::make( $data ); | |
| 57 | - $schedule_manager->save(); | |
| 58 | - unset( $data['schedule'], $data['custom'], $data['holiday'] ); | |
| 59 | - } | |
| 60 | - | |
| 61 | - return Settings::update( $data ); | |
| 62 | - } | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * Get onboard field | |
| 66 | - * | |
| 67 | - * @param string $key Onboarding field | |
| 68 | - * | |
| 69 | - * @return mixed | |
| 70 | - */ | |
| 71 | - public static function get( $key ) { | |
| 72 | - if ( ! array_key_exists( $key, self::$fields ) ) { | |
| 73 | - return new WP_Error( | |
| 74 | - 'invalid_field', | |
| 75 | - // translators: %s is the name of the invalid field. | |
| 76 | - sprintf( __( 'Invalid field %s', 'booktics' ), $key ), | |
| 77 | - array( 'status' => 422 ) | |
| 78 | - ); | |
| 79 | - } | |
| 80 | - | |
| 81 | - return Settings::get( $key ); | |
| 82 | - } | |
| 83 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Manage onboarding | |
| 4 | + * | |
| 5 | + * @package Booktics/Onboard | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace Booktics\Onboard; | |
| 9 | + | |
| 10 | +use Booktics\Services\Schedule_Manager; | |
| 11 | +use Booktics\Settings\Settings; | |
| 12 | +use WP_Error; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Class Onboarding | |
| 16 | + */ | |
| 17 | +class Onboarding { | |
| 18 | + /** | |
| 19 | + * Store onboarding fields | |
| 20 | + * | |
| 21 | + * @var [] | |
| 22 | + */ | |
| 23 | + protected static $fields = array( | |
| 24 | + 'business_email' => '', | |
| 25 | + 'business_name' => '', | |
| 26 | + 'business_type' => '', | |
| 27 | + 'business_timezone' => '', | |
| 28 | + 'schedule' => '', | |
| 29 | + 'custom' => '', | |
| 30 | + 'holiday' => '', | |
| 31 | + 'onboard_setup' => '', | |
| 32 | + ); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Setup onboarding profile | |
| 36 | + * | |
| 37 | + * @param array $data Onboarding data | |
| 38 | + * | |
| 39 | + * @return bool | WP_Error | |
| 40 | + */ | |
| 41 | + public static function update( $data = array() ) { | |
| 42 | + if ( $data ) { | |
| 43 | + foreach ( $data as $key => $value ) { | |
| 44 | + if ( ! array_key_exists( $key, self::$fields ) ) { | |
| 45 | + return new WP_Error( | |
| 46 | + 'invalid_field', | |
| 47 | + // translators: %s is the name of the invalid field. | |
| 48 | + sprintf( __( 'Invalid field %s', 'booktics' ), $key ), | |
| 49 | + array( 'status' => 422 ) | |
| 50 | + ); | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + | |
| 55 | + if ( isset( $data['schedule'] ) || isset( $data['custom'] ) || isset( $data['holiday'] ) ) { | |
| 56 | + $schedule_manager = Schedule_Manager::make( $data ); | |
| 57 | + $schedule_manager->save(); | |
| 58 | + unset( $data['schedule'], $data['custom'], $data['holiday'] ); | |
| 59 | + } | |
| 60 | + | |
| 61 | + return Settings::update( $data ); | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Get onboard field | |
| 66 | + * | |
| 67 | + * @param string $key Onboarding field | |
| 68 | + * | |
| 69 | + * @return mixed | |
| 70 | + */ | |
| 71 | + public static function get( $key ) { | |
| 72 | + if ( ! array_key_exists( $key, self::$fields ) ) { | |
| 73 | + return new WP_Error( | |
| 74 | + 'invalid_field', | |
| 75 | + // translators: %s is the name of the invalid field. | |
| 76 | + sprintf( __( 'Invalid field %s', 'booktics' ), $key ), | |
| 77 | + array( 'status' => 422 ) | |
| 78 | + ); | |
| 79 | + } | |
| 80 | + | |
| 81 | + return Settings::get( $key ); | |
| 82 | + } | |
| 83 | +} | |