Enable multiple current teams for players & staff

This commit is contained in:
Brian Miyaji
2014-05-06 00:24:04 +10:00
parent ba7946104a
commit 6cced39c93
4 changed files with 24 additions and 43 deletions

View File

@@ -90,34 +90,15 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
if ( empty( $teams ) ):
echo '—';
else:
$results = get_post_meta( $post_id, 'sp_results', true );
$main_result = get_option( 'sportspress_primary_result', null );
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ):
$team_results = sp_array_value( $results, $team_id, null );
if ( $main_result ):
$team_result = sp_array_value( $team_results, $main_result, null );
else:
if ( is_array( $team_results ) ):
end( $team_results );
$team_result = prev( $team_results );
else:
$team_result = null;
endif;
endif;
if ( $team_result != null ):
unset( $team_results['outcome'] );
$team_results = implode( ' | ', $team_results );
echo '<a class="result tips" title="' . $team_results . '" href="' . get_edit_post_link( $post_id ) . '">' . $team_result . '</a> ';
endif;
echo $team->post_title;
if ( in_array( $team_id, $current_teams ) ):
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';
endif;
endforeach;

View File

@@ -87,13 +87,13 @@ class SP_Admin_CPT_Staff extends SP_Admin_CPT {
if ( empty( $teams ) ):
echo '&mdash;';
else:
$current_team = get_post_meta( $post_id, 'sp_current_team', true );
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ):
echo $team->post_title;
if ( $team_id == $current_team ):
if ( in_array( $team_id, $current_teams ) ):
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';

View File

@@ -51,7 +51,7 @@ class SP_Meta_Box_Player_Details {
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) );
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
$current_team = get_post_meta( $post->ID, 'sp_current_team', true );
$current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) );
?>
<p><strong><?php _e( 'Number', 'sportspress' ); ?></strong></p>
<p><input type="text" size="4" id="sp_number" name="sp_number" value="<?php echo $number; ?>"></p>
@@ -83,16 +83,16 @@ class SP_Meta_Box_Player_Details {
sp_dropdown_taxonomies( $args );
?></p>
<p><strong><?php _e( 'Current Team', 'sportspress' ); ?></strong></p>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team',
'show_option_blank' => true,
'selected' => $current_team,
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Team', 'sportspress' ) ),
'class' => 'sp-current-team widefat',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
@@ -151,8 +151,8 @@ class SP_Meta_Box_Player_Details {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_number', sp_array_value( $_POST, 'sp_number', '' ) );
update_post_meta( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', '' ) );
update_post_meta( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', null ) );
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', null ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
}
}

View File

@@ -43,7 +43,7 @@ class SP_Meta_Box_Staff_Details {
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) );
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
$current_team = get_post_meta( $post->ID, 'sp_current_team', true );
$current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) );
?>
<p><strong><?php _e( 'Role', 'sportspress' ); ?></strong></p>
<p><input type="text" id="sp_role" name="sp_role" value="<?php echo $role; ?>"></p>
@@ -60,16 +60,16 @@ class SP_Meta_Box_Staff_Details {
<?php endforeach; ?>
</select></p>
<p><strong><?php _e( 'Current Team', 'sportspress' ); ?></strong></p>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team',
'show_option_blank' => true,
'selected' => $current_team,
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Team', 'sportspress' ) ),
'class' => 'sp-current-team widefat',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
@@ -128,8 +128,8 @@ class SP_Meta_Box_Staff_Details {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_role', sp_array_value( $_POST, 'sp_role', '' ) );
update_post_meta( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', '' ) );
update_post_meta( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', null ) );
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', null ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
}
}