Automattic\WooCommerce\Admin\API\Reports\PerformanceIndicators
Controller::format_data_value
Format the data returned from the API for given stats.
Метод класса: Controller{}
Хуков нет.
Возвращает
Разное.
Использование
$Controller = new Controller(); $Controller->format_data_value( $data, $stat, $report, $chart, $query_args );
- $data(массив) (обязательный)
- Data from external endpoint.
- $stat(строка) (обязательный)
- Name of the stat.
- $report(строка) (обязательный)
- Name of the report.
- $chart(строка) (обязательный)
- Name of the chart.
- $query_args(массив) (обязательный)
- Query args.
Код Controller::format_data_value() Controller::format data value WC 10.8.1
public function format_data_value( $data, $stat, $report, $chart, $query_args ) {
if ( 'jetpack/stats' === $report ) {
$index = false;
// Get the index of the field to tally.
if ( isset( $data['general']->visits->fields ) && is_array( $data['general']->visits->fields ) ) {
$index = array_search( $chart, $data['general']->visits->fields, true );
}
if ( ! $index ) {
return null;
}
// Loop over provided data and filter by the queried date.
// Note that this is currently limited to 30 days via the Jetpack API
// but the WordPress.com endpoint allows up to 90 days.
$total = 0;
$before = gmdate( 'Y-m-d', strtotime( isset( $query_args['before'] ) ? $query_args['before'] : TimeInterval::default_before() ) );
$after = gmdate( 'Y-m-d', strtotime( isset( $query_args['after'] ) ? $query_args['after'] : TimeInterval::default_after() ) );
foreach ( $data['general']->visits->data as $datum ) {
if ( $datum[0] >= $after && $datum[0] <= $before ) {
$total += $datum[ $index ];
}
}
return $total;
}
if ( isset( $data['totals'] ) && isset( $data['totals'][ $chart ] ) ) {
return $data['totals'][ $chart ];
}
return null;
}