Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

League table custom sort issue with decimal values #427

Open
rochesterj opened this issue Dec 2, 2021 · 2 comments
Open

League table custom sort issue with decimal values #427

rochesterj opened this issue Dec 2, 2021 · 2 comments
Assignees
Labels

Comments

@rochesterj
Copy link
Collaborator

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
Copy link
Collaborator Author

rochesterj commented Dec 2, 2021

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

@rochesterj rochesterj reopened this Dec 2, 2021
@savvasha
Copy link
Collaborator

savvasha commented May 7, 2023

@rochesterj is that issue still there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
SportsPress 2.8
Awaiting triage
Development

No branches or pull requests

3 participants