Round using precision setting
This commit is contained in:
@@ -2,30 +2,30 @@
|
||||
function sportspress_restrict_manage_posts() {
|
||||
sportspress_highlight_admin_menu();
|
||||
global $typenow, $wp_query;
|
||||
if ( in_array( $typenow, array( 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' ) ) ):
|
||||
$selected = isset( $_REQUEST['sp_team'] ) ? $_REQUEST['sp_team'] : null;
|
||||
$args = array(
|
||||
'show_option_none' => __( 'All Teams', 'sportspress' ),
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_team',
|
||||
'selected' => $selected
|
||||
);
|
||||
// wp_dropdown_pages( $args );
|
||||
endif;
|
||||
if ( in_array( $typenow, array( 'sp_player' ) ) ):
|
||||
$selected = isset( $_REQUEST['sp_position'] ) ? $_REQUEST['sp_position'] : null;
|
||||
$args = array(
|
||||
'show_option_all' => __( 'All Positions', 'sportspress' ),
|
||||
'show_option_all' => __( 'Show all positions', 'sportspress' ),
|
||||
'taxonomy' => 'sp_position',
|
||||
'name' => 'sp_position',
|
||||
'selected' => $selected
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
endif;
|
||||
if ( in_array( $typenow, array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' ) ) ):
|
||||
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
|
||||
$args = array(
|
||||
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'selected' => $selected
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
endif;
|
||||
if ( in_array( $typenow, array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' ) ) ):
|
||||
$selected = isset( $_REQUEST['sp_season'] ) ? $_REQUEST['sp_season'] : null;
|
||||
$args = array(
|
||||
'show_option_all' => __( 'All Seasons', 'sportspress' ),
|
||||
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'selected' => $selected
|
||||
@@ -37,7 +37,7 @@ function sportspress_restrict_manage_posts() {
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'team',
|
||||
'show_option_none' => __( 'All Teams', 'sportspress' ),
|
||||
'show_option_none' => __( 'Show all teams', 'sportspress' ),
|
||||
'selected' => $selected,
|
||||
'values' => 'ID',
|
||||
);
|
||||
|
||||
@@ -33,7 +33,7 @@ function sportspress_column_edit_columns() {
|
||||
'title' => __( 'Label', 'sportspress' ),
|
||||
'sp_key' => __( 'Key', 'sportspress' ),
|
||||
'sp_equation' => __( 'Equation', 'sportspress' ),
|
||||
'sp_precision' => __( 'Precision', 'sportspress' ),
|
||||
'sp_precision' => __( 'Rounding', 'sportspress' ),
|
||||
'sp_order' => __( 'Sort Order', 'sportspress' ),
|
||||
);
|
||||
return $columns;
|
||||
@@ -51,7 +51,7 @@ function sportspress_column_details_meta( $post ) {
|
||||
$precision = get_post_meta( $post->ID, 'sp_precision', true );
|
||||
|
||||
// Defaults
|
||||
if ( $precision == '' ) $precision = 1;
|
||||
if ( $precision == '' ) $precision = 0;
|
||||
?>
|
||||
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
@@ -65,9 +65,9 @@ function sportspress_column_details_meta( $post ) {
|
||||
endforeach;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Precision', 'sportspress' ); ?></strong></p>
|
||||
<p><strong><?php _e( 'Rounding', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-precision-selector">
|
||||
<input name="sp_precision" type="text" size="4" id="sp_precision" value="<?php echo $precision; ?>" placeholder="1">
|
||||
<input name="sp_precision" type="text" size="4" id="sp_precision" value="<?php echo $precision; ?>" placeholder="0">
|
||||
</p>
|
||||
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-order-selector">
|
||||
|
||||
@@ -15,7 +15,7 @@ $data = get_posts( $args );
|
||||
<th><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Equation', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Precision', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Rounding', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Sort Order', 'sportspress' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -566,12 +566,15 @@ if ( !function_exists( 'sportspress_equation_selector' ) ) {
|
||||
$constants[$i] = $i;
|
||||
endfor;
|
||||
|
||||
// Add 100 to constants
|
||||
$constants[100] = 100;
|
||||
|
||||
// Add constants to options
|
||||
$options[ __( 'Constants', 'sportspress' ) ] = (array) $constants;
|
||||
|
||||
?>
|
||||
<select name="sp_equation[]">
|
||||
<option value="">(<?php _e( '— Select —', 'sportspress' ); ?>)</option>
|
||||
<option value=""><?php _e( '— Select —', 'sportspress' ); ?></option>
|
||||
<?php
|
||||
|
||||
foreach ( $options as $label => $option ):
|
||||
@@ -642,7 +645,13 @@ if ( !function_exists( 'sportspress_get_var_equations' ) ) {
|
||||
$output = array();
|
||||
foreach ( $vars as $var ):
|
||||
$equation = get_post_meta( $var->ID, 'sp_equation', true );
|
||||
$output[ $var->post_name ] = $equation;
|
||||
if ( ! $equation ) $equation = 0;
|
||||
$precision = get_post_meta( $var->ID, 'sp_precision', true );
|
||||
if ( ! $precision ) $precision = 0;
|
||||
$output[ $var->post_name ] = array(
|
||||
'equation' => $equation,
|
||||
'precision' => $precision,
|
||||
);
|
||||
endforeach;
|
||||
|
||||
return $output;
|
||||
@@ -1229,7 +1238,7 @@ if ( !function_exists( 'sportspress_get_eos_safe_slug' ) ) {
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sportspress_solve' ) ) {
|
||||
function sportspress_solve( $equation, $vars ) {
|
||||
function sportspress_solve( $equation, $vars, $precision = 0 ) {
|
||||
|
||||
if ( strpos( $equation, '$streak' ) !== false ):
|
||||
|
||||
@@ -1283,7 +1292,7 @@ if ( !function_exists( 'sportspress_solve' ) ) {
|
||||
$eos = new eqEOS();
|
||||
|
||||
// Solve using EOS
|
||||
return round( $eos->solveIF( str_replace( ' ', '', $equation ), $vars ), 3 ); // TODO: add precision setting to each column with default set to 3
|
||||
return round( $eos->solveIF( str_replace( ' ', '', $equation ), $vars ), $precision );
|
||||
else:
|
||||
return 0;
|
||||
endif;
|
||||
@@ -1527,7 +1536,7 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) {
|
||||
// Generate array of placeholder values for each league
|
||||
$placeholders[ $div_id ] = array();
|
||||
foreach ( $equations as $key => $value ):
|
||||
$placeholders[ $div_id ][ $key ] = sportspress_solve( $value, $totals );
|
||||
$placeholders[ $div_id ][ $key ] = sportspress_solve( $value['equation'], $totals, $value['precision'] );
|
||||
endforeach;
|
||||
|
||||
endforeach;
|
||||
@@ -1771,6 +1780,7 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
||||
|
||||
// Add equation to object
|
||||
$stat->equation = sportspress_array_value( sportspress_array_value( $meta, 'sp_equation', array() ), 0, 0 );
|
||||
$stat->precision = sportspress_array_value( sportspress_array_value( $meta, 'sp_precision', array() ), 0, 0 );
|
||||
|
||||
// Add column name to columns
|
||||
$columns[ $stat->post_name ] = $stat->post_title;
|
||||
@@ -1796,7 +1806,7 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
||||
|
||||
foreach ( $stats as $stat ):
|
||||
if ( sportspress_array_value( $placeholders[ $team_id ], $stat->post_name, '' ) == '' ):
|
||||
$placeholders[ $team_id ][ $stat->post_name ] = sportspress_solve( $stat->equation, sportspress_array_value( $totals, $team_id, array() ) );
|
||||
$placeholders[ $team_id ][ $stat->post_name ] = sportspress_solve( $stat->equation, sportspress_array_value( $totals, $team_id, array() ), $stat->precision );
|
||||
endif;
|
||||
endforeach;
|
||||
endforeach;
|
||||
|
||||
@@ -12,7 +12,7 @@ $sportspress_sports['baseball'] = array(
|
||||
'meta' => array(
|
||||
'sp_equation' => '$w',
|
||||
'sp_format' => 'integer',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
'sp_priority' => 1,
|
||||
'sp_order' => 'DESC',
|
||||
),
|
||||
@@ -23,7 +23,7 @@ $sportspress_sports['baseball'] = array(
|
||||
'meta' => array(
|
||||
'sp_equation' => '$l',
|
||||
'sp_format' => 'integer',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
'sp_priority' => 2,
|
||||
'sp_order' => 'ASC',
|
||||
),
|
||||
@@ -34,15 +34,6 @@ $sportspress_sports['baseball'] = array(
|
||||
'meta' => array(
|
||||
'sp_equation' => '$w / $eventsplayed',
|
||||
'sp_format' => 'decimal',
|
||||
'sp_precision' => 3,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'post_title' => 'GB',
|
||||
'post_name' => 'gb',
|
||||
'meta' => array(
|
||||
'sp_equation' => '( $wmax + $l - $w - $lmax ) / 2',
|
||||
'sp_format' => 'decimal',
|
||||
'sp_precision' => 2,
|
||||
),
|
||||
),
|
||||
@@ -52,7 +43,7 @@ $sportspress_sports['baseball'] = array(
|
||||
'meta' => array(
|
||||
'sp_equation' => '$rfor',
|
||||
'sp_format' => 'integer',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
'sp_priority' => 3,
|
||||
'sp_order' => 'DESC',
|
||||
),
|
||||
@@ -63,7 +54,7 @@ $sportspress_sports['baseball'] = array(
|
||||
'meta' => array(
|
||||
'sp_equation' => '$ragainst',
|
||||
'sp_format' => 'integer',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -72,7 +63,7 @@ $sportspress_sports['baseball'] = array(
|
||||
'meta' => array(
|
||||
'sp_equation' => '$streak',
|
||||
'sp_format' => 'integer',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -87,7 +87,7 @@ $sportspress_sports['basketball'] = array(
|
||||
'post_title' => 'Pct',
|
||||
'post_name' => 'pct',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$w / $eventsplayed * 10 * 10',
|
||||
'sp_equation' => '$w / $eventsplayed * 100',
|
||||
),
|
||||
),
|
||||
array(
|
||||
|
||||
@@ -37,7 +37,7 @@ $sportspress_sports['rugby'] = array(
|
||||
'post_name' => 'p',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$eventsplayed',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -45,7 +45,7 @@ $sportspress_sports['rugby'] = array(
|
||||
'post_name' => 'w',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$w',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -53,7 +53,7 @@ $sportspress_sports['rugby'] = array(
|
||||
'post_name' => 'd',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$d',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -61,7 +61,7 @@ $sportspress_sports['rugby'] = array(
|
||||
'post_name' => 'l',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$l',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -69,7 +69,7 @@ $sportspress_sports['rugby'] = array(
|
||||
'post_name' => 'b',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$bonus',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -77,7 +77,7 @@ $sportspress_sports['rugby'] = array(
|
||||
'post_name' => 'f',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$pointsfor',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -85,7 +85,7 @@ $sportspress_sports['rugby'] = array(
|
||||
'post_name' => 'a',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$pointsagainst',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -93,7 +93,7 @@ $sportspress_sports['rugby'] = array(
|
||||
'post_name' => 'pd',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$pointsfor - $pointsagainst',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -101,7 +101,7 @@ $sportspress_sports['rugby'] = array(
|
||||
'post_name' => 'pts',
|
||||
'meta' => array(
|
||||
'sp_equation' => '( $w + $bonus ) * 2 + $d',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
'sp_priority' => '1',
|
||||
'sp_order' => 'DESC',
|
||||
),
|
||||
|
||||
@@ -62,7 +62,7 @@ $sportspress_sports['soccer'] = array(
|
||||
'post_name' => 'p',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$eventsplayed',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -70,7 +70,7 @@ $sportspress_sports['soccer'] = array(
|
||||
'post_name' => 'w',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$w',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -78,7 +78,7 @@ $sportspress_sports['soccer'] = array(
|
||||
'post_name' => 'd',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$d',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -86,7 +86,7 @@ $sportspress_sports['soccer'] = array(
|
||||
'post_name' => 'l',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$l',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -94,7 +94,7 @@ $sportspress_sports['soccer'] = array(
|
||||
'post_name' => 'f',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$goalsfor',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
'sp_priority' => '3',
|
||||
'sp_order' => 'DESC',
|
||||
),
|
||||
@@ -104,7 +104,7 @@ $sportspress_sports['soccer'] = array(
|
||||
'post_name' => 'a',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$goalsagainst',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -112,7 +112,7 @@ $sportspress_sports['soccer'] = array(
|
||||
'post_name' => 'gd',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$goalsfor - $goalsagainst',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
'sp_priority' => '2',
|
||||
'sp_order' => 'DESC',
|
||||
),
|
||||
@@ -122,7 +122,7 @@ $sportspress_sports['soccer'] = array(
|
||||
'post_name' => 'pts',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$w * 3 + $d',
|
||||
'sp_precision' => 1,
|
||||
'sp_precision' => 0,
|
||||
'sp_priority' => '1',
|
||||
'sp_order' => 'DESC',
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user