',
'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;
diff --git a/admin/post-types/list.php b/admin/post-types/list.php
index c57fb62f..4bedf9d0 100644
--- a/admin/post-types/list.php
+++ b/admin/post-types/list.php
@@ -25,8 +25,9 @@ function sportspress_list_edit_columns() {
'cb' => '
',
'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 );
?>
+
+
+ 'sp_league',
+ 'name' => 'sp_league',
+ 'selected' => $league_id,
+ 'value' => 'term_id'
+ );
+ sportspress_dropdown_taxonomies( $args );
+ ?>
+
__( '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 ):
?>
-
+
name; ?>
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;
}
diff --git a/admin/post-types/staff.php b/admin/post-types/staff.php
index fa369e94..f73d8f8d 100644
--- a/admin/post-types/staff.php
+++ b/admin/post-types/staff.php
@@ -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;
diff --git a/admin/post-types/table.php b/admin/post-types/table.php
index 4c99a7da..f11d5aba 100644
--- a/admin/post-types/table.php
+++ b/admin/post-types/table.php
@@ -24,8 +24,9 @@ function sportspress_table_edit_columns() {
$columns = array(
'cb' => '
',
'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 );
?>
-
+
+
'sp_season',
- 'name' => 'sp_season',
+ 'taxonomy' => 'sp_league',
+ 'name' => 'sp_league',
'selected' => $league_id,
'value' => 'term_id'
);
sportspress_dropdown_taxonomies( $args );
?>
+
+
+ 'sp_season',
+ 'name' => 'sp_season',
+ 'selected' => $season_id,
+ 'value' => 'term_id'
+ );
+ sportspress_dropdown_taxonomies( $args );
+ ?>
+
+
ID, 'sp_team', 'block', 'sp_season' );
sportspress_post_adder( 'sp_team' );
diff --git a/admin/post-types/team.php b/admin/post-types/team.php
index c088eca9..873cbc1c 100644
--- a/admin/post-types/team.php
+++ b/admin/post-types/team.php
@@ -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' => '
',
'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 ):
+ ?>
+
name; ?>
+ 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();
}
diff --git a/admin/terms/league.php b/admin/terms/league.php
new file mode 100644
index 00000000..7bfa1659
--- /dev/null
+++ b/admin/terms/league.php
@@ -0,0 +1,21 @@
+ $name,
+ 'labels' => $labels,
+ 'public' => true,
+ 'hierarchical' => true,
+ 'rewrite' => array( 'slug' => 'league' )
+ );
+ register_taxonomy( 'sp_league', $object_type, $args );
+ register_taxonomy_for_object_type( 'sp_league', 'sp_calendar' );
+ register_taxonomy_for_object_type( 'sp_league', 'sp_team' );
+ register_taxonomy_for_object_type( 'sp_league', 'sp_player' );
+ register_taxonomy_for_object_type( 'sp_league', 'sp_staff' );
+}
+add_action( 'init', 'sportspress_league_term_init' );
diff --git a/functions.php b/functions.php
index e10e9fe7..fb594e52 100644
--- a/functions.php
+++ b/functions.php
@@ -1,4 +1,153 @@
$team_id ):
+ if ( ! $team_id ) continue;
+
+ // Get results for players in the team
+ $players = sportspress_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key );
+ $data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) );
+
+ $output .= '
' . get_the_title( $team_id ) . ' ';
+
+ $output .= '
' . '' . '';
+
+ $output .= '' . __( '#', 'sportspress' ) . ' ';
+ $output .= '' . __( 'Player', 'sportspress' ) . ' ';
+
+ foreach( $statistic_labels as $key => $label ):
+ $output .= '' . $label . ' ';
+ endforeach;
+
+ $output .= ' ' . ' ' . '';
+
+ $i = 0;
+
+ foreach( $data as $player_id => $row ):
+
+ if ( ! $player_id )
+ continue;
+
+ $output .= '';
+
+ $number = get_post_meta( $player_id, 'sp_number', true );
+
+ // Player number
+ $output .= '' . $number . ' ';
+
+ // Name as link
+ $permalink = get_post_permalink( $player_id );
+ $name = get_the_title( $player_id );
+ $output .= '' . '' . $name . ' ';
+
+ foreach( $statistic_labels as $key => $label ):
+ if ( $key == 'name' )
+ continue;
+ if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
+ $value = $row[ $key ];
+ else:
+ $value = 0;
+ endif;
+ $output .= '' . $value . ' ';
+ endforeach;
+
+ $output .= ' ';
+
+ $i++;
+
+ endforeach;
+
+ $output .= ' ';
+
+ if ( array_key_exists( 0, $data ) ):
+
+ $output .= '';
+
+ $number = get_post_meta( $player_id, 'sp_number', true );
+
+ // Player number
+ $output .= ' ';
+ $output .= '' . __( 'Total', 'sportspress' ) . ' ';
+
+ $row = $data[0];
+
+ foreach( $statistic_labels as $key => $label ):
+ if ( $key == 'name' ):
+ continue;
+ endif;
+ $output .= '' . sportspress_array_value( $row, $key, '—' ) . ' ';
+ endforeach;
+
+ $output .= ' ';
+
+ endif;
+
+ $output .= '
';
+
+ endforeach;
+
+ // Initialize and check
+ $table_rows = '';
+
+ $i = 0;
+
+ foreach( $results as $team_id => $result ):
+ if ( sportspress_array_value( $result, 'outcome', '-1' ) != '-1' ):
+
+ unset( $result['outcome'] );
+
+ $table_rows .= '
';
+
+ $table_rows .= '' . get_the_title( $team_id ) . ' ';
+
+ foreach( $result_labels as $key => $label ):
+ if ( $key == 'name' )
+ continue;
+ if ( array_key_exists( $key, $result ) && $result[ $key ] != '' ):
+ $value = $result[ $key ];
+ else:
+ $value = '—';
+ endif;
+ $table_rows .= '' . $value . ' ';
+ endforeach;
+
+ $table_rows .= ' ';
+
+ $i++;
+
+ endif;
+ endforeach;
+
+ if ( ! empty( $table_rows ) ):
+
+ $output .= '
' . __( 'Results', 'sportspress' ) . ' ';
+
+ $output .= '
';
+ $output .= '' . __( 'Team', 'sportspress' ) . ' ';
+ foreach( $result_labels as $key => $label ):
+ $output .= '' . $label . ' ';
+ endforeach;
+ $output .= '' . ' ' . '';
+ $output .= $table_rows;
+ $output .= '
';
+
+ endif;
+
+ return $output;
+
+ }
+}
+
if ( !function_exists( 'sportspress_league_table' ) ) {
function sportspress_league_table( $id ) {
@@ -23,7 +172,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
foreach( $data as $team_id => $row ):
- $output .= '
';
+ $output .= ' ';
// Position as number
$output .= '' . $i . ' ';
@@ -53,6 +202,62 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
}
}
+
+if ( !function_exists( 'sportspress_team_columns' ) ) {
+ function sportspress_team_columns( $id ) {
+
+ $leagues = get_the_terms( $id, 'sp_league' );
+
+ $output = '';
+
+ // Loop through data for each league
+ foreach ( $leagues as $league ):
+
+ if ( sizeof( $leagues ) > 1 )
+ $output .= '' . $league->name . ' ';
+
+ $data = sportspress_get_team_columns_data( $id, $league->term_id );
+
+ // The first row should be column labels
+ $labels = $data[0];
+
+ // Remove the first row to leave us with the actual data
+ unset( $data[0] );
+
+ $output .= '' . '' . '';
+
+ foreach( $labels as $key => $label ):
+ $output .= '' . $label . ' ';
+ endforeach;
+
+ $output .= ' ' . ' ' . '';
+
+ $i = 0;
+
+ foreach( $data as $season_id => $row ):
+
+ $output .= '';
+
+ foreach( $labels as $key => $value ):
+ $output .= '' . sportspress_array_value( $row, $key, '—' ) . ' ';
+ endforeach;
+
+ $output .= ' ';
+
+ $i++;
+
+ endforeach;
+
+ $output .= ' ' . '
';
+
+
+ endforeach;
+
+ return $output;
+
+ }
+}
+
if ( !function_exists( 'sportspress_player_list' ) ) {
function sportspress_player_list( $id ) {
@@ -77,7 +282,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
foreach( $data as $player_id => $row ):
- $output .= ' ';
+ $output .= ' ';
// Player number
$number = get_post_meta( $player_id, 'sp_number', true );
@@ -131,7 +336,7 @@ if ( !function_exists( 'sportspress_player_metrics' ) ) {
foreach( $data as $label => $value ):
- $output .= ' ' . $label . ' ' . $value . ' ';
+ $output .= '
' . $label . ' ' . $value . ' ';
$i++;
@@ -148,20 +353,17 @@ if ( !function_exists( 'sportspress_player_metrics' ) ) {
if ( !function_exists( 'sportspress_player_statistics' ) ) {
function sportspress_player_statistics( $id ) {
- $team_ids = (array)get_post_meta( $id, 'sp_team', false );
-
- // First one is empty
- unset( $team_ids[0] );
+ $leagues = get_the_terms( $id, 'sp_league' );
$output = '';
- // Loop through statistics for each team
- foreach ( $team_ids as $team_id ):
+ // Loop through statistics for each league
+ foreach ( $leagues as $league ):
- if ( sizeof( $team_ids ) > 1 )
- $output .= '
' . get_the_title( $team_id ) . ' ';
+ if ( sizeof( $leagues ) > 1 )
+ $output .= '
' . $league->name . ' ';
- $data = sportspress_get_player_statistics_data( $id, $team_id );
+ $data = sportspress_get_player_statistics_data( $id, $league->term_id );
// The first row should be column labels
$labels = $data[0];
@@ -181,7 +383,7 @@ if ( !function_exists( 'sportspress_player_statistics' ) ) {
foreach( $data as $season_id => $row ):
- $output .= '
';
+ $output .= ' ';
foreach( $labels as $key => $value ):
$output .= '' . sportspress_array_value( $row, $key, '—' ) . ' ';
diff --git a/sportspress.php b/sportspress.php
index 49dda786..52473d19 100644
--- a/sportspress.php
+++ b/sportspress.php
@@ -54,6 +54,7 @@ require_once dirname( __FILE__ ) . '/admin/post-types/list.php';
require_once dirname( __FILE__ ) . '/admin/post-types/staff.php';
// Terms
+require_once dirname( __FILE__ ) . '/admin/terms/league.php';
require_once dirname( __FILE__ ) . '/admin/terms/season.php';
require_once dirname( __FILE__ ) . '/admin/terms/venue.php';
require_once dirname( __FILE__ ) . '/admin/terms/position.php';