Enable multiple seasons, competitions, and positions to be selected for player lists

This commit is contained in:
Brian Miyaji
2015-08-29 14:03:52 +10:00
parent a15c5becd5
commit b3912678ce

View File

@@ -35,8 +35,9 @@ class SP_Player_List extends SP_Custom_Post {
* @return array * @return array
*/ */
public function data( $admin = false ) { public function data( $admin = false ) {
$league_id = sp_get_the_term_id( $this->ID, 'sp_league', 0 ); $league_ids = sp_get_the_term_ids( $this->ID, 'sp_league' );
$div_id = sp_get_the_term_id( $this->ID, 'sp_season', 0 ); $season_ids = sp_get_the_term_ids( $this->ID, 'sp_season' );
$position_ids = sp_get_the_term_ids( $this->ID, 'sp_position' );
$team = get_post_meta( $this->ID, 'sp_team', true ); $team = get_post_meta( $this->ID, 'sp_team', true );
$list_stats = (array)get_post_meta( $this->ID, 'sp_players', true ); $list_stats = (array)get_post_meta( $this->ID, 'sp_players', true );
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true ); $adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
@@ -64,19 +65,27 @@ class SP_Player_List extends SP_Custom_Post {
), ),
); );
if ( $league_id ): if ( $league_ids ):
$args['tax_query'][] = array( $args['tax_query'][] = array(
'taxonomy' => 'sp_league', 'taxonomy' => 'sp_league',
'field' => 'id', 'field' => 'id',
'terms' => $league_id 'terms' => $league_ids
); );
endif; endif;
if ( $div_id ): if ( $season_ids ):
$args['tax_query'][] = array( $args['tax_query'][] = array(
'taxonomy' => 'sp_season', 'taxonomy' => 'sp_season',
'field' => 'id', 'field' => 'id',
'terms' => $div_id 'terms' => $season_ids
);
endif;
if ( $position_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_position',
'field' => 'id',
'terms' => $position_ids
); );
endif; endif;
@@ -158,8 +167,13 @@ class SP_Player_List extends SP_Custom_Post {
$static = get_post_meta( $player_id, 'sp_statistics', true ); $static = get_post_meta( $player_id, 'sp_statistics', true );
// Add metrics and static stats to placeholders // Add metrics and static stats to placeholders
$placeholders[ $player_id ] = array_merge( $metrics, sp_array_value( sp_array_value( $static, $league_id, array() ), $div_id, array() ) ); if ( $league_ids && $season_ids ):
foreach ( $league_ids as $league_id ):
foreach ( $season_ids as $season_id ):
$placeholders[ $player_id ] = array_merge( $metrics, sp_array_value( sp_array_value( $static, $league_id, array() ), $season_id, array() ) );
endforeach;
endforeach;
endif;
endforeach; endforeach;
$args = array( $args = array(
@@ -179,19 +193,19 @@ class SP_Player_List extends SP_Custom_Post {
), ),
); );
if ( $league_id ): if ( $league_ids ):
$args['tax_query'][] = array( $args['tax_query'][] = array(
'taxonomy' => 'sp_league', 'taxonomy' => 'sp_league',
'field' => 'id', 'field' => 'id',
'terms' => $league_id 'terms' => $league_ids
); );
endif; endif;
if ( $div_id ): if ( $season_ids ):
$args['tax_query'][] = array( $args['tax_query'][] = array(
'taxonomy' => 'sp_season', 'taxonomy' => 'sp_season',
'field' => 'id', 'field' => 'id',
'terms' => $div_id 'terms' => $season_ids
); );
endif; endif;