Forum Replies Created

Viewing 15 replies - 31 through 45 (of 246 total)
  • Thread Starter af3

    (@af3)

    @magicjohnson Hi, I am not a PHP programmer, this is just based on what I gather but so far it works for me. Its not the best code, maybe someone can help make it better. I added +8 to return the local time in my case; so you have to change this based on what is your GMT.

    Btw, this is a plugin so you have to save it as a php file and put in the root of the \plugin folder and activate win wp-admin.

    I also added the “locked” text in addition to the additional “Save” button. You can remove this if not needed.
    Also added is a link to “Insights” for match_type > 2 — I used it in Euro 2020 for knockout rounds (match_type 2 and above) just to add a manually created page of the match to add some articles or for people to comment on. You can change the match_type, or remove the whole thing if not needed.

    
    <?php
    /**
     * Plugin Name: Football Pool - Playing Now & Extra Save Buttons
     * Description: Add "Playing now" for every match and Extra Save buttons, added by af3
     */
    
    // Save this plugin in the "/wp-content/plugins" folder and activate it //
    
    class FootballPoolExtensionPlayNow {
    	public static function init_extension() {
    		add_filter( 'footballpool_predictionform_match_template', array( __CLASS__, 'match_card_template' ), null, 2 );
    		add_filter( 'footballpool_predictionform_match_template_params', array( __CLASS__, 'change_parameters' ), null, 4 );
    	}
    
    	public static function change_parameters( $match_template_params, $match_id, $user_id, $is_user_page ) {
    
    		// 1. First we add Playing Now Params
    		
    		$mynote = '';
    		$current_date = gmdate('M d, Y', strtotime('+ 8 hours'));
    		$current_timestamp = gmdate('M d, Y H:i:s', strtotime('+ 8 hours'));
    		$game_date = $match_template_params['match_datetime_formatted'].' '.$match_template_params['match_time'];
    
    		$duration = strtotime($game_date) - strtotime($current_timestamp); 
    		$min = $duration / 60;
    		$hours = floor(abs($min) / 60);
        	$minutes = (abs($min) % 60);
    		
            if ( $current_date == $match_template_params['match_datetime_formatted'] ) { 
               	if ($min > 1 && $min < 116 ) { $mynote = '<span class="playing-now">Starting in ' .round($min,0). ' mins</span>'; }
    			elseif ($min > 116 ) { $mynote = '<span class="playing-now">Playing in ' .$hours.' hrs, '. $minutes. ' mins</span>'; }		
    			elseif ($min < -116 ) { $mynote = '<span class="playing-now">Played '.round(abs($min),0).' mins ago</span>'; }			
    			elseif ($min > -166 && $min < 1 ) { $mynote = '<span class="playing-now">Started '.round(abs($min),0).' mins ago</span>'; }
    		} 
    		elseif ( strtotime($current_date) < strtotime($match_template_params['match_datetime_formatted']) ) { 
    			if ($min < 240 ) { $mynote = '<span class="playing-now">Playing in '. round(abs($min),0). ' mins</span>'; }		
    			else { $mynote = '<span class="playing-now">Coming up</span>'; }
    		} 
            elseif ( strtotime($current_date) > strtotime($match_template_params['match_datetime_formatted']) ) { 
            	$mynote = '<span class="playing-now">Completed</span>'; 
    		}
    
            if ($match_template_params['match_type_id'] > 2) {
                $match_template_params['home_team']= str_replace(' ', '-', $match_template_params['home_team']);
                $match_template_params['away_team']= str_replace(' ', '-', $match_template_params['away_team']);
                $mynote .= '<span class="match_info"><a href="'.home_url( '/' ).strtolower($match_template_params['home_team']).'-vs-'.strtolower($match_template_params['away_team']).'">Insights</a></span>';
            }
                    
            $match_template_params['play_started'] = $mynote;
    		
    		// 3. Now we add extra save buttons
    		if ( $match_template_params['match_is_editable'] == true ) {
    			$match_template_params['save_button'] = '<input type="submit" value="save" /><span class="closing-time">Locked 15mins before match</span>';
    		} else {
    			$match_template_params['save_button'] = '';
    		}
    		
    		// 4. FInally, send all the new params for the template
    		return $match_template_params;
    	}
    	
    	public static function match_card_template( $match_template, $is_user_page ) {
    		if ( ! $is_user_page ) {
    			if ( strpos( $match_template, '<tr>' ) !== false ) {
    				$match_template = '<tr id="match-%match_id%-%form_id%" class="%css_class%"
    								title="' . __('match', 'football-pool') . ' %match_id%">
    									<td class="time">%match_time% %play_started%</td>
    									<td class="home">%home_team%</td>
    									<td class="flag">%home_team_flag%</td>
    									<td class="score">%home_input%</td>
    									<td>-</td>
    									<td class="score">%away_input%</td>
    									<td class="flag">%away_team_flag%</td>
    									<td class="away">%away_team%</td>
    									<td>%joker%</td>
    									<td title="' . __('score', 'football-pool') . '" class="numeric">%user_score%</td>
    									<td>%stats_link% %save_button%</td>
    								</tr>';
    			} else {
    				$match_template = '<div id="match-%match_id%-%form_id%" 
    											class="%css_class% match-card match-type-%match_type_id%"
    											title="' . __( 'match', 'football-pool' ) . ' %match_id%">
    										<div class="match-card-header">
    											<span class="matchdate">%match_datetime_formatted%</span>
    											<span class="time">%match_time% %play_started%</span>
    										</div>
    										<div class="flag">%home_team_flag%</div>
    										<div class="flag">%away_team_flag%</div>
    										<div class="home">%home_team%</div>
    										<div class="away">%away_team%</div>
    										<div class="score">
    											%home_input%
    											<div class="actual-score">%home_actual_score%</div>
    										</div>
    										<div class="score">
    											%away_input%
    											<div class="actual-score">%away_actual_score%</div>
    										</div>
    										<div class="match-card-footer">
    											<div class="user-score">%user_score_txt%</div>
    											<div class="fp-icon">%stats_link%</div>
    											<div class="fp-icon">%joker%</div>
    										</div>
    										<div class="match-card-save">%save_button%</div>
    									</div>';
    			}
    		}
    		
    		return $match_template;
    	}
    }
    
    add_filter( 'plugins_loaded', array( 'FootballPoolExtensionPlayNow', 'init_extension' ) );
    
    Thread Starter af3

    (@af3)

    Ah, the shortcode fp-next-matches actually can filter by dates 🙂
    And there is already this fp-pagination plugin 🙂

    Thread Starter af3

    (@af3)

    AH, this plugin is cool. #4 was the issue 🙂

    Thread Starter af3

    (@af3)

    Thanks @antoineh

    Thread Starter af3

    (@af3)

    I’m using a very crude way.. I used the plugin “add stats link to matches” to add this link.. $output .= '<span class="match_info"><a href="'.home_url( '/' ).strtolower($match_info['home_team']).'-vs-'.strtolower($match_info['away_team']).'">X</a></span>';
    and create a post with each of the match with the slug above, add fp shortcodes to show the match info manually in that posts, and some other articles.. 🙂 Its manual but it works for now.

    Thread Starter af3

    (@af3)

    Yes, that works, and thanks for providing the matchid on this page. Perhaps in future, can add this as a feature?

    Btw the statistic page doesnt have match id for css 🙁

    Thread Starter af3

    (@af3)

    wohoo, thanks!

    Thread Starter af3

    (@af3)

    I got it! This is cool.
    I added data-title to the SPAN element so that it can be styled in css. Thank you!

    My 2 cents — there is a free API that provide sufficient free data for major football leagues. Of course, users can opt for paid API too. This would be a great addition to this plugin and really expand the plugin.

    https://www.football-data.org/documentation/samples

    Thread Starter af3

    (@af3)

    Wohoo!! This is super awesome.
    I can get the shortcode to show with the question parameter. They look awesome and the tooltip works too. The css option to show/hide is a great idea.

    [fp-question-scores question="2-34" show_total] works but actually show_total was not shown until I changed the strict equal to dbl equal to display the <TD>.

    [fp-question-scores users="1"] is returning empty for me, also with ranges of userids. Still trying to figure out why.

    Anyway, this is a great addition to the FB-Pool plugin. Thank you.

    You can define the match that will be shown in the ranking setup… just click on the Ranking in admin menu, you can define the matches in each of the ranking you’ve created. Quite cool actually 🙂

    If you are using different ranking type for the next round; maybe in admin, try selecting User defined ranking or the ranking for round of 16 ?

    Thread Starter af3

    (@af3)

    At the moment, the plugin finds users with prediction = 0 and questions = 0 and hide them.

    However, if there is a new matchtype where all users have prediction = 0 and question =0 for these particular match type, the plugin displays users that has prediction > 0 and questions >0 from other match type; and hide new users. Can the plugin shows all users if the matchtype has no prediction from any users yet?

    Thread Starter af3

    (@af3)

    Perhaps, Heading could be Q1, Q2, Q3.. it doesnt need the whole questions.

    For the allscore, I rearranged the display like this image (user on heading) because I have less players than the number of matches so the heading are the users instead of matches. The allquestions could then be something like this (image below) but with the Q1, Q2 either as row and users as heading; or vice versa. The full questions can be displayed as tooltip when user hover on the Q1, Q2 etc.

    https://drive.google.com/file/d/1rBYoC8NvmiETJ85440yK9ZmlTDGNHKo_/view?usp=sharing

    Thread Starter af3

    (@af3)

    Ah — it has a plugin !
    https://wordpress.org/support/topic/do-not-show-users-whose-ranking-is-0/

    Except, would like to show these users in the ranking that has no results yet i.e. below this message “No results yet. Below is a list of all users.”.

Viewing 15 replies - 31 through 45 (of 246 total)