Automattic\WooCommerce\Admin\API\Reports
DataStore::interval_cmp
Compares two report data objects by pre-defined object property and ASC/DESC ordering.
Method of the class: DataStore{}
No Hooks.
Returns
String.
Usage
// private - for code of main (parent) class only $result = $this->interval_cmp( $a, $b );
- $a(stdClass) (required)
- Object a.
- $b(stdClass) (required)
- Object b.
DataStore::interval_cmp() DataStore::interval cmp code WC 11.0.0
private function interval_cmp( $a, $b ) {
if ( '' === $this->order_by || '' === $this->order ) {
return 0;
// @todo Should return WP_Error here perhaps?
}
if ( $a[ $this->order_by ] === $b[ $this->order_by ] ) {
// As relative order is undefined in case of equality in usort, second-level sorting by date needs to be enforced
// so that paging is stable.
if ( $a['time_interval'] === $b['time_interval'] ) {
return 0; // This should never happen.
} elseif ( $a['time_interval'] > $b['time_interval'] ) {
return 1;
} elseif ( $a['time_interval'] < $b['time_interval'] ) {
return -1;
}
} elseif ( $a[ $this->order_by ] > $b[ $this->order_by ] ) {
return strtolower( $this->order ) === 'desc' ? -1 : 1;
} elseif ( $a[ $this->order_by ] < $b[ $this->order_by ] ) {
return strtolower( $this->order ) === 'desc' ? 1 : -1;
}
}