WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

Automattic\WooCommerce\Admin\API\Reports

DataStore::fill_in_missing_intervals() protected WC 1.0

Fills in interval gaps from DB with 0-filled objects.

{} Это метод класса: DataStore{}

Хуков нет.

Возвращает

stdClass.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->fill_in_missing_intervals( $db_intervals, $start_datetime, $end_datetime, $time_interval, $data );
$db_intervals(массив) (обязательный)
Array of all intervals present in the db.
$start_datetime(DateTime) (обязательный)
Start date.
$end_datetime(DateTime) (обязательный)
End date.
$time_interval(строка) (обязательный)
Time interval, e.g. day, week, month.
$data(stdClass) (обязательный) (передается по ссылке — &)
Data with SQL extracted intervals.

Код DataStore::fill_in_missing_intervals() WC 4.7.1

<?php
protected function fill_in_missing_intervals( $db_intervals, $start_datetime, $end_datetime, $time_interval, &$data ) {
	// @todo This is ugly and messy.
	$local_tz = new \DateTimeZone( wc_timezone_string() );
	// At this point, we don't know when we can stop iterating, as the ordering can be based on any value.
	$time_ids     = array_flip( wp_list_pluck( $data->intervals, 'time_interval' ) );
	$db_intervals = array_flip( $db_intervals );
	// Totals object used to get all needed properties.
	$totals_arr = get_object_vars( $data->totals );
	foreach ( $totals_arr as $key => $val ) {
		$totals_arr[ $key ] = 0;
	}
	// @todo Should 'products' be in intervals?
	unset( $totals_arr['products'] );
	while ( $start_datetime <= $end_datetime ) {
		$next_start = TimeInterval::iterate( $start_datetime, $time_interval );
		$time_id    = TimeInterval::time_interval_id( $time_interval, $start_datetime );
		// Either create fill-zero interval or use data from db.
		if ( $next_start > $end_datetime ) {
			$interval_end = $end_datetime->format( 'Y-m-d H:i:s' );
		} else {
			$prev_end_timestamp = (int) $next_start->format( 'U' ) - 1;
			$prev_end           = new \DateTime();
			$prev_end->setTimestamp( $prev_end_timestamp );
			$prev_end->setTimezone( $local_tz );
			$interval_end = $prev_end->format( 'Y-m-d H:i:s' );
		}
		if ( array_key_exists( $time_id, $time_ids ) ) {
			// For interval present in the db for this time frame, just fill in dates.
			$record               = &$data->intervals[ $time_ids[ $time_id ] ];
			$record['date_start'] = $start_datetime->format( 'Y-m-d H:i:s' );
			$record['date_end']   = $interval_end;
		} elseif ( ! array_key_exists( $time_id, $db_intervals ) ) {
			// For intervals present in the db outside of this time frame, do nothing.
			// For intervals not present in the db, fabricate it.
			$record_arr                  = array();
			$record_arr['time_interval'] = $time_id;
			$record_arr['date_start']    = $start_datetime->format( 'Y-m-d H:i:s' );
			$record_arr['date_end']      = $interval_end;
			$data->intervals[]           = array_merge( $record_arr, $totals_arr );
		}
		$start_datetime = $next_start;
	}
	return $data;
}