Add league taxonomy
This commit is contained in:
@@ -24,8 +24,9 @@ function sportspress_calendar_edit_columns() {
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'title' => __( 'Title' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
'sp_venue' => __( 'Venues', 'sportspress' ),
|
||||
);
|
||||
return $columns;
|
||||
}
|
||||
|
||||
@@ -45,18 +45,33 @@ function sportspress_event_meta_init( $post ) {
|
||||
}
|
||||
|
||||
function sportspress_event_details_meta( $post ) {
|
||||
$league_id = sportspress_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||
$season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||
$venue_id = sportspress_get_the_term_id( $post->ID, 'sp_venue', 0 );
|
||||
?>
|
||||
<div>
|
||||
<p><strong><?php _e( 'League', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'selected' => $league_id,
|
||||
'value' => 'term_id',
|
||||
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Season', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-tab-select" data-sp-target="sp_teamdiv">
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'selected' => $season_id,
|
||||
'value' => 'term_id',
|
||||
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
?>
|
||||
@@ -69,6 +84,7 @@ function sportspress_event_details_meta( $post ) {
|
||||
'name' => 'sp_venue',
|
||||
'selected' => $venue_id,
|
||||
'value' => 'term_id',
|
||||
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
?>
|
||||
@@ -79,7 +95,6 @@ function sportspress_event_details_meta( $post ) {
|
||||
|
||||
function sportspress_event_team_meta( $post ) {
|
||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
|
||||
foreach ( $teams as $key => $value ):
|
||||
?>
|
||||
<div class="sp-clone">
|
||||
@@ -177,8 +192,9 @@ function sportspress_event_edit_columns() {
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'title' => __( 'Event', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
'sp_venue' => __( 'Venues', 'sportspress' ),
|
||||
'sp_league' => __( 'League', 'sportspress' ),
|
||||
'sp_season' => __( 'Season', 'sportspress' ),
|
||||
'sp_venue' => __( 'Venue', 'sportspress' ),
|
||||
'sp_kickoff' => __( 'Date/Time', 'sportspress' )
|
||||
);
|
||||
return $columns;
|
||||
|
||||
@@ -25,8 +25,9 @@ function sportspress_list_edit_columns() {
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'title' => __( 'Title' ),
|
||||
'sp_player' => __( 'Players', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' )
|
||||
'sp_league' => __( 'League', 'sportspress' ),
|
||||
'sp_season' => __( 'Season', 'sportspress' ),
|
||||
'sp_team' => __( 'Team', 'sportspress' ),
|
||||
);
|
||||
return $columns;
|
||||
}
|
||||
@@ -44,10 +45,23 @@ function sportspress_list_meta_init( $post ) {
|
||||
}
|
||||
|
||||
function sportspress_list_player_meta( $post ) {
|
||||
$league_id = sportspress_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||
$season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||
$team_id = get_post_meta( $post->ID, 'sp_team', true );
|
||||
?>
|
||||
<div>
|
||||
<p><strong><?php _e( 'League', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'selected' => $league_id,
|
||||
'value' => 'term_id'
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Season', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-tab-select">
|
||||
<?php
|
||||
|
||||
@@ -25,6 +25,7 @@ function sportspress_player_edit_columns() {
|
||||
'title' => __( 'Name', 'sportspress' ),
|
||||
'sp_position' => __( 'Positions', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
);
|
||||
return $columns;
|
||||
@@ -32,12 +33,9 @@ function sportspress_player_edit_columns() {
|
||||
add_filter( 'manage_edit-sp_player_columns', 'sportspress_player_edit_columns' );
|
||||
|
||||
function sportspress_player_meta_init( $post ) {
|
||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
||||
$seasons = (array)get_the_terms( $post->ID, 'sp_season' );
|
||||
|
||||
// First one is empty
|
||||
unset( $teams[0] );
|
||||
|
||||
remove_meta_box( 'submitdiv', 'sp_player', 'side' );
|
||||
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_player', 'side', 'high' );
|
||||
remove_meta_box( 'postimagediv', 'sp_player', 'side' );
|
||||
@@ -45,7 +43,7 @@ function sportspress_player_meta_init( $post ) {
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_player_details_meta', 'sp_player', 'side', 'high' );
|
||||
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_player_team_meta', 'sp_player', 'side', 'high' );
|
||||
|
||||
if ( $teams && ! empty( $teams ) && $seasons && is_array( $seasons ) && is_object( $seasons[0] ) ):
|
||||
if ( $leagues && ! empty( $leagues ) && $seasons && is_array( $seasons ) && is_object( $seasons[0] ) ):
|
||||
add_meta_box( 'sp_statsdiv', __( 'Player Statistics', 'sportspress' ), 'sportspress_player_stats_meta', 'sp_player', 'normal', 'high' );
|
||||
endif;
|
||||
|
||||
@@ -98,28 +96,22 @@ function sportspress_player_team_meta( $post ) {
|
||||
}
|
||||
|
||||
function sportspress_player_stats_meta( $post ) {
|
||||
$team_ids = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
||||
|
||||
// First one is empty
|
||||
unset( $team_ids[0] );
|
||||
$league_num = sizeof( $leagues );
|
||||
|
||||
// Initialize placeholders array
|
||||
$placeholders = array();
|
||||
|
||||
$team_num = sizeof( $team_ids );
|
||||
|
||||
// Loop through statistics for each team
|
||||
foreach ( $team_ids as $team_id ):
|
||||
// Loop through statistics for each league
|
||||
foreach ( $leagues as $league ):
|
||||
|
||||
if ( $team_num > 1 ):
|
||||
if ( $league_num > 1 ):
|
||||
?>
|
||||
<p><strong><?php echo get_the_title( $team_id ); ?></strong></p>
|
||||
<p><strong><?php echo $league->name; ?></strong></p>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_player_statistics_data( $post->ID, $team_id, true );
|
||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_player_statistics_data( $post->ID, $league->term_id, true );
|
||||
|
||||
sportspress_edit_player_statistics_table( $team_id, $columns, $data, $placeholders );
|
||||
sportspress_edit_player_statistics_table( $league->term_id, $columns, $data, $placeholders );
|
||||
|
||||
endforeach;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ function sportspress_staff_edit_columns() {
|
||||
'title' => __( 'Name', 'sportspress' ),
|
||||
'sp_position' => __( 'Positions', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
);
|
||||
return $columns;
|
||||
|
||||
@@ -24,8 +24,9 @@ function sportspress_table_edit_columns() {
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'title' => __( 'Title' ),
|
||||
'sp_league' => __( 'League', 'sportspress' ),
|
||||
'sp_season' => __( 'Season', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
);
|
||||
return $columns;
|
||||
}
|
||||
@@ -43,20 +44,35 @@ function sportspress_table_meta_init( $post ) {
|
||||
}
|
||||
|
||||
function sportspress_table_team_meta( $post, $test ) {
|
||||
$league_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||
$league_id = sportspress_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||
$season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||
?>
|
||||
<div>
|
||||
<p class="sp-tab-select">
|
||||
<p><strong><?php _e( 'League', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'selected' => $league_id,
|
||||
'value' => 'term_id'
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Season', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-tab-select">
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'selected' => $season_id,
|
||||
'value' => 'term_id'
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Teams', 'sportspress' ); ?></strong></p>
|
||||
<?php
|
||||
sportspress_post_checklist( $post->ID, 'sp_team', 'block', 'sp_season' );
|
||||
sportspress_post_adder( 'sp_team' );
|
||||
|
||||
@@ -20,14 +20,15 @@ function sportspress_team_post_init() {
|
||||
add_action( 'init', 'sportspress_team_post_init' );
|
||||
|
||||
function sportspress_team_meta_init( $post ) {
|
||||
$leagues = (array)get_the_terms( $post->ID, 'sp_season' );
|
||||
$leagues = (array)get_the_terms( $post->ID, 'sp_league' );
|
||||
$seasons = (array)get_the_terms( $post->ID, 'sp_season' );
|
||||
|
||||
remove_meta_box( 'submitdiv', 'sp_team', 'side' );
|
||||
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_team', 'side', 'high' );
|
||||
remove_meta_box( 'postimagediv', 'sp_team', 'side' );
|
||||
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
|
||||
|
||||
if ( $leagues && $leagues != array(0) ):
|
||||
if ( $leagues && $leagues != array(0) && $seasons && $seasons != array(0) ):
|
||||
add_meta_box( 'sp_columnssdiv', __( 'Table Columns', 'sportspress' ), 'sportspress_team_columns_meta', 'sp_team', 'normal', 'high' );
|
||||
endif;
|
||||
}
|
||||
@@ -37,165 +38,32 @@ function sportspress_team_edit_columns() {
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'sp_logo' => ' ',
|
||||
'title' => __( 'Team', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' )
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
);
|
||||
return $columns;
|
||||
}
|
||||
add_filter( 'manage_edit-sp_team_columns', 'sportspress_team_edit_columns' );
|
||||
|
||||
function sportspress_team_columns_meta( $post ) {
|
||||
$leagues = (array)get_the_terms( $post->ID, 'sp_season' );
|
||||
$columns = (array)get_post_meta( $post->ID, 'sp_columns', true );
|
||||
$leagues = (array)get_the_terms( $post->ID, 'sp_league' );
|
||||
|
||||
// Equation Operating System
|
||||
$eos = new eqEOS();
|
||||
$league_num = sizeof( $leagues );
|
||||
|
||||
// Get labels from result variables
|
||||
$result_labels = (array)sportspress_get_var_labels( 'sp_result' );
|
||||
|
||||
// Get labels from outcome variables
|
||||
$outcome_labels = (array)sportspress_get_var_labels( 'sp_outcome' );
|
||||
|
||||
// Generate array of all league ids
|
||||
$div_ids = array();
|
||||
foreach ( $leagues as $key => $value ):
|
||||
if ( is_object( $value ) && property_exists( $value, 'term_id' ) )
|
||||
$div_ids[] = $value->term_id;
|
||||
endforeach;
|
||||
|
||||
// Get all leagues populated with columns where available
|
||||
$data = sportspress_array_combine( $div_ids, $columns );
|
||||
|
||||
// Get equations from column variables
|
||||
$equations = sportspress_get_var_equations( 'sp_column' );
|
||||
|
||||
// Initialize placeholders array
|
||||
$placeholders = array();
|
||||
|
||||
foreach ( $div_ids as $div_id ):
|
||||
|
||||
$totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last10' => null );
|
||||
|
||||
foreach ( $result_labels as $key => $value ):
|
||||
$totals[ $key . 'for' ] = 0;
|
||||
$totals[ $key . 'against' ] = 0;
|
||||
endforeach;
|
||||
|
||||
foreach ( $outcome_labels as $key => $value ):
|
||||
$totals[ $key ] = 0;
|
||||
endforeach;
|
||||
|
||||
// Initialize streaks counter
|
||||
$streak = array( 'name' => '', 'count' => 0, 'fire' => 1 );
|
||||
|
||||
// Initialize last 10 counter
|
||||
$last10 = array();
|
||||
|
||||
// Add outcome types to last 10 counter
|
||||
foreach( $outcome_labels as $key => $value ):
|
||||
$last10[ $key ] = 0;
|
||||
endforeach;
|
||||
|
||||
// Get all events involving the team in current season
|
||||
$args = array(
|
||||
'post_type' => 'sp_event',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'order' => 'ASC',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'sp_team',
|
||||
'value' => $post->ID
|
||||
)
|
||||
),
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'field' => 'id',
|
||||
'terms' => $div_id
|
||||
)
|
||||
)
|
||||
);
|
||||
$events = get_posts( $args );
|
||||
|
||||
foreach( $events as $event ):
|
||||
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
||||
foreach ( $results as $team_id => $team_result ):
|
||||
foreach ( $team_result as $key => $value ):
|
||||
if ( $team_id == $post->ID ):
|
||||
if ( $key == 'outcome' ):
|
||||
|
||||
// Increment events played and outcome count
|
||||
if ( array_key_exists( $value, $totals ) ):
|
||||
$totals['eventsplayed']++;
|
||||
$totals[ $value ]++;
|
||||
endif;
|
||||
|
||||
if ( $value && $value != '-1' ):
|
||||
|
||||
// Add to streak counter
|
||||
if ( $streak['fire'] && ( $streak['name'] == '' || $streak['name'] == $value ) ):
|
||||
$streak['name'] = $value;
|
||||
$streak['count'] ++;
|
||||
else:
|
||||
$streak['fire'] = 0;
|
||||
endif;
|
||||
|
||||
// Add to last 10 counter if sum is less than 10
|
||||
if ( array_key_exists( $value, $last10 ) && array_sum( $last10 ) < 10 ):
|
||||
$last10[ $value ] ++;
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
else:
|
||||
if ( array_key_exists( $key . 'for', $totals ) ):
|
||||
$totals[ $key . 'for' ] += $value;
|
||||
endif;
|
||||
endif;
|
||||
else:
|
||||
if ( $key != 'outcome' ):
|
||||
if ( array_key_exists( $key . 'against', $totals ) ):
|
||||
$totals[ $key . 'against' ] += $value;
|
||||
endif;
|
||||
endif;
|
||||
endif;
|
||||
endforeach;
|
||||
endforeach;
|
||||
endforeach;
|
||||
|
||||
// Compile streaks counter and add to totals
|
||||
$args=array(
|
||||
'name' => $streak['name'],
|
||||
'post_type' => 'sp_outcome',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1
|
||||
);
|
||||
$outcomes = get_posts( $args );
|
||||
|
||||
if ( $outcomes ):
|
||||
$outcome = $outcomes[0];
|
||||
$totals['streak'] = $outcome->post_title . $streak['count'];
|
||||
// Loop through statistics for each league
|
||||
foreach ( $leagues as $league ):
|
||||
|
||||
if ( $league_num > 1 ):
|
||||
?>
|
||||
<p><strong><?php echo $league->name; ?></strong></p>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
// Add last 10 to totals
|
||||
$totals['last10'] = $last10;
|
||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_team_columns_data( $post->ID, $league->term_id, true );
|
||||
|
||||
// Generate array of placeholder values for each league
|
||||
$placeholders[ $div_id ] = array();
|
||||
foreach ( $equations as $key => $value ):
|
||||
if ( $totals['eventsplayed'] > 0 ):
|
||||
$placeholders[ $div_id ][ $key ] = sportspress_solve( $value, $totals );
|
||||
else:
|
||||
$placeholders[ $div_id ][ $key ] = 0;
|
||||
endif;
|
||||
endforeach;
|
||||
sportspress_edit_team_columns_table( $columns, $data, $placeholders );
|
||||
|
||||
endforeach;
|
||||
|
||||
// Get columns from statistics variables
|
||||
$columns = sportspress_get_var_labels( 'sp_column' );
|
||||
|
||||
sportspress_edit_team_columns_table( $columns, $data, $placeholders );
|
||||
sportspress_nonce();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user