Add positions to statistics and metrics
This commit is contained in:
105
admin/templates/event-players.php
Normal file
105
admin/templates/event-players.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
if ( !function_exists( 'sportspress_event_players' ) ) {
|
||||
function sportspress_event_players( $id = null ) {
|
||||
|
||||
if ( ! $id ):
|
||||
global $post;
|
||||
$id = $post->ID;
|
||||
endif;
|
||||
|
||||
$teams = (array)get_post_meta( $id, 'sp_team', false );
|
||||
$staff = (array)get_post_meta( $id, 'sp_staff', false );
|
||||
$stats = (array)get_post_meta( $id, 'sp_players', true );
|
||||
$statistic_labels = sportspress_get_var_labels( 'sp_statistic' );
|
||||
|
||||
$output = '';
|
||||
|
||||
foreach( $teams as $key => $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 .= '<h3>' . get_the_title( $team_id ) . '</h3>';
|
||||
|
||||
$output .= '<table class="sp-event-statistics sp-data-table">' . '<thead>' . '<tr>';
|
||||
|
||||
$output .= '<th class="data-number">#</th>';
|
||||
$output .= '<th class="data-number">' . __( 'Player', 'sportspress' ) . '</th>';
|
||||
|
||||
foreach( $statistic_labels as $key => $label ):
|
||||
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( $data as $player_id => $row ):
|
||||
|
||||
if ( ! $player_id )
|
||||
continue;
|
||||
|
||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
|
||||
// Player number
|
||||
$output .= '<td class="data-number">' . $number . '</td>';
|
||||
|
||||
// Name as link
|
||||
$permalink = get_post_permalink( $player_id );
|
||||
$name = get_the_title( $player_id );
|
||||
$output .= '<td class="data-name">' . '<a href="' . $permalink . '">' . $name . '</a></td>';
|
||||
|
||||
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 .= '<td class="data-' . $key . '">' . $value . '</td>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>';
|
||||
|
||||
$i++;
|
||||
|
||||
endforeach;
|
||||
|
||||
$output .= '</tbody>';
|
||||
|
||||
if ( array_key_exists( 0, $data ) ):
|
||||
|
||||
$output .= '<tfoot><tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
|
||||
// Player number
|
||||
$output .= '<td class="data-number"> </td>';
|
||||
$output .= '<td class="data-name">' . __( 'Total', 'sportspress' ) . '</td>';
|
||||
|
||||
$row = $data[0];
|
||||
|
||||
foreach( $statistic_labels as $key => $label ):
|
||||
if ( $key == 'name' ):
|
||||
continue;
|
||||
endif;
|
||||
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '—' ) . '</td>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr></tfoot>';
|
||||
|
||||
endif;
|
||||
|
||||
$output .= '</table>';
|
||||
|
||||
endforeach;
|
||||
|
||||
return apply_filters( 'sportspress_event_players', $output );
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user