Forum Replies Created

Viewing 15 replies - 1 through 15 (of 79 total)
  • thanks!

    If we already have users and predictions, to update the dates in bulk, any way or have to do manually?

    Thread Starter latinosamorir

    (@latinosamorir)

    Antoine, you’re awesome.

    OK, #1 solved.

    For #2, if I want a user to see others predictions after matches, what’s the best way without telling them to update the URL?

    Thread Starter latinosamorir

    (@latinosamorir)

    Hey @clancompetitions! Did you end up making one?

    Thanks!

    Thread Starter latinosamorir

    (@latinosamorir)

    Yes – that would be great @clancompetitions! Thanks

    Thread Starter latinosamorir

    (@latinosamorir)

    Thread Starter latinosamorir

    (@latinosamorir)

    figured it out – timestamp. =)

    something interesting though is that using the timestamp # it gives me the ranking as of the time of the match and it includes the points for that specific match.

    Thread Starter latinosamorir

    (@latinosamorir)

    thanks! i tried this but it returns blanks:

    $row_params['rank'] = $pool->get_user_rank( $user_id, FOOTBALLPOOL_RANKING_DEFAULT , date("Y-m-d H:i:s", $match_info['match_datetime']) );
    $row_params['points'] = $pool->get_user_score( $user_id, FOOTBALLPOOL_RANKING_DEFAULT , date("Y-m-d H:i:s"),$match_info['match_datetime']);

    what am i missing?

    Thread Starter latinosamorir

    (@latinosamorir)

    Awesome thanks!! Will test soon!!

    An additional question, what’s the best way to get the user points? I’ve received request to display the points as well next to rank.

    Where did they info exist?

    Thanks!

    @gudetips16, could you please let me know what code you deleted to fix the pie charts?

    “I also erased the code that made the new ?full with diff? category in the piechart.”

    Thanks @tarmost for pointing me to the right line for the math fix!

    Thread Starter latinosamorir

    (@latinosamorir)

    ah — i noticed that by activating this plugin, the logged in user’s row is no longer highlighted, how can i do that?

    thanks!

    Thread Starter latinosamorir

    (@latinosamorir)

    fixed!

    attached cleaner version:

    <?php
    /**
     * Plugin Name: Football Pool Match Predictions Extension with Ranking
     * Description: Display user ranking and order match predictions by ranking
     * Version: 2.1
     * Author: Antoine Hurkmans + Giovanni Dubois
     * 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_matchpredictions_template_start', array( __CLASS__, 'add_ranking_column_template_start'), null, 2);
    			add_filter( 'footballpool_matchpredictions_row_template', array( __CLASS__, 'add_ranking_column_template_row'), null, 2);
    			add_filter( 'footballpool_matchpredictions_row_params', array( __CLASS__, 'add_ranking_param'), null, 3);
    			add_filter( 'footballpool_statistics_matchpredictions', array( __CLASS__, 'change_matchpredictions' ), null, 2 );
    		}
    	}
    	
    	public static function change_matchpredictions( $predictions, $match_info ) {
    		// add score & ranking
    		array_walk( $predictions, array( __CLASS__, 'add_ranking' ), $match_info );
    		// remove users without predictions
    		$predictions = array_filter( $predictions, array( __CLASS__, 'remove_inactive_users' ) );
    		// sort by ranking
    		usort( $predictions, array( __CLASS__, 'sort_table' ) );
    		
    		return $predictions;
    	}
    	
    	public static function add_ranking( &$prediction, $key, $match_info ) {
    		$pool = new Football_Pool_Pool;
    		$prediction['rank'] = $pool->get_user_rank( $prediction['user_id'], FOOTBALLPOOL_RANKING_DEFAULT , date("Y-m-d H:i:s") );
    		$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 add_ranking_column_template_row ( $row_template , $match_info ) {
    		$pool = new Football_Pool_Pool();
    		$row_template = '<tr>
    								<td class="ranking" style="text-align:  center;">%rank%</td>
    								<td><a href="%user_url%">%user_name%</a></td>
    								<td class="home">%home_score%</td>
    								<td class="match-hyphen">-</td>
    								<td class="away">%away_score%</td>';
    			if ( $pool->has_jokers ) {
    				$row_template .= '<td title="%joker_title_text%"><span class="nopointer %joker_css_class%"></span></td>';
    			}
    			$row_template .= '<td class="score">%score%</td></tr>';	
    			
    			return $row_template;
    	}
    	
    	public static function add_ranking_column_template_start ( $template_start , $match_info ){
    		$pool = new Football_Pool_Pool();
    		$template_start = sprintf( '<table class="matchinfo statistics">
    									<tr><th class="ranking">%s</th><th class="username">%s</th>
    									<th colspan="%d">%s</th><th>%s</th></tr>',
    									__( 'rank', 'football-pool'),
    									__( 'name', 'football-pool' ),
    									( $pool->has_jokers ? 4 : 3 ),
    									__( 'prediction', 'football-pool' ),
    									__( 'score', 'football-pool' )
    								);										
    			return $template_start;
    	}
    	
    	public static function add_ranking_param ( $row_params, $match_info, $user_id ){
    		$pool = new Football_Pool_Pool();
    		$row_params['rank'] = $pool->get_user_rank( $user_id, FOOTBALLPOOL_RANKING_DEFAULT , date("Y-m-d H:i:s") );
    		return $row_params;
    	}
    	
    	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['rank'] == $b['rank'] ) return 0;
    		return ( $a['rank'] > $b['rank'] ) ? 1 : -1;
    	}
    }
    
    add_filter( 'plugins_loaded', array( 'FootballPoolExtensionMatchPredictions', 'init_extension' ) );
    
    Thread Starter latinosamorir

    (@latinosamorir)

    thing i’m having issues with is sorting the ranking, but at least i can show the ranking now!

    Thread Starter latinosamorir

    (@latinosamorir)

    ok! i got it to work!!!

    <?php
    /**
     * Plugin Name: Football Pool Match Predictions Extension with Ranking
     * Description: Order match predictions by ranking
     * Version: 2.1
     * Author: Antoine Hurkmans + Giovanni Dubois
     * 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_matchpredictions_template_start', array( __CLASS__, 'add_ranking_column_template_start'), null, 2);
    			add_filter( 'footballpool_matchpredictions_row_template', array( __CLASS__, 'add_ranking_column_template_row'), null, 2);
    			add_filter( 'footballpool_matchpredictions_row_params', array( __CLASS__, 'add_ranking_param'), null, 3);
    			add_filter( 'footballpool_statistics_matchpredictions', array( __CLASS__, 'change_matchpredictions' ), null, 2 );
    		}
    	}
    	
    	public static function change_matchpredictions( $predictions, $match_info ) {
    		// add score & ranking
    		array_walk( $predictions, array( __CLASS__, 'add_ranking' ), $match_info );
    		// remove users without predictions
    		$predictions = array_filter( $predictions, array( __CLASS__, 'remove_inactive_users' ) );
    		// sort by ranking
    		usort( $predictions, array( __CLASS__, 'sort_table' ) );
    		
    		return $predictions;
    	}
    	
    	public static function add_ranking( &$prediction, $key, $match_info ) {
    		$pool = new Football_Pool_Pool;
    		//$prediction['rank'] = $pool->get_user_rank( $prediction['user_id'], FOOTBALLPOOL_RANKING_DEFAULT , date("Y-m-d H:i:s") );
    		$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 add_ranking_column_template_row ( $row_template , $match_info ) {
    		$pool = new Football_Pool_Pool();
    		$row_template = '<tr>
    								<td class="ranking" style="text-align:  center;">%rank%</td>
    								<td><a href="%user_url%">%user_name%</a></td>
    								<td class="home">%home_score%</td>
    								<td class="match-hyphen">-</td>
    								<td class="away">%away_score%</td>';
    			if ( $pool->has_jokers ) {
    				$row_template .= '<td title="%joker_title_text%"><span class="nopointer %joker_css_class%"></span></td>';
    			}
    			$row_template .= '<td class="score">%score%</td></tr>';	
    			
    			return $row_template;
    	}
    	
    	public static function add_ranking_column_template_start ( $template_start , $match_info ){
    		$pool = new Football_Pool_Pool();
    		$template_start = sprintf( '<table class="matchinfo statistics">
    									<tr><th class="ranking">%s</th><th class="username">%s</th>
    									<th colspan="%d">%s</th><th>%s</th></tr>',
    									__( 'rank', 'football-pool'),
    									__( 'name', 'football-pool' ),
    									( $pool->has_jokers ? 4 : 3 ),
    									__( 'prediction', 'football-pool' ),
    									__( 'score', 'football-pool' )
    								);										
    			return $template_start;
    	}
    	
    	public static function add_ranking_param ( $row_params, $match_info, $user_id ){
    		$pool = new Football_Pool_Pool();
    		$row_params['rank'] = $pool->get_user_rank( $user_id, FOOTBALLPOOL_RANKING_DEFAULT , date("Y-m-d H:i:s") );
    		return $row_params;
    	}
    	
    	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' ) );
    

    it’s dirty, but it works! ?? any feedback appreciated!

    Thread Starter latinosamorir

    (@latinosamorir)

    oh man – i’ve been at it for a few hours and my object orienting programming is very rusty. =(

    any help would be appreciated!!!

Viewing 15 replies - 1 through 15 (of 79 total)