Add option to populate player list automatically
This commit is contained in:
@@ -25,6 +25,8 @@ class SP_Meta_Box_List_Details {
|
||||
$grouping = get_post_meta( $post->ID, 'sp_grouping', true );
|
||||
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
|
||||
$order = get_post_meta( $post->ID, 'sp_order', true );
|
||||
$select = get_post_meta( $post->ID, 'sp_select', true );
|
||||
if ( ! $select ) $select = 'auto';
|
||||
?>
|
||||
<div>
|
||||
<p><strong><?php _e( 'Competition', 'sportspress' ); ?></strong></p>
|
||||
@@ -103,10 +105,18 @@ class SP_Meta_Box_List_Details {
|
||||
</select>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Players', 'sportspress' ); ?></strong></p>
|
||||
<?php
|
||||
sp_post_checklist( $post->ID, 'sp_player', 'block', array( 'sp_league', 'sp_season', 'sp_current_team' ) );
|
||||
sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) );
|
||||
?>
|
||||
<p>
|
||||
<select name="sp_select" class="sp-select-setting">
|
||||
<option value="auto" <?php selected( 'auto', $select ); ?>><?php _e( 'Auto', 'sportspress' ); ?></option>
|
||||
<option value="manual" <?php selected( 'manual', $select ); ?>><?php _e( 'Manual', 'sportspress' ); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<div class="sp-select-options<?php if ( 'auto' == $select ) { ?> hidden<?php } ?>">
|
||||
<?php
|
||||
sp_post_checklist( $post->ID, 'sp_player', 'block', array( 'sp_league', 'sp_season', 'sp_current_team' ) );
|
||||
sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) );
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
@@ -121,6 +131,7 @@ class SP_Meta_Box_List_Details {
|
||||
update_post_meta( $post_id, 'sp_grouping', sp_array_value( $_POST, 'sp_grouping', array() ) );
|
||||
update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', array() ) );
|
||||
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
|
||||
update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
|
||||
}
|
||||
}
|
||||
@@ -37,11 +37,12 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
public function data( $admin = false ) {
|
||||
$league_id = sp_get_the_term_id( $this->ID, 'sp_league', 0 );
|
||||
$div_id = sp_get_the_term_id( $this->ID, 'sp_season', 0 );
|
||||
$player_ids = (array)get_post_meta( $this->ID, 'sp_player', false );
|
||||
$team = get_post_meta( $this->ID, 'sp_team', true );
|
||||
$list_stats = (array)get_post_meta( $this->ID, 'sp_players', true );
|
||||
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
|
||||
$orderby = get_post_meta( $this->ID, 'sp_orderby', true );
|
||||
$order = get_post_meta( $this->ID, 'sp_order', true );
|
||||
$select = get_post_meta( $this->ID, 'sp_select', true );
|
||||
|
||||
// Get labels from performance variables
|
||||
$performance_labels = (array)sp_get_var_labels( 'sp_performance' );
|
||||
@@ -49,6 +50,56 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
// Get labels from outcome variables
|
||||
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
|
||||
|
||||
// Get players automatically if set to auto
|
||||
if ( 'auto' == $select ) {
|
||||
$player_ids = array();
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_player',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'order' => 'ASC',
|
||||
'tax_query' => array(
|
||||
'relation' => 'AND',
|
||||
),
|
||||
);
|
||||
|
||||
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;
|
||||
|
||||
if ( $team ):
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => 'sp_team',
|
||||
'value' => $team
|
||||
),
|
||||
);
|
||||
endif;
|
||||
|
||||
$players = get_posts( $args );
|
||||
|
||||
if ( $players && is_array( $players ) ) {
|
||||
foreach ( $players as $player ) {
|
||||
$player_ids[] = $player->ID;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$player_ids = (array)get_post_meta( $this->ID, 'sp_player', false );
|
||||
}
|
||||
|
||||
// Get all leagues populated with stats where available
|
||||
$tempdata = sp_array_combine( $player_ids, $list_stats );
|
||||
|
||||
@@ -129,7 +180,7 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
);
|
||||
endif;
|
||||
|
||||
if ( $league_id ):
|
||||
if ( $div_id ):
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'field' => 'id',
|
||||
|
||||
Reference in New Issue
Block a user