Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • That should work @gerrit_bes

    <?php
    /**
     * Plugin Name: Football Pool Match Predictions Extension
     * Description: Order match predictions by score and don't show users without predictions.
     * Version: 2.0
     * Author: Antoine Hurkmans
     * Author URI: mailto:[email protected]
     * License: MIT
     */
    
    // Save this plugin in the wp-content/plugins folder and activate it //
    
    class FootballPoolExtensionMatchPredictions {
    	public static function init_extension() {
    		if ( ! is_admin() ) {
    			add_filter( 'footballpool_statistics_matchpredictions', array( __CLASS__, 'change_matchpredictions' ), null, 2 );
    		}
    	}
    	
    	public static function change_matchpredictions( $predictions, $match_info ) {
    		// add score
    		array_walk( $predictions, array( __CLASS__, 'add_score' ), $match_info );
    		// remove users from other leagues
    		//$predictions = array_filter( $predictions, function( $p ) {
    		//return (int) $p['league_id'] === 5;
    		//} );
    		$predictions = array_filter( $predictions, array( __CLASS__, 'Filter_user_league' ) );
    		// remove users without predictions
    		// $predictions = array_filter( $predictions, array( __CLASS__, 'remove_inactive_users' ) );
    		// sort by score
    		usort( $predictions, array( __CLASS__, 'sort_table' ) );
    		
    		return $predictions;
    	}
    
    	public static function Filter_user_league ( $p ) {
    
    	$user_id = get_current_user_id();
    
    	if ( $user_id > 0 ) {
    		$pool = new Football_Pool_Pool();
    		$league_name = $pool->get_league_for_user( $user_id );
    	}
    
    	return (int) $p['league_id'] === $league_name;
    	}
    	
    	public static function add_score( &$prediction, $key, $match_info ) {
    		$pool = new Football_Pool_Pool;
    		$prediction['score'] = $pool->calc_score(
    									$match_info['home_score'], 
    									$match_info['away_score'], 
    									$prediction['home_score'], 
    									$prediction['away_score'], 
    									$prediction['has_joker'],
    									$match_info['id'],
    									$prediction['user_id']
    								);
    	}
    	
    	public static function remove_inactive_users( $prediction ) {
    		return ! is_null( $prediction['home_score'] ) && ! is_null( $prediction['away_score'] );
    	}
    	
    	public static function sort_table( $a, $b ) {
    		if ( $a['score'] == $b['score'] ) return 0;
    		return ( $a['score'] < $b['score'] ) ? 1 : -1;
    	}
    }
    
    add_filter( 'plugins_loaded', array( 'FootballPoolExtensionMatchPredictions', 'init_extension' ) );
    

    @fegs1204 do you have code for the questions, too? (Thanks for the other code btw ?? )

    Thanks @antoineh but if I do this i can`t see any tips in the list.

     public static function change_matchpredictions( $predictions, $match_info ) {
    	// add score
            array_walk( $predictions, array( __CLASS__, 'add_score' ), $match_info );
            
    	$user_id = get_current_user_id();
    	$pool = new Football_Pool_Pool();
    	$league = $pool->get_league_for_user( $user_id );
    
    	// remove users from other leagues
    	$predictions = array_filter( $predictions, function( $p ) {
    		return (int) $p['league_id'] === ( $league );
    	} );
    
            // sort by score
            usort( $predictions, array( __CLASS__, 'sort_table' ) );
             
            return $predictions;
        }
    

    Can you explain the code to get the current users league-id into the code snipped you shared? I tried with the code from the other plugin, but I could not get it to work.
    Or @fegs1204 do you have your plugins working? Could you please share them?

    
    // remove users from other leagues
    $predictions = array_filter( $predictions, function( $p ) {
    	return (int) $p['league_id'] === <strong>this code</strong>;
    } );
Viewing 3 replies - 1 through 3 (of 3 total)