Enable selecting column groups in player lists
This commit is contained in:
@@ -23,15 +23,15 @@ class SP_Meta_Box_List_Columns {
|
||||
?>
|
||||
<div id="sp-column-group-select">
|
||||
<label class="selectit">
|
||||
<input type="checkbox" name="sp_column_group[]" value="sp_performance" <?php checked( true, ( empty( $column_groups ) || in_array( 'sp_performance', $column_groups ) ) ); ?>>
|
||||
<input type="checkbox" name="sp_column_group[]" value="sp_performance" <?php checked( true, in_array( 'sp_performance', $column_groups ) ); ?>>
|
||||
<?php _e( 'Performance', 'sportspress' ); ?>
|
||||
</label><br>
|
||||
<label class="selectit">
|
||||
<input type="checkbox" name="sp_column_group[]" value="sp_metric" <?php checked( true, ( empty( $column_groups ) || in_array( 'sp_metric', $column_groups ) ) ); ?>>
|
||||
<input type="checkbox" name="sp_column_group[]" value="sp_metric" <?php checked( true, in_array( 'sp_metric', $column_groups ) ); ?>>
|
||||
<?php _e( 'Metrics', 'sportspress' ); ?>
|
||||
</label><br>
|
||||
<label class="selectit">
|
||||
<input type="checkbox" name="sp_column_group[]" value="sp_statistic" <?php checked( true, ( empty( $column_groups ) || in_array( 'sp_statistic', $column_groups ) ) ); ?>>
|
||||
<input type="checkbox" name="sp_column_group[]" value="sp_statistic" <?php checked( true, in_array( 'sp_statistic', $column_groups ) ); ?>>
|
||||
<?php _e( 'Statistics', 'sportspress' ); ?>
|
||||
</label><br>
|
||||
</div>
|
||||
|
||||
@@ -98,7 +98,7 @@ class SP_Meta_Box_List_Data {
|
||||
else:
|
||||
?>
|
||||
<tr class="sp-row alternate">
|
||||
<td colspan="<?php $colspan = sizeof( $columns ) + 1; echo $colspan; ?>">
|
||||
<td colspan="<?php $colspan = sizeof( $columns ) + 2; echo $colspan; ?>">
|
||||
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Players', 'sportspress' ) ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -145,7 +145,7 @@ class SP_Meta_Box_List_Data {
|
||||
else:
|
||||
?>
|
||||
<tr class="sp-row alternate">
|
||||
<td colspan="<?php $colspan = sizeof( $columns ) + 1; echo $colspan; ?>">
|
||||
<td colspan="<?php $colspan = sizeof( $columns ) + 2; echo $colspan; ?>">
|
||||
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Players', 'sportspress' ) ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -85,7 +85,7 @@ class SP_Meta_Box_List_Details {
|
||||
'number' => __( 'Number', 'sportspress' ),
|
||||
'name' => __( 'Name', 'sportspress' ),
|
||||
),
|
||||
'post_type' => array( 'sp_metric', 'sp_statistic' ),
|
||||
'post_type' => array( 'sp_performance', 'sp_metric', 'sp_statistic' ),
|
||||
'name' => 'sp_orderby',
|
||||
'selected' => $orderby,
|
||||
'values' => 'slug',
|
||||
|
||||
@@ -83,7 +83,7 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
endforeach;
|
||||
|
||||
// Get metrics
|
||||
$metrics = get_post_meta( $player_id, 'sp_metrics', true );
|
||||
$metrics = (array) get_post_meta( $player_id, 'sp_metrics', true );
|
||||
foreach ( $metrics as $key => $value ):
|
||||
$adjustment = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $key, null );
|
||||
if ( $adjustment != null )
|
||||
@@ -227,59 +227,63 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
$totals[ $player_id ]['last10'] = $last10;
|
||||
endforeach;
|
||||
|
||||
$args = array(
|
||||
'post_type' => $column_groups,
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$stats = get_posts( $args );
|
||||
|
||||
$columns = array();
|
||||
|
||||
foreach ( $stats as $stat ):
|
||||
if ( ! empty( $column_groups ) ):
|
||||
|
||||
// Get post meta
|
||||
$meta = get_post_meta( $stat->ID );
|
||||
|
||||
// Add equation to object
|
||||
$stat->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, null );
|
||||
$stat->precision = sp_array_value( sp_array_value( $meta, 'sp_precision', array() ), 0, 0 );
|
||||
|
||||
// Add column name to columns
|
||||
$columns[ $stat->post_name ] = $stat->post_title;
|
||||
|
||||
endforeach;
|
||||
|
||||
// Fill in empty placeholder values for each player
|
||||
foreach ( $player_ids as $player_id ):
|
||||
if ( ! $player_id )
|
||||
continue;
|
||||
|
||||
$variables = array_merge( sp_array_value( $totals, $player_id, array() ), array_filter( sp_array_value( $placeholders, $player_id, array() ) ) );
|
||||
$args = array(
|
||||
'post_type' => $column_groups,
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$stats = get_posts( $args );
|
||||
|
||||
foreach ( $stats as $stat ):
|
||||
if ( sp_array_value( $placeholders[ $player_id ], $stat->post_name, '' ) == '' ):
|
||||
|
||||
if ( $stat->equation == null ):
|
||||
$placeholder = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $stat->post_name, null );
|
||||
if ( $placeholder == null ):
|
||||
$placeholder = '-';
|
||||
endif;
|
||||
else:
|
||||
// Solve
|
||||
$placeholder = sp_solve( $stat->equation, $variables, $stat->precision );
|
||||
// Get post meta
|
||||
$meta = get_post_meta( $stat->ID );
|
||||
|
||||
// Adjustments
|
||||
$placeholder += sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $stat->post_name, 0 );
|
||||
endif;
|
||||
// Add equation to object
|
||||
$stat->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, null );
|
||||
$stat->precision = sp_array_value( sp_array_value( $meta, 'sp_precision', array() ), 0, 0 );
|
||||
|
||||
// Add column name to columns
|
||||
$columns[ $stat->post_name ] = $stat->post_title;
|
||||
|
||||
$placeholders[ $player_id ][ $stat->post_name ] = $placeholder;
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
endforeach;
|
||||
// Fill in empty placeholder values for each player
|
||||
foreach ( $player_ids as $player_id ):
|
||||
if ( ! $player_id )
|
||||
continue;
|
||||
|
||||
$variables = array_merge( sp_array_value( $totals, $player_id, array() ), array_filter( sp_array_value( $placeholders, $player_id, array() ) ) );
|
||||
|
||||
foreach ( $stats as $stat ):
|
||||
if ( sp_array_value( $placeholders[ $player_id ], $stat->post_name, '' ) == '' ):
|
||||
|
||||
if ( $stat->equation == null ):
|
||||
$placeholder = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $stat->post_name, null );
|
||||
if ( $placeholder == null ):
|
||||
$placeholder = '-';
|
||||
endif;
|
||||
else:
|
||||
// Solve
|
||||
$placeholder = sp_solve( $stat->equation, $variables, $stat->precision );
|
||||
|
||||
// Adjustments
|
||||
$placeholder += sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $stat->post_name, 0 );
|
||||
endif;
|
||||
|
||||
$placeholders[ $player_id ][ $stat->post_name ] = $placeholder;
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
endforeach;
|
||||
|
||||
endif;
|
||||
|
||||
// Merge the data and placeholders arrays
|
||||
$merged = array();
|
||||
|
||||
Reference in New Issue
Block a user