Add main result, last 5 counter, and fix countdown direction

This commit is contained in:
Brian Miyaji
2014-02-06 17:47:49 +11:00
parent 1c0bc6a468
commit a53619b2d8
10 changed files with 205 additions and 28 deletions

View File

@@ -29,12 +29,28 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
break; break;
elseif ( $post_type == 'sp_event' ): elseif ( $post_type == 'sp_event' ):
$results = get_post_meta( $post_id, 'sp_results', true ); $results = get_post_meta( $post_id, 'sp_results', true );
$options = get_option( 'sportspress' );
$main_result = sportspress_array_value( $options, 'main_result', null );
foreach( $teams as $team_id ): foreach( $teams as $team_id ):
if ( ! $team_id ) continue; if ( ! $team_id ) continue;
$team = get_post( $team_id ); $team = get_post( $team_id );
$outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
echo $team->post_title; echo $team->post_title;
$team_results = sportspress_array_value( $results, $team_id, null );
if ( $main_result ):
$team_result = sportspress_array_value( $team_results, $main_result, null );
else:
end( $team_results );
$team_result = prev( $team_results );
endif;
if ( $team_result != null ):
echo ' — ' . $team_result;
endif;
$outcome_slug = sportspress_array_value( $team_results, 'outcome', null );
if ( $outcome_slug && $outcome_slug != '-1' ): if ( $outcome_slug && $outcome_slug != '-1' ):
$args=array( $args=array(
'name' => $outcome_slug, 'name' => $outcome_slug,
@@ -46,9 +62,10 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
if ( sizeof( $outcomes ) ): if ( sizeof( $outcomes ) ):
$outcome = reset( $outcomes ); $outcome = reset( $outcomes );
echo ' — ' . $outcome->post_title; echo ' (' . $outcome->post_title . ')';
endif; endif;
endif; endif;
echo '<br>'; echo '<br>';
endforeach; endforeach;
elseif ( $post_type == 'sp_player' ): elseif ( $post_type == 'sp_player' ):

View File

@@ -1,6 +1,7 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<?php if ( false ): ?>
<div id="message" class="error sportspress-message"> <div id="message" class="error sportspress-message">
<h4><?php _e( '<strong>Your theme does not declare SportsPress support</strong> &#8211; if you encounter layout issues please read our integration guide or choose a SportsPress theme :)', 'sportspress' ); ?></h4> <h4><?php _e( '<strong>Your theme does not declare SportsPress support</strong> &#8211; if you encounter layout issues please read our integration guide or choose a SportsPress theme :)', 'sportspress' ); ?></h4>
<p class="submit"> <p class="submit">
@@ -8,3 +9,4 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<a class="button-secondary" href="<?php echo add_query_arg( 'hide_sportspress_theme_support_check', 'true' ); ?>"><?php _e( 'Hide this notice', 'sportspress' ); ?></a> <a class="button-secondary" href="<?php echo add_query_arg( 'hide_sportspress_theme_support_check', 'true' ); ?>"><?php _e( 'Hide this notice', 'sportspress' ); ?></a>
</p> </p>
</div> </div>
<?php endif;

View File

@@ -20,6 +20,13 @@ $sportspress_sports['football'] = array(
'sp_equation' => '$l', 'sp_equation' => '$l',
), ),
), ),
array(
'post_title' => 'T',
'post_name' => 't',
'meta' => array(
'sp_equation' => '$t',
),
),
array( array(
'post_title' => 'Pct', 'post_title' => 'Pct',
'post_name' => 'pct', 'post_name' => 'pct',
@@ -31,26 +38,123 @@ $sportspress_sports['football'] = array(
'post_title' => 'PF', 'post_title' => 'PF',
'post_name' => 'pf', 'post_name' => 'pf',
'meta' => array( 'meta' => array(
'sp_equation' => '$ptsfor', 'sp_equation' => '$pointsfor',
), ),
), ),
array( array(
'post_title' => 'PA', 'post_title' => 'PA',
'post_name' => 'pa', 'post_name' => 'pa',
'meta' => array( 'meta' => array(
'sp_equation' => '$ptsagainst', 'sp_equation' => '$pointsagainst',
), ),
), ),
array( array(
'post_title' => 'Str', 'post_title' => 'Net Pts',
'post_name' => 'netpts',
'meta' => array(
'sp_equation' => '$pointsfor - $pointsagainst',
),
),
array(
'post_title' => 'TD',
'post_name' => 'td',
'meta' => array(
'sp_equation' => '$touchdown',
),
),
array(
'post_title' => 'Strk',
'post_name' => 'strk', 'post_name' => 'strk',
'meta' => array( 'meta' => array(
'sp_equation' => '$streak', 'sp_equation' => '$streak',
), ),
), ),
array(
'post_title' => 'Last 5',
'post_name' => 'last5',
'meta' => array(
'sp_equation' => '$last5',
),
),
), ),
// Statistics // Statistics
'sp_statistic' => array( 'sp_statistic' => array(
array(
'post_title' => 'Comp',
'post_name' => 'comp', // QB
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
array(
'post_title' => 'Comp',
'post_name' => 'comp',
),
), ),
// Results // Results
'sp_result' => array( 'sp_result' => array(

View File

@@ -1,4 +1,9 @@
<h3 class="title"><?php _e( 'Event Settings', 'sportspress' ); ?></h3>
<?php <?php
settings_fields( 'sportspress_events' );
do_settings_sections( 'sportspress_events' );
submit_button();
$args = array( $args = array(
'post_type' => 'sp_result', 'post_type' => 'sp_result',
'numberposts' => -1, 'numberposts' => -1,

View File

@@ -38,15 +38,31 @@ function sportspress_settings() {
function sportspress_sport_callback() { function sportspress_sport_callback() {
global $sportspress_sports; global $sportspress_sports;
$options = get_option( 'sportspress' ); $options = get_option( 'sportspress' );
$selected = sportspress_array_value( $options, 'sport', null );
?> ?>
<select id="sportspress_sport" name="sportspress[sport]"> <select id="sportspress_sport" name="sportspress[sport]">
<?php foreach( $sportspress_sports as $slug => $sport ): ?> <?php foreach( $sportspress_sports as $slug => $sport ): ?>
<option value="<?php echo $slug; ?>" <?php selected( $options['sport'], $slug ); ?>><?php echo $sport['name']; ?></option> <option value="<?php echo $slug; ?>" <?php selected( $selected, $slug ); ?>><?php echo $sport['name']; ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<?php <?php
} }
function sportspress_result_callback() {
$options = get_option( 'sportspress' );
$selected = sportspress_array_value( $options, 'main_result', null );
$args = array(
'post_type' => 'sp_result',
'name' => 'sportspress[main_result]',
'show_option_all' => __( '(Auto)', 'sportspress' ),
'selected' => $selected,
'values' => 'slug',
);
sportspress_dropdown_pages( $args );
}
function sportspress_team_stats_callback() { function sportspress_team_stats_callback() {
sportspress_render_option_field( 'sportspress_stats', 'team', 'textarea' ); sportspress_render_option_field( 'sportspress_stats', 'team', 'textarea' );
} }
@@ -88,8 +104,7 @@ function sportspress_settings_init() {
// Event Settings // Event Settings
register_setting( register_setting(
'sportspress_events', 'sportspress_events',
'sportspress', 'sportspress'
'sportspress_validate'
); );
add_settings_section( add_settings_section(
@@ -100,9 +115,9 @@ function sportspress_settings_init() {
); );
add_settings_field( add_settings_field(
'sport', 'result',
__( 'Sport', 'sportspress' ), __( 'Main Result', 'sportspress' ),
'sportspress_sport_callback', 'sportspress_result_callback',
'sportspress_events', 'sportspress_events',
'events' 'events'
); );

View File

@@ -37,13 +37,13 @@ if ( !function_exists( 'sportspress_countdown' ) ) {
$now = new DateTime( current_time( 'mysql', 0 ) ); $now = new DateTime( current_time( 'mysql', 0 ) );
$date = new DateTime( $post->post_date ); $date = new DateTime( $post->post_date );
$interval = $date->diff( $now ); $interval = date_diff( $now, $date );
$output .= '<h3 class="countdown sp-countdown"><time datetime="' . $post->post_date . '" data-countdown="' . str_replace( '-', '/', $post->post_date ) . '">' . $output .= '<h3 class="countdown sp-countdown"><time datetime="' . $post->post_date . '" data-countdown="' . str_replace( '-', '/', $post->post_date ) . '">' .
'<span>' . sprintf( '%02s', $interval->d ) . ' <small>' . __( 'days', 'sportspress' ) . '</small></span> ' . '<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->d ) ) . ' <small>' . __( 'days', 'sportspress' ) . '</small></span> ' .
'<span>' . sprintf( '%02s', $interval->h ) . ' <small>' . __( 'hours', 'sportspress' ) . '</small></span> ' . '<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->h ) ) . ' <small>' . __( 'hours', 'sportspress' ) . '</small></span> ' .
'<span>' . sprintf( '%02s', $interval->i ) . ' <small>' . __( 'mins', 'sportspress' ) . '</small></span> ' . '<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->i ) ) . ' <small>' . __( 'mins', 'sportspress' ) . '</small></span> ' .
'<span>' . sprintf( '%02s', $interval->s ) . ' <small>' . __( 'secs', 'sportspress' ) . '</small></span>' . '<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->s ) ) . ' <small>' . __( 'secs', 'sportspress' ) . '</small></span>' .
'</time></h3>'; '</time></h3>';
$output .= '</div>'; $output .= '</div>';

View File

@@ -40,7 +40,7 @@ class SP_Widget_Countdown extends WP_Widget {
'name' => $this->get_field_name('id'), 'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'), 'id' => $this->get_field_id('id'),
'selected' => $id, 'selected' => $id,
'show_option_all' => '(' . __( 'Next Event', 'premier' ) . ')', 'show_option_all' => __( '(Auto)', 'sportspress' ),
'values' => 'ID', 'values' => 'ID',
'class' => 'widefat', 'class' => 'widefat',
'show_dates' => true, 'show_dates' => true,

View File

@@ -491,6 +491,7 @@ if ( !function_exists( 'sportspress_equation_selector' ) ) {
case 'outcome': case 'outcome':
$options[ __( 'Outcomes', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '&uarr;', 'min' => '&darr;' ) ); $options[ __( 'Outcomes', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '&uarr;', 'min' => '&darr;' ) );
$options[ __( 'Outcomes', 'sportspress' ) ]['$streak'] = __( 'Streak', 'sportspress' ); $options[ __( 'Outcomes', 'sportspress' ) ]['$streak'] = __( 'Streak', 'sportspress' );
$options[ __( 'Outcomes', 'sportspress' ) ]['$last5'] = __( 'Last 5', 'sportspress' );
$options[ __( 'Outcomes', 'sportspress' ) ]['$last10'] = __( 'Last 10', 'sportspress' ); $options[ __( 'Outcomes', 'sportspress' ) ]['$last10'] = __( 'Last 10', 'sportspress' );
break; break;
case 'column': case 'column':
@@ -1151,6 +1152,16 @@ if ( !function_exists( 'sportspress_solve' ) ) {
// Return direct value // Return direct value
return sportspress_array_value( $vars, 'streak', 0 ); return sportspress_array_value( $vars, 'streak', 0 );
elseif ( str_replace( ' ', '', $equation ) == '$last5' ):
// Return imploded string
$last5 = sportspress_array_value( $vars, 'last5', array( 0 ) );
if ( array_sum( $last5 ) > 0 ):
return implode( '-', $last5 );
else:
return '&mdash;';
endif;
elseif ( str_replace( ' ', '', $equation ) == '$last10' ): elseif ( str_replace( ' ', '', $equation ) == '$last10' ):
// Return imploded string // Return imploded string
@@ -1306,7 +1317,7 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) {
foreach ( $div_ids as $div_id ): foreach ( $div_ids as $div_id ):
$totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last10' => null ); $totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last5' => null, 'last10' => null );
foreach ( $result_labels as $key => $value ): foreach ( $result_labels as $key => $value ):
$totals[ $key . 'for' ] = 0; $totals[ $key . 'for' ] = 0;
@@ -1320,11 +1331,13 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) {
// Initialize streaks counter // Initialize streaks counter
$streak = array( 'name' => '', 'count' => 0, 'fire' => 1 ); $streak = array( 'name' => '', 'count' => 0, 'fire' => 1 );
// Initialize last 10 counter // Initialize last counters
$last5 = array();
$last10 = array(); $last10 = array();
// Add outcome types to last 10 counter // Add outcome types to last counters
foreach( $outcome_labels as $key => $value ): foreach( $outcome_labels as $key => $value ):
$last5[ $key ] = 0;
$last10[ $key ] = 0; $last10[ $key ] = 0;
endforeach; endforeach;
@@ -1379,6 +1392,11 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) {
$streak['fire'] = 0; $streak['fire'] = 0;
endif; endif;
// Add to last 5 counter if sum is less than 5
if ( array_key_exists( $value, $last5 ) && array_sum( $last5 ) < 5 ):
$last5[ $value ] ++;
endif;
// Add to last 10 counter if sum is less than 10 // Add to last 10 counter if sum is less than 10
if ( array_key_exists( $value, $last10 ) && array_sum( $last10 ) < 10 ): if ( array_key_exists( $value, $last10 ) && array_sum( $last10 ) < 10 ):
$last10[ $value ] ++; $last10[ $value ] ++;
@@ -1416,7 +1434,8 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) {
$totals['streak'] = $outcome->post_title . $streak['count']; $totals['streak'] = $outcome->post_title . $streak['count'];
endif; endif;
// Add last 10 to totals // Add last counters to totals
$totals['last5'] = $last5;
$totals['last10'] = $last10; $totals['last10'] = $last10;
// Generate array of placeholder values for each league // Generate array of placeholder values for each league
@@ -1497,7 +1516,8 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
// Initialize streaks counter // Initialize streaks counter
$streaks = array(); $streaks = array();
// Initialize last 10s counter // Initialize last counters
$last5s = array();
$last10s = array(); $last10s = array();
foreach ( $team_ids as $team_id ): foreach ( $team_ids as $team_id ):
@@ -1507,11 +1527,13 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
// Initialize team streaks counter // Initialize team streaks counter
$streaks[ $team_id ] = array( 'name' => '', 'count' => 0, 'fire' => 1 ); $streaks[ $team_id ] = array( 'name' => '', 'count' => 0, 'fire' => 1 );
// Initialize team last 10 counter // Initialize team last counters
$last5s[ $team_id ] = array();
$last10s[ $team_id ] = array(); $last10s[ $team_id ] = array();
// Add outcome types to team last 10 counter // Add outcome types to team last counters
foreach( $outcome_labels as $key => $value ): foreach( $outcome_labels as $key => $value ):
$last5s[ $team_id ][ $key ] = 0;
$last10s[ $team_id ][ $key ] = 0; $last10s[ $team_id ][ $key ] = 0;
endforeach; endforeach;
@@ -1586,6 +1608,11 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
$streaks[ $team_id ]['fire'] = 0; $streaks[ $team_id ]['fire'] = 0;
endif; endif;
// Add to last 5 counter if sum is less than 5
if ( array_key_exists( $team_id, $last5s ) && array_key_exists( $value, $last5s[ $team_id ] ) && array_sum( $last5s[ $team_id ] ) < 5 ):
$last5s[ $team_id ][ $value ] ++;
endif;
// Add to last 10 counter if sum is less than 10 // Add to last 10 counter if sum is less than 10
if ( array_key_exists( $team_id, $last10s ) && array_key_exists( $value, $last10s[ $team_id ] ) && array_sum( $last10s[ $team_id ] ) < 10 ): if ( array_key_exists( $team_id, $last10s ) && array_key_exists( $value, $last10s[ $team_id ] ) && array_sum( $last10s[ $team_id ] ) < 10 ):
$last10s[ $team_id ][ $value ] ++; $last10s[ $team_id ][ $value ] ++;
@@ -1632,6 +1659,11 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
endif; endif;
endforeach; endforeach;
foreach ( $last5s as $team_id => $last5 ):
// Add last 5 to totals
$totals[ $team_id ]['last5'] = $last5;
endforeach;
foreach ( $last10s as $team_id => $last10 ): foreach ( $last10s as $team_id => $last10 ):
// Add last 10 to totals // Add last 10 to totals
$totals[ $team_id ]['last10'] = $last10; $totals[ $team_id ]['last10'] = $last10;

View File

@@ -74,9 +74,11 @@ SportsPress is currently in beta and is undergoing testing. We are still activel
= 0.2.2 = = 0.2.2 =
* Feature - League Table widget added. * Feature - League Table widget added.
* Feature - Events widget added. * Feature - Recent Events widget added.
* Feature - Future Events widget added.
* Feature - Countdown widget added. * Feature - Countdown widget added.
* Fix - Syntax error fixed for PHP version 5.2 and below. * Fix - Syntax error fixed for PHP version 5.2 and below.
* Tweak - Editor section added to League Tables and Player Lists.
= 0.2.1 = = 0.2.1 =
* Feature - Events Calendar widget added. * Feature - Events Calendar widget added.