From d26569a8becfec3fe3c0ad61251cbd2951b810cb Mon Sep 17 00:00:00 2001 From: GotPPay Date: Tue, 11 Sep 2018 09:27:20 +0200 Subject: [PATCH] create user class and make use of it --- .../api/class-wiaas-rest-user-api.php | 21 +++------- .../user/class-wiaas-user-profile.php | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 backend/app/plugins/wiaas/includes/user/class-wiaas-user-profile.php diff --git a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-user-api.php b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-user-api.php index e7ee939..0ebfb24 100644 --- a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-user-api.php +++ b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-user-api.php @@ -8,6 +8,10 @@ class Wiass_REST_User_API { */ private static $namespace = 'wiaas'; + public function __construct() { + include_once dirname( __FILE__ ) . '/user/class-wiaas-user-profile.php'; + } + public static function register_routes() { register_rest_route( self::$namespace, 'user/validate-token', array( @@ -39,21 +43,8 @@ class Wiass_REST_User_API { } public static function get_countries(){ - $result = [ - array( - 'idCountry' => '1', - 'countryName' => 'Sweden' - ), - array( - 'idCountry' => '2', - 'countryName' => 'Finland' - ), - array( - 'idCountry' => '3', - 'countryName' => 'Denmark' - ) - ]; + $countries = Wiaas_User_Profile::get_list_of_countries(); - return new WP_REST_Response($result); + return new WP_REST_Response($countries); } } \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/user/class-wiaas-user-profile.php b/backend/app/plugins/wiaas/includes/user/class-wiaas-user-profile.php new file mode 100644 index 0000000..a13ede6 --- /dev/null +++ b/backend/app/plugins/wiaas/includes/user/class-wiaas-user-profile.php @@ -0,0 +1,40 @@ + '1', + 'countryName' => 'Sweden' + ), + array( + 'idCountry' => '2', + 'countryName' => 'Finland' + ), + array( + 'idCountry' => '3', + 'countryName' => 'Denmark' + ) + ]; + + public static function get_list_of_countries(){ + return self::LIST_OF_COUNTRIES; + } + + public static function check_country_id($id){ + foreach (self::LIST_OF_COUNTRIES as $country){ + if ($country['idCountry'] === $id) return true; + } + return false; + } + + public static function get_country_name_by_id($id){ + foreach(self::LIST_OF_COUNTRIES as $country){ + if ($country['idCountry'] === $id) return $country['countryName']; + } + return ''; + } +} \ No newline at end of file