From 1248c1031439119e2ce683b3461e5e047f9d4f35 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 17 Jul 2019 22:47:10 -0400 Subject: [PATCH] adding poi route and endpoint. Using POST to send the lat lon to get poi by boundaries --- setup/routes.php | 3 +- setup/routes/pointsOfInterest.php | 117 ++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 setup/routes/pointsOfInterest.php diff --git a/setup/routes.php b/setup/routes.php index 44fd9b7..de0f29c 100644 --- a/setup/routes.php +++ b/setup/routes.php @@ -22,4 +22,5 @@ require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php'; * Require the routes */ require_once 'routes/dashboard.php'; -require_once 'routes/members.php'; \ No newline at end of file +require_once 'routes/members.php'; +require_once 'routes/pointsOfInterest.php'; \ No newline at end of file diff --git a/setup/routes/pointsOfInterest.php b/setup/routes/pointsOfInterest.php new file mode 100644 index 0000000..950b1d4 --- /dev/null +++ b/setup/routes/pointsOfInterest.php @@ -0,0 +1,117 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release adminHooks.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/** + * Require the Contact Data Class. + */ + + +/** + * Documentation for Wordpress API and adding custom endpoints. + * https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/ + */ +class GLMA_POI_Rest_Controller +{ + /** + * __construct + * + * Class Constructor + * + * @param $wpdb Wordpress wpdb Database Object + * @param $config GlmAssociate config array + */ + public function __construct( $wpdb, $config ) + { + $this->namespace = 'glm/v1/'; + $this->resource_name = 'poi'; + + // Setup wpdb and config + $this->wpdb = $wpdb; + $this->config = $config; + } + + /** + * register_routes + * + * Registers the routes for this class. + * + * @return void + */ + public function register_routes() + { + // Members Route + register_rest_route( + $this->namespace, // namespace + $this->resource_name , // resource_name + array( // array of arrays for multiple methods. Add more arrays for different endpoints. + array( // endpoint for getting members + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => function( $request ) { + // Callback function can be a lot shorter. + // You could just create a new model to get the results in an array + // and use return rest_ensure_response( $data ); + + + return rest_ensure_response( $request ); + }, + ) + ) + ); + + } + + public function get_collection_params(){ + return array( + 'page' => array( + 'description' => 'Current page of the collection', + 'type' => 'integer', + 'default' => 1, + 'sanitize_callback' => 'absint', + ), + 'per_page' => array( + 'description' => 'Maximum number of items to be returned in result set.', + 'type' => 'integer', + 'default' => 10, + 'sanitize_callback' => 'absint', + ), + 'search' => array( + 'description' => 'Limit results to those matching a string', + 'type' => 'string', + 'sanitize_callback' => 'sanitize_text_field', + ), + ); + } + + public function authorization_status_code(){ + $status = 401; + + if ( is_user_logged_in() ) { + $status = 403; + } + return $status; + } + +} + +/** + * Create Action for the REST API Route. + */ + add_action( + 'rest_api_init', + function(){ + $controller = new GLMA_POI_Rest_Controller( $this->wpdb, $this->config ); + $controller->register_routes(); + } + ); -- 2.17.1