Enable auto populating league tables
This commit is contained in:
@@ -466,8 +466,9 @@ jQuery(document).ready(function($){
|
|||||||
$(".post-type-sp_list #post-formats-select input.post-format").trigger("change");
|
$(".post-type-sp_list #post-formats-select input.post-format").trigger("change");
|
||||||
|
|
||||||
// Auto-select hides options
|
// Auto-select hides options
|
||||||
$(".sp-select-setting").change(function() {
|
$(".sp-select-setting").find("select").change(function() {
|
||||||
$(".sp-select-options").toggle("manual"==$(this).val());
|
$(".sp-select-all-range").toggle("manual"==$(this).val());
|
||||||
|
$(this).closest(".sp-select-setting").siblings(".sp-tab-select").find("select").change()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Configure primary result option (Ajax)
|
// Configure primary result option (Ajax)
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ class SP_Meta_Box_Table_Details {
|
|||||||
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
||||||
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
|
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||||
$season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
|
$season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||||
|
$select = get_post_meta( $post->ID, 'sp_select', true );
|
||||||
|
if ( ! $select ) {
|
||||||
|
global $pagenow;
|
||||||
|
$select = ( 'post-new.php' ? 'auto' : 'manual' );
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<div>
|
<div>
|
||||||
<p><strong><?php _e( 'Competition', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Competition', 'sportspress' ); ?></strong></p>
|
||||||
@@ -55,8 +60,14 @@ class SP_Meta_Box_Table_Details {
|
|||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
<p><strong><?php _e( 'Teams', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Teams', 'sportspress' ); ?></strong></p>
|
||||||
|
<p class="sp-select-setting">
|
||||||
|
<select name="sp_select">
|
||||||
|
<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>
|
||||||
<?php
|
<?php
|
||||||
sp_post_checklist( $post->ID, 'sp_team', 'block', array( 'sp_league', 'sp_season' ) );
|
sp_post_checklist( $post->ID, 'sp_team', ( 'auto' == $select ? 'none' : 'block' ), array( 'sp_league', 'sp_season' ) );
|
||||||
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
|
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
@@ -69,6 +80,7 @@ class SP_Meta_Box_Table_Details {
|
|||||||
public static function save( $post_id, $post ) {
|
public static function save( $post_id, $post ) {
|
||||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' );
|
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' );
|
||||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
||||||
|
update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,10 +31,10 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
public function data( $admin = false ) {
|
public function data( $admin = false ) {
|
||||||
$league_id = sp_get_the_term_id( $this->ID, 'sp_league', 0 );
|
$league_id = sp_get_the_term_id( $this->ID, 'sp_league', 0 );
|
||||||
$div_id = sp_get_the_term_id( $this->ID, 'sp_season', 0 );
|
$div_id = sp_get_the_term_id( $this->ID, 'sp_season', 0 );
|
||||||
$team_ids = (array)get_post_meta( $this->ID, 'sp_team', false );
|
|
||||||
$table_stats = (array)get_post_meta( $this->ID, 'sp_teams', true );
|
$table_stats = (array)get_post_meta( $this->ID, 'sp_teams', true );
|
||||||
$usecolumns = get_post_meta( $this->ID, 'sp_columns', true );
|
$usecolumns = get_post_meta( $this->ID, 'sp_columns', true );
|
||||||
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
|
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
|
||||||
|
$select = get_post_meta( $this->ID, 'sp_select', true );
|
||||||
|
|
||||||
// Get labels from result variables
|
// Get labels from result variables
|
||||||
$result_labels = (array)sp_get_var_labels( 'sp_result' );
|
$result_labels = (array)sp_get_var_labels( 'sp_result' );
|
||||||
@@ -42,6 +42,47 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
// Get labels from outcome variables
|
// Get labels from outcome variables
|
||||||
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
|
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
|
||||||
|
|
||||||
|
// Get teams automatically if set to auto
|
||||||
|
if ( 'auto' == $select ) {
|
||||||
|
$team_ids = array();
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'sp_team',
|
||||||
|
'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;
|
||||||
|
|
||||||
|
$teams = get_posts( $args );
|
||||||
|
|
||||||
|
if ( $teams && is_array( $teams ) ) {
|
||||||
|
foreach ( $teams as $team ) {
|
||||||
|
$team_ids[] = $team->ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$team_ids = (array)get_post_meta( $this->ID, 'sp_team', false );
|
||||||
|
}
|
||||||
|
|
||||||
// Get all leagues populated with stats where available
|
// Get all leagues populated with stats where available
|
||||||
$tempdata = sp_array_combine( $team_ids, $table_stats );
|
$tempdata = sp_array_combine( $team_ids, $table_stats );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user