Add precision to event result equations

This commit is contained in:
Brian Miyaji
2015-09-20 22:25:12 +10:00
parent ce8675e064
commit 805e83b7d1
2 changed files with 16 additions and 3 deletions

View File

@@ -86,10 +86,10 @@ class SP_Meta_Box_Event_Results {
$dynamic_results = get_posts( $args );
$equations = array();
$precisions = array();
$precision = array();
foreach ( $dynamic_results as $result ) {
$equations[ $result->post_name ] = get_post_meta( $result->ID, 'sp_equation', true );
$precisions[ $result->post_name ] = (int) get_post_meta( $result->ID, 'sp_precision', true );
$precision[ $result->post_name ] = (int) get_post_meta( $result->ID, 'sp_precision', true );
}
@@ -109,7 +109,7 @@ class SP_Meta_Box_Event_Results {
}
$totals[ 'eventsplayed' ] = 1;
$totals = apply_filters( 'sportspress_event_result_equation_vars', $totals, $performance, $team );
$results[ $team ][ $key ] = sp_solve( $equation, $totals, sp_array_value( $precisions, $key, 0 ), '' );
$results[ $team ][ $key ] = sp_solve( $equation, $totals, sp_array_value( $precision, $key, 0 ), '' );
}
}
}

View File

@@ -23,6 +23,7 @@ class SP_Meta_Box_Result_Details extends SP_Meta_Box_Config {
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$precision = get_post_meta( $post->ID, 'sp_precision', true );
global $pagenow;
if ( 'post.php' == $pagenow && 'draft' !== get_post_status() ) {
$readonly = true;
@@ -35,6 +36,18 @@ class SP_Meta_Box_Result_Details extends SP_Meta_Box_Config {
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>"<?php if ( $readonly ) { ?> readonly="readonly"<?php } ?>> <span class="description">(for, against)</span>
</p>
<p><strong><?php _e( 'Decimal Places', 'sportspress' ); ?></strong></p>
<p class="sp-precision-selector">
<input name="sp_precision" type="text" size="4" id="sp_precision" value="<?php echo $precision; ?>" placeholder="0">
</p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
self::delete_duplicate( $_POST );
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
}
}