Add player list widget and add league table widget columns selector

This commit is contained in:
Brian Miyaji
2014-02-12 04:30:16 +11:00
parent 08b6111fb2
commit cacbd3c27e
11 changed files with 300 additions and 63 deletions

View File

@@ -6,34 +6,12 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$id = get_the_ID();
$defaults = array(
'number_label' => __( 'Pos', 'sportspress' ),
'thumbnails' => 0,
'thumbnail_size' => 'thumbnail'
'columns' => null,
);
$r = wp_parse_args( $args, $defaults );
$leagues = get_the_terms( $id, 'sp_league' );
$seasons = get_the_terms( $id, 'sp_season' );
$terms = array();
if ( $leagues ):
$league = reset( $leagues );
$terms[] = $league->name;
endif;
if ( $seasons ):
$season = reset( $seasons );
$terms[] = $season->name;
endif;
$title = sizeof( $terms ) ? implode( ' — ', $terms ) : get_the_title( $id );
if ( ! is_singular( 'sp_table' ) )
$output = '<h4 class="sp-table-caption"><a href="' . get_permalink( $id ) . '">' . $title . '</a></h4>';
else
$output = '<h4 class="sp-table-caption">' . $title . '</h4>';
$output .= '<div class="sp-table-wrapper">' .
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-league-table sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
$data = sportspress_get_league_table_data( $id );
@@ -44,9 +22,13 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
// Remove the first row to leave us with the actual data
unset( $data[0] );
$output .= '<th class="data-number">' . $r['number_label'] . '</th>';
$columns = sportspress_array_value( $r, 'columns', null );
$output .= '<th class="data-number">' . __( 'Pos', 'sportspress' ) . '</th>';
foreach( $labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
if ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) )
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
@@ -57,23 +39,17 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
// Position as number
$output .= '<td class="data-number">' . ( $i + 1 ) . '</td>';
// Rank
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
// Thumbnail and name as link
$permalink = get_post_permalink( $team_id );
if ( $r['thumbnails'] ):
$thumbnail = get_the_post_thumbnail( $team_id, $r['thumbnail_size'], array( 'class' => 'logo' ) );
else:
$thumbnail = null;
endif;
$name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', '&nbsp;' ) );
$output .= '<td class="data-name">' . ( $thumbnail ? $thumbnail . ' ' : '' ) . '<a href="' . $permalink . '">' . $name . '</a></td>';
$output .= '<td class="data-name"><a href="' . get_post_permalink( $team_id ) . '">' . $name . '</a></td>';
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
if ( ! is_array( $columns ) || in_array( $key, $columns ) )
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$output .= '</tr>';
@@ -84,7 +60,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$output .= '</tbody>' . '</table>' . '</div>';
return apply_filters( 'sportspress_league_table', $output );
return apply_filters( 'sportspress_league_table', $output, $id );
}
}

View File

@@ -1,24 +1,51 @@
<?php
if ( !function_exists( 'sportspress_player_list' ) ) {
function sportspress_player_list( $id = null ) {
function sportspress_player_list( $id = null, $args = '' ) {
if ( ! $id )
$id = get_the_ID();
$data = sportspress_get_player_list_data( $id );
$defaults = array(
'statistics' => null,
'orderby' => 'number',
'order' => 'ASC',
);
$r = wp_parse_args( $args, $defaults );
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-player-list sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
$data = sportspress_get_player_list_data( $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 .= '<th class="data-number">#</th>';
$statistics = sportspress_array_value( $r, 'statistics', null );
if ( $r['orderby'] != 'number' || $r['order'] != 'ASC' ):
global $sportspress_statistic_priorities;
$sportspress_statistic_priorities = array(
array(
'statistic' => $r['orderby'],
'order' => $r['order'],
),
);
uasort( $data, 'sportspress_sort_list_players' );
endif;
if ( $r['orderby'] == 'number' ):
$output .= '<th class="data-number">#</th>';
else:
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
endif;
foreach( $labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
if ( ! is_array( $statistics ) || $key == 'name' || in_array( $key, $statistics ) )
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
@@ -29,9 +56,13 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
// Player number
$number = get_post_meta( $player_id, 'sp_number', true );
$output .= '<td class="data-number">' . ( $number ? $number : '&nbsp;' ) . '</td>';
// Rank or number
if ( isset( $r['orderby'] ) && $r['orderby'] != 'number' ):
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
else:
$number = get_post_meta( $player_id, 'sp_number', true );
$output .= '<td class="data-number">' . ( $number ? $number : '&nbsp;' ) . '</td>';
endif;
// Name as link
$permalink = get_post_permalink( $player_id );
@@ -41,6 +72,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
if ( ! is_array( $statistics ) || in_array( $key, $statistics ) )
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;