Automattic\WooCommerce\Admin\API

Leaderboards::get_items()publicWC 1.0

Return all leaderboards.

Method of the class: Leaderboards{}

No Hooks.

Return

WP_Error|WP_REST_Response.

Usage

$Leaderboards = new Leaderboards();
$Leaderboards->get_items( $request );
$request(WP_REST_Request) (required)
Request data.

Leaderboards::get_items() code WC 7.3.0

public function get_items( $request ) {
	$persisted_query = json_decode( $request['persisted_query'], true );

	switch ( $request['leaderboard'] ) {
		case 'customers':
			$leaderboards = array( $this->get_customers_leaderboard( $request['per_page'], $request['after'], $request['before'], $persisted_query ) );
			break;
		case 'coupons':
			$leaderboards = array( $this->get_coupons_leaderboard( $request['per_page'], $request['after'], $request['before'], $persisted_query ) );
			break;
		case 'categories':
			$leaderboards = array( $this->get_categories_leaderboard( $request['per_page'], $request['after'], $request['before'], $persisted_query ) );
			break;
		case 'products':
			$leaderboards = array( $this->get_products_leaderboard( $request['per_page'], $request['after'], $request['before'], $persisted_query ) );
			break;
		default:
			$leaderboards = $this->get_leaderboards( $request['per_page'], $request['after'], $request['before'], $persisted_query );
			break;
	}

	$data = array();
	if ( ! empty( $leaderboards ) ) {
		foreach ( $leaderboards as $leaderboard ) {
			$response = $this->prepare_item_for_response( $leaderboard, $request );
			$data[]   = $this->prepare_response_for_collection( $response );
		}
	}

	return rest_ensure_response( $data );
}