Enable player list grouping by position
This commit is contained in:
@@ -13,6 +13,7 @@ $defaults = array(
|
||||
'id' => get_the_ID(),
|
||||
'number' => -1,
|
||||
'performance' => null,
|
||||
'grouping' => null,
|
||||
'orderby' => 'default',
|
||||
'order' => 'ASC',
|
||||
'show_all_players_link' => false,
|
||||
@@ -25,9 +26,6 @@ $defaults = array(
|
||||
|
||||
extract( $defaults, EXTR_SKIP );
|
||||
|
||||
$output = '<div class="sp-table-wrapper">' .
|
||||
'<table class="sp-player-list sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . ( $sortable ? ' sp-sortable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
|
||||
|
||||
$list = new SP_Player_List( $id );
|
||||
$data = $list->data();
|
||||
|
||||
@@ -37,7 +35,14 @@ $labels = $data[0];
|
||||
// Remove the first row to leave us with the actual data
|
||||
unset( $data[0] );
|
||||
|
||||
if ( $orderby != 'default' ):
|
||||
if ( ! $grouping || $grouping == 'default' ):
|
||||
$grouping = $list->grouping;
|
||||
endif;
|
||||
|
||||
if ( $orderby == 'default' ):
|
||||
$orderby = $list->orderby;
|
||||
$order = $list->order;
|
||||
else:
|
||||
$list->priorities = array(
|
||||
array(
|
||||
'key' => $orderby,
|
||||
@@ -47,61 +52,82 @@ if ( $orderby != 'default' ):
|
||||
uasort( $data, array( $list, 'sort' ) );
|
||||
endif;
|
||||
|
||||
if ( in_array( $orderby, array( 'number', 'name' ) ) ):
|
||||
$output .= '<th class="data-number">#</th>';
|
||||
if ( $grouping == 'position' ):
|
||||
$groups = get_terms( 'sp_position' );
|
||||
else:
|
||||
$output .= '<th class="data-rank">' . SP()->text->string('Rank') . '</th>';
|
||||
$group = new stdClass();
|
||||
$group->term_id = null;
|
||||
$group->name = null;
|
||||
$group->slug = null;
|
||||
$groups = array( $group );
|
||||
endif;
|
||||
|
||||
foreach( $labels as $key => $label ):
|
||||
if ( ! is_array( $performance ) || $key == 'name' || in_array( $key, $performance ) )
|
||||
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
|
||||
endforeach;
|
||||
$output = '';
|
||||
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
foreach ( $groups as $group ):
|
||||
if ( ! empty( $group->name ) )
|
||||
$output .= '<h3 class="sp-list-group-name">' . $group->name . '</h3>';
|
||||
|
||||
$i = 0;
|
||||
$output .= '<div class="sp-table-wrapper">' .
|
||||
'<table class="sp-player-list sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . ( $sortable ? ' sp-sortable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
|
||||
|
||||
if ( intval( $number ) > 0 )
|
||||
$limit = $number;
|
||||
|
||||
foreach( $data as $player_id => $row ):
|
||||
if ( isset( $limit ) && $i >= $limit ) continue;
|
||||
|
||||
$name = sp_array_value( $row, 'name', null );
|
||||
if ( ! $name ) continue;
|
||||
|
||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
// Rank or number
|
||||
if ( isset( $orderby ) && $orderby != 'number' ):
|
||||
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
|
||||
if ( in_array( $orderby, array( 'number', 'name' ) ) ):
|
||||
$output .= '<th class="data-number">#</th>';
|
||||
else:
|
||||
$output .= '<td class="data-number">' . sp_array_value( $row, 'number', ' ' ) . '</td>';
|
||||
$output .= '<th class="data-rank">' . SP()->text->string('Rank') . '</th>';
|
||||
endif;
|
||||
|
||||
if ( $link_posts ):
|
||||
$permalink = get_post_permalink( $player_id );
|
||||
$name = '<a href="' . $permalink . '">' . $name . '</a>';
|
||||
endif;
|
||||
|
||||
$output .= '<td class="data-name">' . $name . '</td>';
|
||||
|
||||
foreach( $labels as $key => $value ):
|
||||
if ( $key == 'name' )
|
||||
continue;
|
||||
if ( ! is_array( $performance ) || in_array( $key, $performance ) )
|
||||
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||
foreach( $labels as $key => $label ):
|
||||
if ( ! is_array( $performance ) || $key == 'name' || in_array( $key, $performance ) )
|
||||
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>';
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
|
||||
$i++;
|
||||
$i = 0;
|
||||
|
||||
if ( intval( $number ) > 0 )
|
||||
$limit = $number;
|
||||
|
||||
foreach( $data as $player_id => $row ): if ( empty( $group->term_id ) || has_term( $group->term_id, 'sp_position', $player_id ) ):
|
||||
|
||||
if ( isset( $limit ) && $i >= $limit ) continue;
|
||||
|
||||
$name = sp_array_value( $row, 'name', null );
|
||||
if ( ! $name ) continue;
|
||||
|
||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
// Rank or number
|
||||
if ( isset( $orderby ) && $orderby != 'number' ):
|
||||
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
|
||||
else:
|
||||
$output .= '<td class="data-number">' . sp_array_value( $row, 'number', ' ' ) . '</td>';
|
||||
endif;
|
||||
|
||||
if ( $link_posts ):
|
||||
$permalink = get_post_permalink( $player_id );
|
||||
$name = '<a href="' . $permalink . '">' . $name . '</a>';
|
||||
endif;
|
||||
|
||||
$output .= '<td class="data-name">' . $name . '</td>';
|
||||
|
||||
foreach( $labels as $key => $value ):
|
||||
if ( $key == 'name' )
|
||||
continue;
|
||||
if ( ! is_array( $performance ) || in_array( $key, $performance ) )
|
||||
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>';
|
||||
|
||||
$i++;
|
||||
|
||||
endif; endforeach;
|
||||
|
||||
$output .= '</tbody>' . '</table>' . '</div>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tbody>' . '</table>' . '</div>';
|
||||
|
||||
if ( $show_all_players_link )
|
||||
$output .= '<a class="sp-player-list-link sp-view-all-link" href="' . get_permalink( $id ) . '">' . SP()->text->string('View all players') . '</a>';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user