Change player numbers and positions per event
This commit is contained in:
@@ -194,6 +194,11 @@ table.widefat.sp-data-table input[type="number"] {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.widefat.sp-data-table input.small-text {
|
||||||
|
width: 50px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
table.widefat.sp-data-table input.name {
|
table.widefat.sp-data-table input.name {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
width: auto;
|
width: auto;
|
||||||
|
|||||||
@@ -60,6 +60,16 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th><?php _e( 'Player', 'sportspress' ); ?></th>
|
<th><?php _e( 'Player', 'sportspress' ); ?></th>
|
||||||
|
<th>
|
||||||
|
<?php if ( $has_checkboxes ): ?>
|
||||||
|
<label for="sp_columns_position">
|
||||||
|
<input type="checkbox" name="sp_columns[]" value="position" id="sp_columns_position" <?php checked( is_array( $columns ) && in_array( 'position', $columns ) ); ?>>
|
||||||
|
<?php _e( 'Position', 'sportspress' ); ?>
|
||||||
|
</label>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php _e( 'Position', 'sportspress' ); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</th>
|
||||||
<?php foreach ( $labels as $key => $label ): ?>
|
<?php foreach ( $labels as $key => $label ): ?>
|
||||||
<th>
|
<th>
|
||||||
<?php if ( $has_checkboxes ): ?>
|
<?php if ( $has_checkboxes ): ?>
|
||||||
@@ -80,10 +90,28 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
foreach ( $data as $player_id => $player_performance ):
|
foreach ( $data as $player_id => $player_performance ):
|
||||||
if ( !$player_id ) continue;
|
if ( !$player_id ) continue;
|
||||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||||
|
$value = sp_array_value( $player_performance, 'number', '' );
|
||||||
?>
|
?>
|
||||||
<tr class="sp-row sp-post" data-player="<?php echo $player_id; ?>">
|
<tr class="sp-row sp-post" data-player="<?php echo $player_id; ?>">
|
||||||
<td><?php echo ( $number ? $number : ' ' ); ?></td>
|
<td>
|
||||||
|
<input class="small-text sp-player-number-input" type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][number]" value="<?php echo $value; ?>" placeholder="<?php echo $number; ?>" />
|
||||||
|
</td>
|
||||||
<td><?php echo get_the_title( $player_id ); ?></td>
|
<td><?php echo get_the_title( $player_id ); ?></td>
|
||||||
|
<td>
|
||||||
|
<?php
|
||||||
|
$selected = sp_array_value( $player_performance, 'position', null );
|
||||||
|
if ( $selected == null ):
|
||||||
|
$selected = sp_get_the_term_id( $player_id, 'sp_position', 0 );
|
||||||
|
endif;
|
||||||
|
$args = array(
|
||||||
|
'taxonomy' => 'sp_position',
|
||||||
|
'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position]',
|
||||||
|
'values' => 'term_id',
|
||||||
|
'selected' => $selected
|
||||||
|
);
|
||||||
|
sp_dropdown_taxonomies( $args );
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
<?php foreach( $labels as $column => $label ):
|
<?php foreach( $labels as $column => $label ):
|
||||||
$value = sp_array_value( $player_performance, $column, '' );
|
$value = sp_array_value( $player_performance, $column, '' );
|
||||||
?>
|
?>
|
||||||
@@ -104,6 +132,7 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
<tr class="sp-row sp-total">
|
<tr class="sp-row sp-total">
|
||||||
<td> </td>
|
<td> </td>
|
||||||
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
|
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
|
||||||
|
<td> </td>
|
||||||
<?php foreach( $labels as $column => $label ):
|
<?php foreach( $labels as $column => $label ):
|
||||||
$player_id = 0;
|
$player_id = 0;
|
||||||
$player_performance = sp_array_value( $data, 0, array() );
|
$player_performance = sp_array_value( $data, 0, array() );
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
$performance = (array)get_post_meta( $this->ID, 'sp_players', true );
|
$performance = (array)get_post_meta( $this->ID, 'sp_players', true );
|
||||||
$labels = sp_get_var_labels( 'sp_performance' );
|
$labels = sp_get_var_labels( 'sp_performance' );
|
||||||
$columns = get_post_meta( $this->ID, 'sp_columns', true );
|
$columns = get_post_meta( $this->ID, 'sp_columns', true );
|
||||||
$output = array();
|
|
||||||
foreach( $teams as $i => $team_id ):
|
foreach( $teams as $i => $team_id ):
|
||||||
$players = sp_array_between( (array)get_post_meta( $this->ID, 'sp_player', false ), 0, $i );
|
$players = sp_array_between( (array)get_post_meta( $this->ID, 'sp_player', false ), 0, $i );
|
||||||
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
||||||
@@ -74,6 +73,12 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
$totals[ $key ] += sp_array_value( $player_performance, $key, 0 );
|
$totals[ $key ] += sp_array_value( $player_performance, $key, 0 );
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
if ( ! array_key_exists( 'number', $player_performance ) || $player_performance['number'] == null ):
|
||||||
|
$performance[ $team_id ][ $player_id ]['number'] = get_post_meta( $player_id, 'sp_number', true );
|
||||||
|
endif;
|
||||||
|
if ( ! array_key_exists( 'position', $player_performance ) || $player_performance['position'] == null ):
|
||||||
|
$performance[ $team_id ][ $player_id ]['position'] = get_post_meta( $player_id, 'sp_position', true );
|
||||||
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
foreach( $totals as $key => $value ):
|
foreach( $totals as $key => $value ):
|
||||||
@@ -82,34 +87,13 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
$totals[ $key ] = $manual_total;
|
$totals[ $key ] = $manual_total;
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$lineup = array_filter( $data, array( $this, 'lineup_filter' ) );
|
|
||||||
$subs = array_filter( $data, array( $this, 'sub_filter' ) );
|
|
||||||
|
|
||||||
foreach ( $subs as $player_id => $player ):
|
|
||||||
if ( ! $player_id )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$sub = sp_array_value( $player, 'sub', 0 );
|
|
||||||
|
|
||||||
if ( ! $sub )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$lineup[ $sub ]['sub'] = $player_id;
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
$output[ $team_id ] = array(
|
|
||||||
'lineup' => $lineup,
|
|
||||||
'subs' => $subs,
|
|
||||||
'total' => $totals
|
|
||||||
);
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
if ( $admin ):
|
if ( $admin ):
|
||||||
return array( $labels, $columns, $performance, $teams );
|
return array( $labels, $columns, $performance, $teams );
|
||||||
else:
|
else:
|
||||||
// Add status to performance labels
|
// Add position to performance labels
|
||||||
$labels['status'] = __( 'Status', 'sportspress' );
|
$labels = array_merge( array( 'position' => __( 'Position', 'sportspress' ) ), $labels );
|
||||||
if ( ! is_array( $columns ) )
|
if ( ! is_array( $columns ) )
|
||||||
$columns = array();
|
$columns = array();
|
||||||
foreach ( $labels as $key => $label ):
|
foreach ( $labels as $key => $label ):
|
||||||
|
|||||||
@@ -86,9 +86,9 @@ foreach( $teams as $index => $team_id ):
|
|||||||
if ( ! $name )
|
if ( ! $name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
echo '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
echo '<tr class="' . sp_array_value( $row, 'status', 'lineup' ) . ' ' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||||
|
|
||||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
$number = sp_array_value( $row, 'number', ' ' );
|
||||||
|
|
||||||
// Player number
|
// Player number
|
||||||
echo '<td class="data-number">' . $number . '</td>';
|
echo '<td class="data-number">' . $number . '</td>';
|
||||||
@@ -99,11 +99,12 @@ foreach( $teams as $index => $team_id ):
|
|||||||
if ( isset( $row['status'] ) && $row['status'] == 'sub' ):
|
if ( isset( $row['status'] ) && $row['status'] == 'sub' ):
|
||||||
$name = '(' . $name . ')';
|
$name = '(' . $name . ')';
|
||||||
endif;
|
endif;
|
||||||
if ( array_key_exists( $player_id, $lineup_sub_relation ) ):
|
endif;
|
||||||
$name .= ' <span class="sub-in" title="' . get_the_title( $lineup_sub_relation[ $player_id ] ) . '">' . get_post_meta( $lineup_sub_relation[ $player_id ], 'sp_number', true ) . '</span>';
|
|
||||||
elseif ( isset( $row['sub'] ) && $row['sub'] ):
|
if ( array_key_exists( $player_id, $lineup_sub_relation ) ):
|
||||||
$name .= ' <span class="sub-out" title="' . get_the_title( $row[ 'sub' ] ) . '">' . get_post_meta( $row['sub'], 'sp_number', true ) . '</span>';
|
$name .= ' <span class="sub-in" title="' . get_the_title( $lineup_sub_relation[ $player_id ] ) . '">' . sp_array_value( sp_array_value( $data, $lineup_sub_relation[ $player_id ], array() ), 'number', null ) . '</span>';
|
||||||
endif;
|
elseif ( isset( $row['sub'] ) && $row['sub'] ):
|
||||||
|
$name .= ' <span class="sub-out" title="' . get_the_title( $row[ 'sub' ] ) . '">' . sp_array_value( sp_array_value( $data, $row['sub'], array() ), 'number', null ) . '</span>';
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
echo '<td class="data-name">' . $name . '</td>';
|
echo '<td class="data-name">' . $name . '</td>';
|
||||||
@@ -112,10 +113,19 @@ foreach( $teams as $index => $team_id ):
|
|||||||
foreach( $labels as $key => $label ):
|
foreach( $labels as $key => $label ):
|
||||||
if ( $key == 'name' )
|
if ( $key == 'name' )
|
||||||
continue;
|
continue;
|
||||||
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
|
if ( $key == 'position' ):
|
||||||
$value = $row[ $key ];
|
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
|
||||||
|
$position = get_term_by( 'id', $row[ $key ], 'sp_position' );
|
||||||
|
$value = $position->name;
|
||||||
|
else:
|
||||||
|
$value = '—';
|
||||||
|
endif;
|
||||||
else:
|
else:
|
||||||
$value = 0;
|
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
|
||||||
|
$value = $row[ $key ];
|
||||||
|
else:
|
||||||
|
$value = 0;
|
||||||
|
endif;
|
||||||
endif;
|
endif;
|
||||||
if ( ! array_key_exists( $key, $totals ) ):
|
if ( ! array_key_exists( $key, $totals ) ):
|
||||||
$totals[ $key ] = 0;
|
$totals[ $key ] = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user