Add option to always increment league table positions

This commit is contained in:
Brian Miyaji
2015-08-29 14:03:27 +10:00
parent 4656f14279
commit a15c5becd5
2 changed files with 59 additions and 19 deletions

View File

@@ -29,8 +29,8 @@ class SP_League_Table extends SP_Custom_Post{
* @return array
*/
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 );
$league_ids = sp_get_the_term_ids( $this->ID, 'sp_league' );
$season_ids = sp_get_the_term_ids( $this->ID, 'sp_season' );
$table_stats = (array)get_post_meta( $this->ID, 'sp_teams', true );
$usecolumns = get_post_meta( $this->ID, 'sp_columns', 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(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_id
'terms' => $league_ids
);
endif;
if ( $div_id ):
if ( $season_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $div_id
'terms' => $season_ids
);
endif;
@@ -146,8 +146,14 @@ class SP_League_Table extends SP_Custom_Post{
// Get static stats
$static = get_post_meta( $team_id, 'sp_columns', true );
// Add static stats to placeholders
$placeholders[ $team_id ] = (array) sp_array_value( sp_array_value( $static, $league_id, array() ), $div_id, array() );
if ( 'yes' == get_option( 'sportspress_team_column_editing', 'no' ) && $league_ids && $season_ids ):
// 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;
@@ -170,19 +176,19 @@ class SP_League_Table extends SP_Custom_Post{
),
);
if ( $league_id ):
if ( $league_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_id
'terms' => $league_ids
);
endif;
if ( $div_id ):
if ( $season_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $div_id
'terms' => $season_ids
);
endif;
@@ -542,6 +548,10 @@ class SP_League_Table extends SP_Custom_Post{
public function calculate_pos( $columns ) {
$this->counter++;
if ( 'yes' == get_option( 'sportspress_table_increment', 'no' ) ) {
return $this->counter;
}
// Replace compare data and use last set
$compare = $this->compare;
$this->compare = $columns;

View File

@@ -38,6 +38,7 @@ class SportsPress_League_Tables {
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
add_filter( 'sportspress_shortcodes', array( $this, 'add_shortcodes' ) );
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
*/
public function add_meta_boxes( $meta_boxes ) {
$meta_boxes['sp_team']['columns'] = array(
'title' => __( 'Table Columns', 'sportspress' ),
'output' => 'SP_Meta_Box_Team_Columns::output',
'save' => 'SP_Meta_Box_Team_Columns::save',
'context' => 'normal',
'priority' => 'high',
);
if ( 'yes' == get_option( 'sportspress_team_column_editing', 'no' ) ) {
$meta_boxes['sp_team']['columns'] = array(
'title' => __( 'Table Columns', 'sportspress' ),
'output' => 'SP_Meta_Box_Team_Columns::output',
'save' => 'SP_Meta_Box_Team_Columns::save',
'context' => 'normal',
'priority' => 'high',
);
}
$meta_boxes['sp_team']['tables'] = array(
'title' => __( 'League Tables', 'sportspress' ),
'output' => 'SP_Meta_Box_Team_Tables::output',
@@ -223,6 +226,14 @@ class SportsPress_League_Tables {
'step' => 1
),
),
array(
'title' => __( 'Pos', 'sportspress' ),
'desc' => __( 'Always increment', 'sportspress' ),
'id' => 'sportspress_table_increment',
'default' => 'no',
'type' => 'checkbox',
),
) ),
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;