SportsPress icon indicating copy to clipboard operation
SportsPress copied to clipboard

League table custom sort issue with decimal values

Open rochesterj opened this issue 3 years ago • 2 comments

In the sportspress/includes/class-sp-league-table.php file, lines 911 and 917, uasort expects 0 or 1 or -1, thus simply returning the value difference will give inconsistent results.

How to reproduce: Create a new league table, use a column with decimal places then add a difference smaller than 1 between items: e.g Team A: 5.28 Team B: 6.27

The ordering will be broken, because the function returns -0.99 instead of -1.

How to fix it: A simple one line conditional statement should do it: return ( (float) $b[ $this->orderby ] - (float) $a[ $this->orderby ] ) > 0 ? 1 : -1;

and return ( (float) $a[ $this->orderby ] - (float) $b[ $this->orderby ] ) > 0 ? 1 : -1;

At least this fixes the issue for me. Cheers!

rochesterj avatar Dec 02 '21 16:12 rochesterj

Or maybe even the simpler version return ($a < $b) ? -1 : 1; should work, there's no need to subtract these 2

rochesterj avatar Dec 02 '21 16:12 rochesterj

@rochesterj is that issue still there?

savvasha avatar May 07 '23 07:05 savvasha