Automattic\WooCommerce\Admin\API\Reports

Segmenter::fill_in_missing_segments()protectedWC 1.0

Adds zeroes for segments not present in the data selection.

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

Хуков нет.

Возвращает

Массив.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->fill_in_missing_segments( $segments );
$segments(массив) (обязательный)
Array of segments from the database for given data points.

Код Segmenter::fill_in_missing_segments() WC 8.7.0

protected function fill_in_missing_segments( $segments ) {
	$segment_subtotals = array();
	if ( isset( $this->query_args['fields'] ) && is_array( $this->query_args['fields'] ) ) {
		foreach ( $this->query_args['fields'] as $field ) {
			if ( isset( $this->report_columns[ $field ] ) ) {
				$segment_subtotals[ $field ] = 0;
			}
		}
	} else {
		foreach ( $this->report_columns as $field => $sql_clause ) {
			$segment_subtotals[ $field ] = 0;
		}
	}
	if ( ! is_array( $segments ) ) {
		$segments = array();
	}
	$all_segment_ids = $this->get_all_segments();
	$segment_labels  = $this->get_segment_labels();
	foreach ( $all_segment_ids as $segment_id ) {
		if ( ! isset( $segments[ $segment_id ] ) ) {
			$segments[ $segment_id ] = array(
				'segment_id'    => $segment_id,
				'segment_label' => $segment_labels[ $segment_id ],
				'subtotals'     => $segment_subtotals,
			);
		}
	}

	// Using array_values to remove custom keys, so that it gets later converted to JSON as an array.
	$segments_no_keys = array_values( $segments );
	usort( $segments_no_keys, array( $this, 'segment_cmp' ) );
	return $segments_no_keys;
}