This commit is contained in:
Hoang Huu 2019-10-25 17:35:24 +07:00
parent 0c48dbfa7c
commit 930ce3d63a
2 changed files with 79 additions and 17 deletions

View File

@ -94,7 +94,6 @@ function opalestate_get_user_data_by_consumer_key( $consumer_key ) {
* @param object $property_info The Download Post Object * @param object $property_info The Download Post Object
* *
* @return array Array of post data to return back in the API * @return array Array of post data to return back in the API
* @since 1.0
* *
*/ */
function opalestate_api_get_property_data( $property_info ) { function opalestate_api_get_property_data( $property_info ) {
@ -154,7 +153,45 @@ function opalestate_api_get_property_data( $property_info ) {
'values' => $array_values, '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 );
} }
/** /**

View File

@ -47,11 +47,11 @@ class Opalestate_Property_Api extends Opalestate_Base_API {
'permission_callback' => [ $this, 'get_items_permissions_check' ], 'permission_callback' => [ $this, 'get_items_permissions_check' ],
'args' => $this->get_collection_params(), 'args' => $this->get_collection_params(),
], ],
[ // [
'methods' => WP_REST_Server::CREATABLE, // 'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'create_item' ], // 'callback' => [ $this, 'create_item' ],
'permission_callback' => [ $this, 'create_item_permissions_check' ], // 'permission_callback' => [ $this, 'create_item_permissions_check' ],
], // ],
] ]
); );
@ -70,11 +70,11 @@ class Opalestate_Property_Api extends Opalestate_Base_API {
'callback' => [ $this, 'get_item' ], 'callback' => [ $this, 'get_item' ],
'permission_callback' => [ $this, 'get_item_permissions_check' ], 'permission_callback' => [ $this, 'get_item_permissions_check' ],
], ],
// [ [
// 'methods' => WP_REST_Server::EDITABLE, 'methods' => WP_REST_Server::EDITABLE,
// 'callback' => [ $this, 'update_item' ], 'callback' => [ $this, 'update_item' ],
// // 'permission_callback' => [ $this, 'update_item_permissions_check' ], 'permission_callback' => [ $this, 'update_item_permissions_check' ],
// ], ],
// [ // [
// 'methods' => WP_REST_Server::DELETABLE, // 'methods' => WP_REST_Server::DELETABLE,
// 'callback' => [ $this, 'delete_item' ], // '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. * @param WP_REST_Request $request Full details about the request.
* * @return WP_Error|WP_REST_Response
* @return WP_REST_Response is json data
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$response = []; $response = [];
@ -179,6 +178,32 @@ class Opalestate_Property_Api extends Opalestate_Base_API {
return $this->get_response( $code, $response ); 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 ) { public function delete_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
$force = (bool) $request['force']; $force = (bool) $request['force'];