Display meta boxes only when statistics available

This commit is contained in:
ThemeBoy
2013-12-11 17:38:49 +11:00
parent 06dfb2f613
commit 05a80bb727
5 changed files with 55 additions and 37 deletions

View File

@@ -28,12 +28,17 @@ function sp_event_display_scheduled( $posts ) {
}
add_filter( 'the_posts', 'sp_event_display_scheduled' );
function sp_event_meta_init() {
function sp_event_meta_init( $post ) {
$limit = get_option( 'sp_event_team_count' );
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
remove_meta_box( 'submitdiv', 'sp_event', 'side' );
add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_event_team_meta', 'sp_event', 'side', 'high' );
add_meta_box( 'sp_playersdiv', __( 'Players', 'sportspress' ), 'sp_event_players_meta', 'sp_event', 'normal', 'high' );
add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sp_event_results_meta', 'sp_event', 'normal', 'high' );
if ( $teams != array_pad( array_slice( array(), 0, $limit ), $limit, 0 ) ):
add_meta_box( 'sp_playersdiv', __( 'Players', 'sportspress' ), 'sp_event_players_meta', 'sp_event', 'normal', 'high' );
add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sp_event_results_meta', 'sp_event', 'normal', 'high' );
endif;
add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sp_event_article_meta', 'sp_event', 'normal', 'high' );
}
@@ -75,35 +80,26 @@ function sp_event_players_meta( $post ) {
$limit = get_option( 'sp_event_team_count' );
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
// Teams
if ( $teams == array_pad( array_slice( array(), 0, $limit ), $limit, 0 ) ):
$stats = (array)get_post_meta( $post->ID, 'sp_players', true );
// Get columns from result variables
$columns = sp_get_var_labels( 'sp_metric', true );
foreach ( $teams as $key => $team_id ):
if ( ! $team_id ) continue;
// Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
?>
<p><strong><?php echo $team_id ? get_the_title( $team_id ) : sprintf( __( 'Select %s' ), 'Teams' ); ?></strong></p>
<div>
<p><strong><?php echo get_the_title( $team_id ); ?></strong></p>
<?php sp_event_players_table( $columns, $data, $team_id ); ?>
</div>
<?php
else:
$stats = (array)get_post_meta( $post->ID, 'sp_players', true );
// Get columns from result variables
$columns = sp_get_var_labels( 'sp_metric', true );
foreach ( $teams as $key => $team_id ):
// Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
?>
<div>
<p><strong><?php echo $team_id ? get_the_title( $team_id ) : sprintf( __( 'Select %s' ), 'Team' ); ?></strong></p>
<?php if ( $team_id ) sp_event_players_table( $columns, $data, $team_id ); ?>
</div>
<?php
endforeach;
endif;
endforeach;
}

View File

@@ -30,9 +30,14 @@ function sp_list_edit_columns() {
}
add_filter( 'manage_edit-sp_list_columns', 'sp_list_edit_columns' );
function sp_list_meta_init() {
function sp_list_meta_init( $post ) {
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
add_meta_box( 'sp_playerdiv', __( 'Players', 'sportspress' ), 'sp_list_player_meta', 'sp_list', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sp_list_stats_meta', 'sp_list', 'normal', 'high' );
if ( $players && $players != array(0) ):
add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sp_list_stats_meta', 'sp_list', 'normal', 'high' );
endif;
}
function sp_list_player_meta( $post ) {

View File

@@ -18,13 +18,20 @@ function sp_player_cpt_init() {
}
add_action( 'init', 'sp_player_cpt_init' );
function sp_player_meta_init() {
function sp_player_meta_init( $post ) {
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
$divisions = (array)get_the_terms( $post->ID, 'sp_div' );
remove_meta_box( 'submitdiv', 'sp_player', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_player', 'side', 'high' );
remove_meta_box( 'postimagediv', 'sp_player', 'side' );
add_meta_box( 'postimagediv', __( 'Photo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_player_team_meta', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_player_stats_meta', 'sp_player', 'normal', 'high' );
if ( $teams && $teams != array(0) && $divisions && $divisions != array(0) ):
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_player_stats_meta', 'sp_player', 'normal', 'high' );
endif;
add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sp_player_profile_meta', 'sp_player', 'normal', 'high' );
}

View File

@@ -29,12 +29,17 @@ function sp_table_edit_columns() {
}
add_filter( 'manage_edit-sp_table_columns', 'sp_table_edit_columns' );
function sp_table_meta_init() {
function sp_table_meta_init( $post ) {
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_table_team_meta', 'sp_table', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'League Table', 'sportspress' ), 'sp_table_stats_meta', 'sp_table', 'normal', 'high' );
if ( $teams && $teams != array(0) ):
add_meta_box( 'sp_statsdiv', __( 'League Table', 'sportspress' ), 'sp_table_stats_meta', 'sp_table', 'normal', 'high' );
endif;
}
function sp_table_team_meta( $post ) {
function sp_table_team_meta( $post, $test ) {
$division_id = sp_get_the_term_id( $post->ID, 'sp_div', 0 );
?>
<div>

View File

@@ -18,12 +18,17 @@ function sp_team_cpt_init() {
}
add_action( 'init', 'sp_team_cpt_init' );
function sp_team_meta_init() {
function sp_team_meta_init( $post ) {
$divisions = (array)get_the_terms( $post->ID, 'sp_div' );
remove_meta_box( 'submitdiv', 'sp_team', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_team', 'side', 'high' );
remove_meta_box( 'postimagediv', 'sp_team', 'side' );
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_team_stats_meta', 'sp_team', 'normal', 'high' );
if ( $divisions && $divisions != array(0) ):
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_team_stats_meta', 'sp_team', 'normal', 'high' );
endif;
}
function sp_team_edit_columns() {