Automattic\WooCommerce\Admin\API\Reports

GenericStatsController::get_item_schema()publicWC 1.0

Get the Report's schema, conforming to JSON Schema.

Please note, it does not call add_additional_fields_schema, as you may want to update the title first.

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

Хуков нет.

Возвращает

Массив.

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

$GenericStatsController = new GenericStatsController();
$GenericStatsController->get_item_schema();

Код GenericStatsController::get_item_schema() WC 9.2.3

public function get_item_schema() {
	$data_values = $this->get_item_properties_schema();

	$segments = array(
		'segments' => array(
			'description' => __( 'Reports data grouped by segment condition.', 'woocommerce' ),
			'type'        => 'array',
			'context'     => array( 'view', 'edit' ),
			'readonly'    => true,
			'items'       => array(
				'type'       => 'object',
				'properties' => array(
					'segment_id' => array(
						'description' => __( 'Segment identificator.', 'woocommerce' ),
						'type'        => 'integer',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
					),
					'subtotals'  => array(
						'description' => __( 'Interval subtotals.', 'woocommerce' ),
						'type'        => 'object',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
						'properties'  => $data_values,
					),
				),
			),
		),
	);

	$totals = array_merge( $data_values, $segments );

	return array(
		'$schema'    => 'http://json-schema.org/draft-04/schema#',
		'title'      => 'report_stats',
		'type'       => 'object',
		'properties' => array(
			'totals'    => array(
				'description' => __( 'Totals data.', 'woocommerce' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'readonly'    => true,
				'properties'  => $totals,
			),
			'intervals' => array(
				'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ),
				'type'        => 'array',
				'context'     => array( 'view', 'edit' ),
				'readonly'    => true,
				'items'       => array(
					'type'       => 'object',
					'properties' => array(
						'interval'       => array(
							'description' => __( 'Type of interval.', 'woocommerce' ),
							'type'        => 'string',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
							'enum'        => array( 'day', 'week', 'month', 'year' ),
						),
						'date_start'     => array(
							'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ),
							'type'        => 'string',
							'format'      => 'date-time',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
						),
						'date_start_gmt' => array(
							'description' => __( 'The date the report start, as GMT.', 'woocommerce' ),
							'type'        => 'string',
							'format'      => 'date-time',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
						),
						'date_end'       => array(
							'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ),
							'type'        => 'string',
							'format'      => 'date-time',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
						),
						'date_end_gmt'   => array(
							'description' => __( 'The date the report end, as GMT.', 'woocommerce' ),
							'type'        => 'string',
							'format'      => 'date-time',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
						),
						'subtotals'      => array(
							'description' => __( 'Interval subtotals.', 'woocommerce' ),
							'type'        => 'object',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
							'properties'  => $totals,
						),
					),
				),
			),
		),
	);
}