Added more general function for sorting array of arrays based on subarray's key.

This commit is contained in:
Peter Fabian 2019-01-15 11:08:23 +01:00
parent 13ec8e2851
commit b593163dff
1 changed files with 12 additions and 1 deletions

View File

@ -94,9 +94,20 @@ class WC_Admin_Reports_Data_Store {
* @param string $direction DESC/ASC. * @param string $direction DESC/ASC.
*/ */
protected function sort_intervals( &$data, $sort_by, $direction ) { protected function sort_intervals( &$data, $sort_by, $direction ) {
$this->sort_array( $data->intervals, $sort_by, $direction );
}
/**
* Sorts array of arrays based on subarray key $sort_by.
*
* @param array $arr Array to sort.
* @param string $sort_by Ordering property.
* @param string $direction DESC/ASC.
*/
protected function sort_array( &$arr, $sort_by, $direction ) {
$this->order_by = $this->normalize_order_by( $sort_by ); $this->order_by = $this->normalize_order_by( $sort_by );
$this->order = $direction; $this->order = $direction;
usort( $data->intervals, array( $this, 'interval_cmp' ) ); usort( $arr, array( $this, 'interval_cmp' ) );
} }
/** /**