• Resolved fanman1948

    (@fanman1948)


    Hi,
    I’m using your add-on to sort the results according to the points scored by the user. I have changed the code a little bit in order to show also users who have not entered typing.

    But is it possible to make the sorting work like this, for example.
    1. Users who have scored 3 points
    2. Users who have scored 2 points
    3. Users who have scored 1 points
    4. Users who have scored 0 points
    5. Users who have scored 0 points (but did not type).

    That is, from the highest number of points scored to the lowest, but so that those who did not type at all – are at the bottom of the list.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author AntoineH

    (@antoineh)

    Which add-on exactly are you using? I have so many it’s hard to tell which one you are referring to ??

    Thread Starter fanman1948

    (@fanman1948)

    Plugin Name: Football Pool Sort Match Predictions

    Plugin Author AntoineH

    (@antoineh)

    Yes, that is actually pretty easy. I can show you an example tonight. Basically boils down to adding an extra value to the $predictions array (e.g. 1 for the people with a prediction and 0 for those who didn’t). The logic for this is already in that add-on (as part of the remove inactive users). And with this value added to the array, you can use it in the sorting callback as a second sorting parameter for the spaceship operator (meaning when points are the same, then use this new value first to divide the players).

    pekos

    (@pekos)

    Hi @fanman1948 & @antoineh

    can you please share location for Football Pool Sort Match Predictions ?

    If this is in dropbox, is there a main download location with all plugins listed?

    Thanx

    Thread Starter fanman1948

    (@fanman1948)

    pekos

    (@pekos)

    thank you @fanman1948

    Plugin Author AntoineH

    (@antoineh)

    @fanman1948 add the following line to your add_score() function:

    $prediction['user_has_prediction'] = ( is_null( $prediction['home_score'] ) || is_null( $prediction['away_score'] ) ) ? 0 : 1;

    This will add a “1” to the array for people that have entered a prediction, and “0” for those who didn’t.

    And then change the sorting rule in sort_table() to this:

    return [$b['score'], $b['user_has_prediction'], $a['user_name']] <=> [$a['score'], $a['user_has_prediction'], $b['user_name']];

    This should do the trick.

    Thread Starter fanman1948

    (@fanman1948)

    hmmm like this?

    	public static function add_score( $prediction['user_has_prediction'] = ( is_null( $prediction['home_score'] ) || is_null( $prediction['away_score'] ) ) ? 0 : 1; ) {

    when I have error message

    syntax error, unexpected '[', expecting ')'
    • This reply was modified 9 months ago by fanman1948.
    Plugin Author AntoineH

    (@antoineh)

    No, sorry, I meant please add somewhere in the function body.

    public static function add_score( &$prediction, $key, $match_info ) {

    ...current code...


    $prediction['user_has_prediction'] = ( is_null( $prediction['home_score'] ) || is_null( $prediction['away_score'] ) ) ? 0 : 1;
    }
    Thread Starter fanman1948

    (@fanman1948)

    aaa…yes, now it’s works. but maybe you know why sometimes sort by alphabet isn’t work?

    • This reply was modified 9 months ago by fanman1948.
    Plugin Author AntoineH

    (@antoineh)

    Don’t know. Could be a difference in the user name that is used in the sorting and the user name that is passed to the template for the display. Or something in the spaceship operator with regards to string comparisons. Don’t know if it is worth the effort of investigating.

    Thread Starter fanman1948

    (@fanman1948)

    it’s looks like prediction goals decided this. Eg. Albania 0-1 Spain and first is every user with prediction 0 for Albania, next user with 1

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Sorting the results’ is closed to new replies.