Display player list on front end

This commit is contained in:
ThemeBoy
2013-12-04 03:45:13 +11:00
parent fbd189a4dd
commit de06094d95
4 changed files with 207 additions and 120 deletions

View File

@@ -73,122 +73,10 @@ function sp_list_player_meta( $post ) {
}
function sp_list_stats_meta( $post ) {
$div_id = sp_get_the_term_id( $post->ID, 'sp_div', 0 );
$team_id = get_post_meta( $post->ID, 'sp_team', true );
$player_ids = (array)get_post_meta( $post->ID, 'sp_player', false );
$stats = (array)get_post_meta( $post->ID, 'sp_players', true );
// Equation Operating System
$eos = new eqEOS();
list( $columns, $data, $placeholders, $merged ) = sp_get_list( $post->ID, true );
// Get labels from result variables
$metric_labels = (array)sp_get_var_labels( 'sp_metric' );
// Get all divisions populated with stats where available
$data = sp_array_combine( $player_ids, $stats );
// Get equations from statistics variables
$equations = sp_get_var_equations( 'sp_metric' );
// Create entry for each player in totals
$totals = array();
$placeholders = array();
foreach ( $player_ids as $player_id ):
if ( ! $player_id )
continue;
$totals[ $player_id ] = array( 'eventsattended' => 0, 'eventsplayed' => 0 );
foreach ( $metric_labels as $key => $value ):
$totals[ $player_id ][ $key ] = 0;
endforeach;
// Get static metrics
$static = get_post_meta( $player_id, 'sp_metrics', true );
// Create placeholders entry for the player
$placeholders[ $player_id ] = array();
// Add static metrics to placeholders
if ( array_key_exists( $team_id, $static ) && array_key_exists( $div_id, $static[ $team_id ] ) ):
$placeholders[ $player_id ] = $static[ $team_id ][ $div_id ];
endif;
endforeach;
$args = array(
'post_type' => 'sp_event',
'numberposts' => -1,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'sp_div',
'field' => 'id',
'terms' => $div_id
)
),
'meta_query' => array(
array(
'key' => 'sp_team',
'value' => $team_id,
)
)
);
$events = get_posts( $args );
// Event loop
foreach( $events as $event ):
$teams = (array)get_post_meta( $event->ID, 'sp_players', true );
if ( ! array_key_exists( $team_id, $teams ) )
continue;
$players = sp_array_value( $teams, $team_id, array() );
foreach ( $players as $player_id => $player_metrics ):
// Increment events played
$totals[ $player_id ]['eventsplayed']++;
foreach ( $player_metrics as $key => $value ):
if ( array_key_exists( $key, $totals[ $player_id ] ) ):
$totals[ $player_id ][ $key ] += $value;
endif;
endforeach;
endforeach;
endforeach;
// Generate placeholder values for each team
foreach ( $player_ids as $player_id ):
if ( ! $player_id )
continue;
foreach ( $equations as $key => $value ):
if ( sp_array_value( $placeholders[ $player_id ], $key, '' ) == '' ):
if ( empty( $value ) ):
// Reflect totals
$placeholders[ $player_id ][ $key ] = sp_array_value( sp_array_value( $totals, $player_id, array() ), $key, 0 );
else:
// Calculate value
$placeholders[ $player_id ][ $key ] = $eos->solveIF( str_replace( ' ', '', $value ), sp_array_value( $totals, $player_id, array() ) );
endif;
endif;
endforeach;
endforeach;
sp_player_table( $metric_labels, $data, $placeholders );
sp_player_table( $columns, $data, $placeholders );
sp_nonce();
}
?>

View File

@@ -9,7 +9,7 @@ function sp_table_cpt_init() {
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'author' ),
'supports' => array( 'title', 'author', 'excerpt' ),
'register_meta_box_cb' => 'sp_table_meta_init',
'rewrite' => array( 'slug' => 'table' ),
'show_in_menu' => 'edit.php?post_type=sp_event'