Display total statistics per player

This commit is contained in:
Brian Miyaji
2014-08-24 00:19:55 +10:00
parent 70e124b3c2
commit c17e47fd38
3 changed files with 91 additions and 70 deletions

View File

@@ -19,27 +19,24 @@ class SP_Meta_Box_Player_Statistics {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$player = new SP_Player( $post );
$leagues = get_the_terms( $post->ID, 'sp_league' ); $leagues = get_the_terms( $post->ID, 'sp_league' );
$league_num = sizeof( $leagues ); $league_num = sizeof( $leagues );
// Loop through statistics for each league // Loop through statistics for each league
if ( $leagues ): foreach ( $leagues as $league ): if ( $leagues ): foreach ( $leagues as $league ):
?>
if ( $league_num > 1 ): <p><strong><?php echo $league->name; ?></strong></p>
?> <?php
<p><strong><?php echo $league->name; ?></strong></p>
<?php
endif;
$player = new SP_Player( $post );
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true ); list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams ); self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams );
endforeach; else: endforeach; endif;
?>
printf( __( 'Select %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ); <p><strong><?php _e( 'Total', 'sportspress' ); ?></strong></p>
<?php
endif; list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true );
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );
} }
/** /**
@@ -61,10 +58,12 @@ class SP_Meta_Box_Player_Statistics {
<thead> <thead>
<tr> <tr>
<th><?php _e( 'Season', 'sportspress' ); ?></th> <th><?php _e( 'Season', 'sportspress' ); ?></th>
<th><label for="sp_columns_team"> <?php if ( $league_id ): ?>
<input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>> <th><label for="sp_columns_team">
<?php _e( 'Team', 'sportspress' ); ?> <input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>>
</label></th> <?php _e( 'Team', 'sportspress' ); ?>
</label></th>
<?php endif; ?>
<?php foreach ( $columns as $key => $label ): if ( $key == 'team' ) continue; ?> <?php foreach ( $columns as $key => $label ): if ( $key == 'team' ) continue; ?>
<th><?php echo $label; ?></th> <th><?php echo $label; ?></th>
<?php endforeach; ?> <?php endforeach; ?>
@@ -74,44 +73,49 @@ class SP_Meta_Box_Player_Statistics {
<?php <?php
$i = 0; $i = 0;
foreach ( $data as $div_id => $div_stats ): foreach ( $data as $div_id => $div_stats ):
if ( !$div_id || $div_id == 'statistics' ) continue; if ( $div_id === 'statistics' ) continue;
$div = get_term( $div_id, 'sp_season' ); $div = get_term( $div_id, 'sp_season' );
?> ?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>"> <tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo $div->name; ?>
</td>
<td> <td>
<?php <?php
$value = sp_array_value( $leagues, $div_id, '-1' ); if ( 'WP_Error' == get_class( $div ) ) _e( 'Total', 'sportspress' );
$args = array( else echo $div->name;
'post_type' => 'sp_team',
'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']',
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $value,
'values' => 'ID',
'include' => $teams,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sp_league',
'terms' => $league_id,
'field' => 'id',
),
array(
'taxonomy' => 'sp_season',
'terms' => $div_id,
'field' => 'id',
),
),
);
if ( ! sp_dropdown_pages( $args ) ):
_e( 'No results found.', 'sportspress' );
endif;
?> ?>
</td> </td>
<?php if ( $league_id ): ?>
<td>
<?php
$value = sp_array_value( $leagues, $div_id, '-1' );
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']',
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $value,
'values' => 'ID',
'include' => $teams,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sp_league',
'terms' => $league_id,
'field' => 'id',
),
array(
'taxonomy' => 'sp_season',
'terms' => $div_id,
'field' => 'id',
),
),
);
if ( ! sp_dropdown_pages( $args ) ):
_e( 'No results found.', 'sportspress' );
endif;
?>
</td>
<?php endif; ?>
<?php foreach ( $columns as $column => $label ): if ( $column == 'team' ) continue; <?php foreach ( $columns as $column => $label ): if ( $column == 'team' ) continue;
?> ?>
<td><?php <td><?php

View File

@@ -118,18 +118,25 @@ class SP_Player_List extends SP_Custom_Post {
'order' => 'ASC', 'order' => 'ASC',
'tax_query' => array( 'tax_query' => array(
'relation' => 'AND', 'relation' => 'AND',
array( ),
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_id
),
array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $div_id
)
)
); );
if ( $league_id ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_id
);
endif;
if ( $league_id ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $div_id
);
endif;
$events = get_posts( $args ); $events = get_posts( $args );
// Event loop // Event loop

View File

@@ -83,6 +83,9 @@ class SP_Player extends SP_Custom_Post {
endif; endif;
endforeach; endforeach;
$div_ids[] = 0;
$season_names[0] = __( 'Total', 'sportspress' );
$data = array(); $data = array();
// Get all seasons populated with data where available // Get all seasons populated with data where available
@@ -138,18 +141,25 @@ class SP_Player extends SP_Custom_Post {
), ),
'tax_query' => array( 'tax_query' => array(
'relation' => 'AND', 'relation' => 'AND',
array( ),
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_id
),
array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $div_id
),
)
); );
if ( $league_id ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_id
);
endif;
if ( $div_id ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $div_id
);
endif;
$events = get_posts( $args ); $events = get_posts( $args );
// Event loop // Event loop