Add option to always increment league table positions
This commit is contained in:
@@ -29,8 +29,8 @@ class SP_League_Table 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' );
|
||||||
$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 );
|
||||||
@@ -56,19 +56,19 @@ class SP_League_Table 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;
|
||||||
|
|
||||||
@@ -146,8 +146,14 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
// Get static stats
|
// Get static stats
|
||||||
$static = get_post_meta( $team_id, 'sp_columns', true );
|
$static = get_post_meta( $team_id, 'sp_columns', true );
|
||||||
|
|
||||||
// Add static stats to placeholders
|
if ( 'yes' == get_option( 'sportspress_team_column_editing', 'no' ) && $league_ids && $season_ids ):
|
||||||
$placeholders[ $team_id ] = (array) sp_array_value( sp_array_value( $static, $league_id, array() ), $div_id, array() );
|
// Add static stats to placeholders
|
||||||
|
foreach ( $league_ids as $league_id ):
|
||||||
|
foreach ( $season_ids as $season_id ):
|
||||||
|
$placeholders[ $team_id ] = (array) sp_array_value( sp_array_value( $static, $league_id, array() ), $season_id, array() );
|
||||||
|
endforeach;
|
||||||
|
endforeach;
|
||||||
|
endif;
|
||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
@@ -170,19 +176,19 @@ class SP_League_Table 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;
|
||||||
|
|
||||||
@@ -542,6 +548,10 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
public function calculate_pos( $columns ) {
|
public function calculate_pos( $columns ) {
|
||||||
$this->counter++;
|
$this->counter++;
|
||||||
|
|
||||||
|
if ( 'yes' == get_option( 'sportspress_table_increment', 'no' ) ) {
|
||||||
|
return $this->counter;
|
||||||
|
}
|
||||||
|
|
||||||
// Replace compare data and use last set
|
// Replace compare data and use last set
|
||||||
$compare = $this->compare;
|
$compare = $this->compare;
|
||||||
$this->compare = $columns;
|
$this->compare = $columns;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class SportsPress_League_Tables {
|
|||||||
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
||||||
add_filter( 'sportspress_shortcodes', array( $this, 'add_shortcodes' ) );
|
add_filter( 'sportspress_shortcodes', array( $this, 'add_shortcodes' ) );
|
||||||
add_filter( 'sportspress_team_settings', array( $this, 'add_settings' ) );
|
add_filter( 'sportspress_team_settings', array( $this, 'add_settings' ) );
|
||||||
|
add_filter( 'sportspress_team_options', array( $this, 'add_options' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,13 +121,15 @@ class SportsPress_League_Tables {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function add_meta_boxes( $meta_boxes ) {
|
public function add_meta_boxes( $meta_boxes ) {
|
||||||
$meta_boxes['sp_team']['columns'] = array(
|
if ( 'yes' == get_option( 'sportspress_team_column_editing', 'no' ) ) {
|
||||||
'title' => __( 'Table Columns', 'sportspress' ),
|
$meta_boxes['sp_team']['columns'] = array(
|
||||||
'output' => 'SP_Meta_Box_Team_Columns::output',
|
'title' => __( 'Table Columns', 'sportspress' ),
|
||||||
'save' => 'SP_Meta_Box_Team_Columns::save',
|
'output' => 'SP_Meta_Box_Team_Columns::output',
|
||||||
'context' => 'normal',
|
'save' => 'SP_Meta_Box_Team_Columns::save',
|
||||||
'priority' => 'high',
|
'context' => 'normal',
|
||||||
);
|
'priority' => 'high',
|
||||||
|
);
|
||||||
|
}
|
||||||
$meta_boxes['sp_team']['tables'] = array(
|
$meta_boxes['sp_team']['tables'] = array(
|
||||||
'title' => __( 'League Tables', 'sportspress' ),
|
'title' => __( 'League Tables', 'sportspress' ),
|
||||||
'output' => 'SP_Meta_Box_Team_Tables::output',
|
'output' => 'SP_Meta_Box_Team_Tables::output',
|
||||||
@@ -223,6 +226,14 @@ class SportsPress_League_Tables {
|
|||||||
'step' => 1
|
'step' => 1
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
'title' => __( 'Pos', 'sportspress' ),
|
||||||
|
'desc' => __( 'Always increment', 'sportspress' ),
|
||||||
|
'id' => 'sportspress_table_increment',
|
||||||
|
'default' => 'no',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
),
|
||||||
) ),
|
) ),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
@@ -230,6 +241,25 @@ class SportsPress_League_Tables {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add options.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function add_options( $options ) {
|
||||||
|
return array_merge( $options,
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'title' => __( 'Table Columns', 'sportspress' ),
|
||||||
|
'desc' => __( 'Enable column editing', 'sportspress' ),
|
||||||
|
'id' => 'sportspress_team_column_editing',
|
||||||
|
'default' => 'no',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
|
|||||||
Reference in New Issue
Block a user