Automattic\WooCommerce\Admin\API\Reports\PerformanceIndicators

Controller::get_items()publicWC 1.0

Get all reports.

Метод класса: Controller{}

Возвращает

Массив|WP_Error.

Использование

$Controller = new Controller();
$Controller->get_items( $request );
$request(WP_REST_Request) (обязательный)
Request data.

Код Controller::get_items() WC 9.8.2

public function get_items( $request ) {
	$indicator_data = $this->get_indicator_data();
	if ( is_wp_error( $indicator_data ) ) {
		return $indicator_data;
	}

	$query_args = $this->prepare_reports_query( $request );
	if ( empty( $query_args['stats'] ) ) {
		return new \WP_Error( 'woocommerce_analytics_performance_indicators_empty_query', __( 'A list of stats to query must be provided.', 'woocommerce' ), 400 );
	}

	$stats = array();
	foreach ( $query_args['stats'] as $stat ) {
		$is_error = false;

		$pieces = $this->get_stats_parts( $stat );
		$report = $pieces[0];
		$chart  = $pieces[1];

		if ( ! in_array( $stat, $this->allowed_stats, true ) ) {
			continue;
		}

		$response = $this->get_stats_data( $report, $query_args );

		if ( is_wp_error( $response ) ) {
			return $response;
		}

		$data   = $response->get_data();
		$format = $this->formats[ $stat ];
		$label  = $this->labels[ $stat ];

		if ( 200 !== $response->get_status() ) {
			$stats[] = (object) array(
				'stat'   => $stat,
				'chart'  => $chart,
				'label'  => $label,
				'format' => $format,
				'value'  => null,
			);
			continue;
		}

		$stats[] = (object) array(
			'stat'   => $stat,
			'chart'  => $chart,
			'label'  => $label,
			'format' => $format,
			'value'  => apply_filters( 'woocommerce_rest_performance_indicators_data_value', $data, $stat, $report, $chart, $query_args ),
		);
	}

	usort( $stats, array( $this, 'sort' ) );

	$objects = array();
	foreach ( $stats as $stat ) {
		$data      = $this->prepare_item_for_response( $stat, $request );
		$objects[] = $this->prepare_response_for_collection( $data );
	}

	$response = rest_ensure_response( $objects );
	$response->header( 'X-WP-Total', count( $stats ) );
	$response->header( 'X-WP-TotalPages', 1 );

	$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );

	return $response;
}