WC_Admin_Report::prepare_chart_data()
Put data with post_date's into an array of times.
Метод класса: WC_Admin_Report{}
Хуков нет.
Возвращает
Массив
.
Использование
$WC_Admin_Report = new WC_Admin_Report(); $WC_Admin_Report->prepare_chart_data( $data, $date_key, $data_key, $interval, $start_date, $group_by );
- $data(массив) (обязательный)
- array of your data.
- $date_key(строка) (обязательный)
- key for the 'date' field. e.g. post_date.
- $data_key(строка) (обязательный)
- key for the data you are charting.
- $interval(int) (обязательный)
- interval to use.
- $start_date(строка) (обязательный)
- start date.
- $group_by(строка) (обязательный)
- group by.
Код WC_Admin_Report::prepare_chart_data() WC Admin Report::prepare chart data WC 9.4.2
public function prepare_chart_data( $data, $date_key, $data_key, $interval, $start_date, $group_by ) { // phpcs:disable WordPress.DateTime.RestrictedFunctions.date_date $prepared_data = array(); // Ensure all days (or months) have values in this range. if ( 'day' === $group_by ) { for ( $i = 0; $i <= $interval; $i ++ ) { $time = strtotime( date( 'Ymd', strtotime( "+{$i} DAY", $start_date ) ) ) . '000'; if ( ! isset( $prepared_data[ $time ] ) ) { $prepared_data[ $time ] = array( esc_js( $time ), 0 ); } } } else { $current_yearnum = date( 'Y', $start_date ); $current_monthnum = date( 'm', $start_date ); for ( $i = 0; $i <= $interval; $i ++ ) { $time = strtotime( $current_yearnum . str_pad( $current_monthnum, 2, '0', STR_PAD_LEFT ) . '01' ) . '000'; if ( ! isset( $prepared_data[ $time ] ) ) { $prepared_data[ $time ] = array( esc_js( $time ), 0 ); } $current_monthnum ++; if ( $current_monthnum > 12 ) { $current_monthnum = 1; $current_yearnum ++; } } } foreach ( $data as $d ) { switch ( $group_by ) { case 'day': $time = strtotime( date( 'Ymd', strtotime( $d->$date_key ) ) ) . '000'; break; case 'month': default: $time = strtotime( date( 'Ym', strtotime( $d->$date_key ) ) . '01' ) . '000'; break; } if ( ! isset( $prepared_data[ $time ] ) ) { continue; } if ( $data_key ) { $prepared_data[ $time ][1] += is_numeric( $d->$data_key ) ? $d->$data_key : 0; } else { $prepared_data[ $time ][1] ++; } } return $prepared_data; // phpcs:enable WordPress.DateTime.RestrictedFunctions.date_date }