Automattic\WooCommerce\Admin\API\Reports
Segmenter::fill_in_missing_segments()
Adds zeroes for segments not present in the data selection.
Method of the class: Segmenter{}
No Hooks.
Return
Array
.
Usage
// protected - for code of main (parent) or child class $result = $this->fill_in_missing_segments( $segments );
- $segments(array) (required)
- Array of segments from the database for given data points.
Segmenter::fill_in_missing_segments() Segmenter::fill in missing segments code WC 9.5.1
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; }