From 930ce3d63a540e70b98bd4aca6f9ae28fd27429e Mon Sep 17 00:00:00 2001 From: Hoang Huu Date: Fri, 25 Oct 2019 17:35:24 +0700 Subject: [PATCH] Update --- inc/api/functions.php | 43 ++++++++++++++++++++++++++++++--- inc/api/v1/property.php | 53 ++++++++++++++++++++++++++++++----------- 2 files changed, 79 insertions(+), 17 deletions(-) diff --git a/inc/api/functions.php b/inc/api/functions.php index d1bbd474..84e996d5 100644 --- a/inc/api/functions.php +++ b/inc/api/functions.php @@ -93,8 +93,7 @@ function opalestate_get_user_data_by_consumer_key( $consumer_key ) { * * @param object $property_info The Download Post Object * - * @return array Array of post data to return back in the API - * @since 1.0 + * @return array Array of post data to return back in the API * */ function opalestate_api_get_property_data( $property_info ) { @@ -154,7 +153,45 @@ function opalestate_api_get_property_data( $property_info ) { 'values' => $array_values, ]; - return apply_filters( 'opalestate_api_properties_property', $property ); + return apply_filters( 'opalestate_api_get_property_data', $property ); +} + +/** + * The opalestate_property post object, generate the data for the API output + * + * @param object $property_info The Download Post Object + * + * @return array Array of post data to return back in the API + * @since 1.0 + * + */ +function opalestate_api_parse_property_meta_key() { + $request = [ + 'name' => '', + 'status' => '', + 'content' => '', + 'thumbnail' => '', + 'gallery' => '', + 'price' => '', + 'saleprice' => '', + 'before_price_label' => '', + 'price_label' => '', + 'featured' => '', + 'map' => '', + 'address' => '', + 'video' => '', + 'virtual_tour' => '', + 'attachments' => '', + 'floor_plans' => '', + 'statuses' => '', + 'labels' => '', + 'locations' => '', + 'facilities' => '', + 'amenities' => '', + 'types' => '', + ]; + + return apply_filters( 'opalestate_api_parse_property_meta_key', $request ); } /** diff --git a/inc/api/v1/property.php b/inc/api/v1/property.php index 12be1fa8..b9fc76e2 100644 --- a/inc/api/v1/property.php +++ b/inc/api/v1/property.php @@ -47,11 +47,11 @@ class Opalestate_Property_Api extends Opalestate_Base_API { 'permission_callback' => [ $this, 'get_items_permissions_check' ], 'args' => $this->get_collection_params(), ], - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'create_item' ], - 'permission_callback' => [ $this, 'create_item_permissions_check' ], - ], + // [ + // 'methods' => WP_REST_Server::CREATABLE, + // 'callback' => [ $this, 'create_item' ], + // 'permission_callback' => [ $this, 'create_item_permissions_check' ], + // ], ] ); @@ -70,11 +70,11 @@ class Opalestate_Property_Api extends Opalestate_Base_API { 'callback' => [ $this, 'get_item' ], 'permission_callback' => [ $this, 'get_item_permissions_check' ], ], - // [ - // 'methods' => WP_REST_Server::EDITABLE, - // 'callback' => [ $this, 'update_item' ], - // // 'permission_callback' => [ $this, 'update_item_permissions_check' ], - // ], + [ + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'update_item' ], + 'permission_callback' => [ $this, 'update_item_permissions_check' ], + ], // [ // 'methods' => WP_REST_Server::DELETABLE, // 'callback' => [ $this, 'delete_item' ], @@ -153,11 +153,10 @@ class Opalestate_Property_Api extends Opalestate_Base_API { } /** - * Get Property + * Get a property * - * Based on request to get a property. - * - * @return WP_REST_Response is json data + * @param WP_REST_Request $request Full details about the request. + * @return WP_Error|WP_REST_Response */ public function get_item( $request ) { $response = []; @@ -179,6 +178,32 @@ class Opalestate_Property_Api extends Opalestate_Base_API { return $this->get_response( $code, $response ); } + /** + * Update a property. + * + * @param WP_REST_Request $request Full details about the request. + * @return WP_Error|WP_REST_Response + */ + public function update_item( $request ) { + $id = absint( $request['id'] ); + + $property = get_post( $id ); + if ( ! $property || $this->post_type != $property->post_type ) { + $code = 404; + $response['error'] = sprintf( esc_html__( 'Property ID: %s does not exist!', 'opalestate-pro' ), $id ); + } else { + + } + + return $this->get_response( $code, $response ); + } + + /** + * Delete a property. + * + * @param WP_REST_Request $request Full details about the request. + * @return WP_Error|WP_REST_Response + */ public function delete_item( $request ) { $id = (int) $request['id']; $force = (bool) $request['force'];