Enable individual players to compete in events

This commit is contained in:
Brian Miyaji
2014-12-10 04:11:08 +11:00
parent e90e32af8b
commit 46cd25d73d
7 changed files with 54 additions and 22 deletions

View File

@@ -125,6 +125,8 @@ class SP_Admin_Meta_Boxes {
add_meta_box( 'sp_videodiv', __( 'Video', 'sportspress' ), 'SP_Meta_Box_Event_Video::output', 'sp_event', 'side', 'low' );
if ( sizeof( array_filter( sp_array_value( $post_meta, 'sp_team', array() ) ) ) ):
add_meta_box( 'sp_resultsdiv', __( 'Team Results', 'sportspress' ), 'SP_Meta_Box_Event_Results::output', 'sp_event', 'normal', 'high' );
endif;
if ( sizeof( array_filter( sp_array_value( $post_meta, 'sp_player', array() ) ) ) ):
add_meta_box( 'sp_performancediv', __( 'Player Performance', 'sportspress' ), 'SP_Meta_Box_Event_Performance::output', 'sp_event', 'normal', 'high' );
endif;
add_meta_box( 'sp_editordiv', __( 'Article', 'sportspress' ), 'SP_Meta_Box_Event_Editor::output', 'sp_event', 'normal', 'low' );

View File

@@ -25,7 +25,7 @@ class SP_Meta_Box_Event_Performance {
$i = 0;
foreach ( $teams as $key => $team_id ):
if ( ! $team_id ) continue;
if ( -1 == $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 );
@@ -33,7 +33,11 @@ class SP_Meta_Box_Event_Performance {
?>
<div>
<p><strong><?php echo get_the_title( $team_id ); ?></strong></p>
<?php if ( $team_id ): ?>
<p><strong><?php echo get_the_title( $team_id ); ?></strong></p>
<?php elseif ( $i ): ?>
<br>
<?php endif; ?>
<?php self::table( $labels, $columns, $data, $team_id, $i == 0 ); ?>
</div>
<?php
@@ -83,7 +87,9 @@ class SP_Meta_Box_Event_Performance {
<?php endif; ?>
</th>
<?php endforeach; ?>
<th><?php _e( 'Status', 'sportspress' ); ?></th>
<?php if ( $team_id ): ?>
<th><?php _e( 'Status', 'sportspress' ); ?></th>
<?php endif; ?>
</tr>
</thead>
<tfoot>
@@ -99,7 +105,9 @@ class SP_Meta_Box_Event_Performance {
?>
<td><input type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" /></td>
<?php endforeach; ?>
<td>&nbsp;</td>
<?php if ( $team_id ): ?>
<td>&nbsp;</td>
<?php endif; ?>
</tr>
</tfoot>
<tbody>
@@ -137,10 +145,12 @@ class SP_Meta_Box_Event_Performance {
<input class="sp-player-<?php echo $column; ?>-input" type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" />
</td>
<?php endforeach; ?>
<td class="sp-status-selector">
<?php echo self::status_select( $team_id, $player_id, sp_array_value( $player_performance, 'status', null ) ); ?>
<?php echo self::sub_select( $team_id, $player_id, sp_array_value( $player_performance, 'sub', null ), $data ); ?>
</td>
<?php if ( $team_id ): ?>
<td class="sp-status-selector">
<?php echo self::status_select( $team_id, $player_id, sp_array_value( $player_performance, 'status', null ) ); ?>
<?php echo self::sub_select( $team_id, $player_id, sp_array_value( $player_performance, 'sub', null ), $data ); ?>
</td>
<?php endif; ?>
</tr>
<?php
endforeach;

View File

@@ -59,10 +59,12 @@ class SP_Meta_Box_Event_Teams {
'post_type' => 'sp_team',
'name' => 'sp_team[]',
'class' => 'sportspress-pages',
'show_option_none' => sprintf( __( '&mdash; None &mdash;', 'sportspress' ), 'Team' ),
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
'show_option_all' => __( '&mdash; Individual &mdash;', 'sportspress' ),
'values' => 'ID',
'selected' => $team,
);
wp_dropdown_pages( $args );
sp_dropdown_pages( $args );
?>
</p>
<ul id="sp_team-tabs" class="wp-tab-bar sp-tab-bar">

View File

@@ -103,6 +103,7 @@ class SP_Meta_Box_Player_Statistics {
'post_type' => 'sp_team',
'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']',
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
'show_option_all' => __( '&mdash; Individual &mdash;', 'sportspress' ),
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $value,

View File

@@ -106,6 +106,13 @@ class SP_Event extends SP_Custom_Post{
endif;
endforeach;
endif;
// Move individual players to top level of array
if ( array_key_exists( 0, $performance ) ) {
foreach ( $performance[ 0 ] as $player_id => $player_performance ) {
$performance[ $player_id ] = array( $player_id => $player_performance );
}
}
$performance[0] = $labels;
return $performance;
endif;

View File

@@ -281,21 +281,25 @@ class SP_Player extends SP_Custom_Post {
foreach( $placeholders as $season_id => $season_data ):
if ( ! sp_array_value( $leagues, $season_id, 0 ) )
if ( -1 == sp_array_value( $leagues, $season_id, 0 ) )
continue;
$season_name = sp_array_value( $season_names, $season_id, '&nbsp;' );
$team_id = sp_array_value( $leagues, $season_id, array() );
if ( ! $team_id || $team_id == '-1' )
if ( -1 == $team_id )
continue;
$team_name = get_the_title( $team_id );
if ( get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false ):
$team_permalink = get_permalink( $team_id );
$team_name = '<a href="' . $team_permalink . '">' . $team_name . '</a>';
if ( $team_id ):
$team_name = get_the_title( $team_id );
if ( get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false ):
$team_permalink = get_permalink( $team_id );
$team_name = '<a href="' . $team_permalink . '">' . $team_name . '</a>';
endif;
else:
$team_name = '&mdash;';
endif;
// Add season name to row

View File

@@ -51,7 +51,7 @@ if ( is_array( $teams ) ):
endif;
foreach( $teams as $index => $team_id ):
if ( ! $team_id ) continue;
if ( -1 == $team_id ) continue;
// Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $index );
@@ -61,12 +61,18 @@ if ( is_array( $teams ) ):
$totals = array();
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
if ( $team_id ) {
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
} else {
$data = sp_array_value( array_values( $performance ), $index );
}
if ( ! $show_team_players && ! $show_staff && ! $show_total ) continue;
?>
<div class="sp-template sp-template-event-performance sp-template-event-performance-<?php echo $mode; ?>">
<h4 class="sp-table-caption"><?php echo get_the_title( $team_id ); ?></h4>
<?php if ( $team_id ): ?>
<h4 class="sp-table-caption"><?php echo get_the_title( $team_id ); ?></h4>
<?php endif; ?>
<?php
if ( $show_staff ):
sp_get_template( 'event-staff.php', array( 'id' => $id, 'index' => $index ) );
@@ -179,7 +185,7 @@ if ( is_array( $teams ) ):
?>
</tbody>
<?php endif; ?>
<?php if ( $status == 'results' && $show_total && array_key_exists( 0, $data ) ): ?>
<?php if ( $show_total ): ?>
<<?php echo ( $show_team_players ? 'tfoot' : 'tbody' ); ?>>
<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">
<?php
@@ -188,7 +194,7 @@ if ( is_array( $teams ) ):
echo '<td class="data-name">' . __( 'Total', 'sportspress' ) . '</td>';
endif;
$row = $data[0];
$row = sp_array_value( $data, 0, array() );
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';