Add total type selector for average-based player statistics
This commit is contained in:
@@ -33,16 +33,16 @@ class SP_Meta_Box_Player_Statistics {
|
||||
?>
|
||||
<p><strong><?php echo $league->name; ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes, $formats ) = $player->data( $league->term_id, true );
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0, true, $formats );
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes, $formats, $total_types ) = $player->data( $league->term_id, true );
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0, true, $formats, $total_types );
|
||||
$i ++;
|
||||
endforeach;
|
||||
if ( $show_career_totals ) {
|
||||
?>
|
||||
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true );
|
||||
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes, $formats, $total_types ) = $player->data( 0, true );
|
||||
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams, false, false, $formats, $total_types );
|
||||
}
|
||||
} else {
|
||||
// Determine order of sections
|
||||
@@ -60,16 +60,16 @@ class SP_Meta_Box_Player_Statistics {
|
||||
?>
|
||||
<p><strong><?php echo $league->name; ?> — <?php echo $section_label; ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes ) = $player->data( $league->term_id, true, $section_id );
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0 && $s == 0, $s == 0 );
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes, $formats, $total_types ) = $player->data( $league->term_id, true, $section_id );
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0 && $s == 0, $s == 0, $formats, $total_types );
|
||||
$i ++;
|
||||
endforeach;
|
||||
if ( $show_career_totals ) {
|
||||
?>
|
||||
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?> — <?php echo $section_label; ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true, $section_id );
|
||||
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0 && $s == 0, $s == 0 );
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes, $formats, $total_types ) = $player->data( 0, true, $section_id );
|
||||
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0 && $s == 0, $s == 0, $formats, $total_types );
|
||||
}
|
||||
$s ++;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class SP_Meta_Box_Player_Statistics {
|
||||
/**
|
||||
* Admin edit table
|
||||
*/
|
||||
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $has_checkboxes = false, $team_select = false, $formats = array() ) {
|
||||
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $has_checkboxes = false, $team_select = false, $formats = array(), $total_types = array() ) {
|
||||
$readonly = false;
|
||||
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
|
||||
?>
|
||||
@@ -124,7 +124,7 @@ class SP_Meta_Box_Player_Statistics {
|
||||
if ( $readonly )
|
||||
echo $value ? $value : $placeholder;
|
||||
else
|
||||
echo '<input type="text" name="sp_statistics[' . $league_id . '][0][' . $column . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-sp-format="number" />';
|
||||
echo '<input type="text" name="sp_statistics[' . $league_id . '][0][' . $column . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-sp-format="number" data-sp-total-type="' . sp_array_value( $total_types, $column, 'total' ) . '" />';
|
||||
?></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
|
||||
@@ -26,6 +26,7 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
|
||||
$precision = get_post_meta( $post->ID, 'sp_precision', true );
|
||||
$section = get_post_meta( $post->ID, 'sp_section', true );
|
||||
$format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
$total = get_post_meta( $post->ID, 'sp_total_type', true );
|
||||
$visible = get_post_meta( $post->ID, 'sp_visible', true );
|
||||
|
||||
// Defaults
|
||||
@@ -65,6 +66,17 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<select name="sp_total_type">
|
||||
<?php
|
||||
$options = apply_filters( 'sportspress_statistic_totals', array( 'total' => __( 'Total', 'sportspress' ), 'average' => __( 'Average', 'sportspress' ) ) );
|
||||
foreach ( $options as $key => $value ):
|
||||
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $total, true, false ), $value );
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<strong><?php _e( 'Visible', 'sportspress' ); ?></strong>
|
||||
<i class="dashicons dashicons-editor-help sp-desc-tip" title="<?php _e( 'Display in player profile?', 'sportspress' ); ?>"></i>
|
||||
@@ -92,6 +104,7 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
|
||||
public static function save( $post_id, $post ) {
|
||||
self::delete_duplicate( $_POST );
|
||||
update_post_meta( $post_id, 'sp_section', (int) sp_array_value( $_POST, 'sp_section', -1 ) );
|
||||
update_post_meta( $post_id, 'sp_total_type', sp_array_value( $_POST, 'sp_total_type', 'total' ) );
|
||||
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'number' ) );
|
||||
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
|
||||
update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1 ) );
|
||||
|
||||
Reference in New Issue
Block a user