Made the interval sorting stable (second level sort by time_interval).

This is required so that intervals are sorted in the same way each time when going through pages of results.
This commit is contained in:
Peter Fabian 2019-01-23 16:58:03 +01:00
parent 3521e8d485
commit eff341d832
1 changed files with 9 additions and 1 deletions

View File

@ -76,7 +76,15 @@ class WC_Admin_Reports_Data_Store {
// TODO: should return WP_Error here perhaps?
}
if ( $a[ $this->order_by ] === $b[ $this->order_by ] ) {
return 0;
// 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 ] ) {