Add option to record minutes for individual statistics

This commit is contained in:
Brian Miyaji
2016-12-20 20:22:26 +11:00
parent f4f1ce79a4
commit b0adfc1177
4 changed files with 73 additions and 25 deletions

View File

@@ -364,21 +364,27 @@ jQuery(document).ready(function($){
// Format selector // Format selector
$(".sp-format-selector select:first").change(function() { $(".sp-format-selector select:first").change(function() {
$precisionselector = $(".sp-precision-selector input:first"); $precisiondiv = $("#sp_precisiondiv");
$precisioninput = $("#sp_precision");
$timeddiv = $("#sp_timeddiv");
$equationdiv = $("#sp_equationdiv"); $equationdiv = $("#sp_equationdiv");
// Precision settings
if($(this).val() == "decimal" || $(this).val() == "time") {
$precisionselector.prop( "disabled", false );
} else {
$precisionselector.prop( "disabled", true )
}
// Equation settings // Equation settings
if ($(this).val() == "equation") { if ($(this).val() == "equation") {
$equationdiv.show(); $equationdiv.show();
$precisiondiv.show();
$timeddiv.hide();
$precisioninput.prop( "disabled", false );
} else if ($(this).val() == "number") {
$equationdiv.hide();
$precisiondiv.hide();
$timeddiv.show();
$precisioninput.prop( "disabled", true );
} else { } else {
$equationdiv.hide(); $equationdiv.hide();
$precisiondiv.hide();
$timeddiv.hide();
$precisioninput.prop( "disabled", true );
} }
}); });

View File

@@ -20,7 +20,7 @@ class SP_Meta_Box_Event_Performance {
*/ */
public static function output( $post ) { public static function output( $post ) {
$event = new SP_Event( $post ); $event = new SP_Event( $post );
list( $labels, $columns, $stats, $teams, $formats, $order ) = $event->performance( true ); list( $labels, $columns, $stats, $teams, $formats, $order, $timed ) = $event->performance( true );
if ( 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'yes' ) ) if ( 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'yes' ) )
$timeline = $event->timeline( true ); $timeline = $event->timeline( true );
@@ -65,7 +65,7 @@ class SP_Meta_Box_Event_Performance {
// Check if individual mode // Check if individual mode
$is_individual = get_option( 'sportspress_load_individual_mode_module', 'no' ) === 'yes' ? true : false; $is_individual = get_option( 'sportspress_load_individual_mode_module', 'no' ) === 'yes' ? true : false;
self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order, $numbers, $is_individual, $timeline ); self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order, $numbers, $is_individual, $timeline, $timed );
} }
/** /**
@@ -81,7 +81,7 @@ class SP_Meta_Box_Event_Performance {
/** /**
* Admin edit tables * Admin edit tables
*/ */
public static function tables( $post_id, $stats = array(), $labels = array(), $columns = array(), $teams = array(), $has_checkboxes = false, $positions = array(), $status = true, $formats = array(), $order = array(), $numbers = true, $is_individual = false, $timeline = array() ) { public static function tables( $post_id, $stats = array(), $labels = array(), $columns = array(), $teams = array(), $has_checkboxes = false, $positions = array(), $status = true, $formats = array(), $order = array(), $numbers = true, $is_individual = false, $timeline = array(), $timed = array() ) {
$sections = get_option( 'sportspress_event_performance_sections', -1 ); $sections = get_option( 'sportspress_event_performance_sections', -1 );
if ( $is_individual ) { if ( $is_individual ) {
@@ -116,7 +116,7 @@ class SP_Meta_Box_Event_Performance {
$player_timeline = false; $player_timeline = false;
endif; endif;
self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, false, $numbers, -1, $formats, $player_timeline ); self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, false, $numbers, -1, $formats, $player_timeline, $timed );
endforeach; endforeach;
endforeach; endforeach;
?> ?>
@@ -145,7 +145,7 @@ class SP_Meta_Box_Event_Performance {
?> ?>
<div> <div>
<p><strong><?php echo get_the_title( $team_id ); ?></strong></p> <p><strong><?php echo get_the_title( $team_id ); ?></strong></p>
<?php self::table( $labels, $columns, $data, $team_id, $has_checkboxes, $positions, $status, -1, $formats, $order, $numbers, $team_timeline ); ?> <?php self::table( $labels, $columns, $data, $team_id, $has_checkboxes, $positions, $status, -1, $formats, $order, $numbers, $team_timeline, $timed ); ?>
<?php do_action( 'sportspress_after_event_performance_table_admin', $labels, $columns, $data, $team_id ); ?> <?php do_action( 'sportspress_after_event_performance_table_admin', $labels, $columns, $data, $team_id ); ?>
</div> </div>
<?php } else { ?> <?php } else { ?>
@@ -227,7 +227,7 @@ class SP_Meta_Box_Event_Performance {
?> ?>
<div> <div>
<p><strong><?php echo get_the_title( $team_id ); ?> &mdash; <?php echo $section_label; ?></strong></p> <p><strong><?php echo get_the_title( $team_id ); ?> &mdash; <?php echo $section_label; ?></strong></p>
<?php self::table( $labels[ $section_id ], $columns, $data[ $section_id ], $team_id, ( $has_checkboxes && 0 === $i ), $positions, $status, $section_id, $formats, $order, $numbers, $team_timeline ); ?> <?php self::table( $labels[ $section_id ], $columns, $data[ $section_id ], $team_id, ( $has_checkboxes && 0 === $i ), $positions, $status, $section_id, $formats, $order, $numbers, $team_timeline, $timed ); ?>
<?php do_action( 'sportspress_after_event_performance_table_admin', $labels[ $section_id ], $columns, $data[ $section_id ], $team_id ); ?> <?php do_action( 'sportspress_after_event_performance_table_admin', $labels[ $section_id ], $columns, $data[ $section_id ], $team_id ); ?>
</div> </div>
<?php <?php
@@ -241,7 +241,7 @@ class SP_Meta_Box_Event_Performance {
/** /**
* Admin edit table * Admin edit table
*/ */
public static function table( $labels = array(), $columns = array(), $data = array(), $team_id, $has_checkboxes = false, $positions = array(), $status = true, $section = -1, $formats = array(), $order = array(), $numbers = true, $team_timeline = array() ) { public static function table( $labels = array(), $columns = array(), $data = array(), $team_id, $has_checkboxes = false, $positions = array(), $status = true, $section = -1, $formats = array(), $order = array(), $numbers = true, $team_timeline = array(), $timed = array() ) {
?> ?>
<div class="sp-data-table-container"> <div class="sp-data-table-container">
<table class="widefat sp-data-table sp-performance-table sp-sortable-table"> <table class="widefat sp-data-table sp-performance-table sp-sortable-table">
@@ -276,7 +276,7 @@ class SP_Meta_Box_Event_Performance {
$player_timeline = false; $player_timeline = false;
endif; endif;
self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, $numbers, $section, $formats, $player_timeline ); self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, $numbers, $section, $formats, $player_timeline, $timed );
endforeach; endforeach;
?> ?>
@@ -369,7 +369,7 @@ class SP_Meta_Box_Event_Performance {
/** /**
* Admin edit table row * Admin edit table row
*/ */
public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true, $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array(), $player_timeline = array() ) { public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true, $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array(), $player_timeline = array(), $timed = array() ) {
if ( $player_id <= 0 ) return; if ( $player_id <= 0 ) return;
$value = sp_array_value( $player_performance, 'number', '' ); $value = sp_array_value( $player_performance, 'number', '' );
@@ -419,7 +419,7 @@ class SP_Meta_Box_Event_Performance {
?> ?>
<td> <td>
<input class="sp-player-<?php echo $column; ?>-input sp-sync-input" type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo $placeholder; ?>" /> <input class="sp-player-<?php echo $column; ?>-input sp-sync-input" type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo $placeholder; ?>" />
<?php if ( $intval ) { ?> <?php if ( $intval && in_array( $column, $timed ) ) { ?>
<?php <?php
// Get performance times // Get performance times
if ( is_array( $player_timeline ) ) { if ( is_array( $player_timeline ) ) {

View File

@@ -40,6 +40,13 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
$format = 'number'; $format = 'number';
} }
$precision = get_post_meta( $post->ID, 'sp_precision', true ); $precision = get_post_meta( $post->ID, 'sp_precision', true );
if ( '' === $precision ) {
$precision = 0;
}
$timed = get_post_meta( $post->ID, 'sp_timed', true );
if ( '' === $timed ) {
$timed = false;
}
?> ?>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p> <p>
@@ -68,10 +75,32 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
?> ?>
</select> </select>
</p> </p>
<div id="sp_precisiondiv">
<p><strong><?php _e( 'Decimal Places', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Decimal Places', 'sportspress' ); ?></strong></p>
<p> <p>
<input name="sp_precision" type="text" size="4" id="sp_precision" value="<?php echo $precision; ?>" placeholder="0"> <input name="sp_precision" type="text" size="4" id="sp_precision" value="<?php echo $precision; ?>" placeholder="0">
</p> </p>
</div>
<div id="sp_timeddiv">
<p>
<strong><?php _e( 'Timed', 'sportspress' ); ?></strong>
<i class="dashicons dashicons-editor-help sp-desc-tip" title="<?php _e( 'Record minutes?', 'sportspress' ); ?>"></i>
</p>
<ul class="sp-timed-selector">
<li>
<label class="selectit">
<input name="sp_timed" id="sp_timed_yes" type="radio" value="1" <?php checked( $timed ); ?>>
<?php _e( 'Yes', 'sportspress' ); ?>
</label>
</li>
<li>
<label class="selectit">
<input name="sp_timed" id="sp_timed_no" type="radio" value="0" <?php checked( ! $timed ); ?>>
<?php _e( 'No', 'sportspress' ); ?>
</label>
</li>
</ul>
</div>
<?php <?php
if ( 'auto' === get_option( 'sportspress_player_columns', 'auto' ) ) { if ( 'auto' === get_option( 'sportspress_player_columns', 'auto' ) ) {
$visible = get_post_meta( $post->ID, 'sp_visible', true ); $visible = get_post_meta( $post->ID, 'sp_visible', true );
@@ -109,6 +138,7 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
update_post_meta( $post_id, 'sp_section', (int) sp_array_value( $_POST, 'sp_section', -1 ) ); update_post_meta( $post_id, 'sp_section', (int) sp_array_value( $_POST, 'sp_section', -1 ) );
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'number' ) ); update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'number' ) );
update_post_meta( $post_id, 'sp_precision', sp_array_value( $_POST, 'sp_precision', 0 ) ); update_post_meta( $post_id, 'sp_precision', sp_array_value( $_POST, 'sp_precision', 0 ) );
update_post_meta( $post_id, 'sp_timed', sp_array_value( $_POST, 'sp_timed', 0 ) );
if ( 'auto' === get_option( 'sportspress_player_columns', 'auto' ) ) { if ( 'auto' === get_option( 'sportspress_player_columns', 'auto' ) ) {
update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1 ) ); update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1 ) );
} }

View File

@@ -98,15 +98,24 @@ class SP_Event extends SP_Custom_Post{
$labels = array(); $labels = array();
$formats = array(); $formats = array();
$timed = array();
$equations = array(); $equations = array();
foreach ( $vars as $var ) { foreach ( $vars as $var ) {
$labels[ $var->post_name ] = $var->post_title; $labels[ $var->post_name ] = $var->post_title;
$format = get_post_meta( $var->ID, 'sp_format', true ); $format = get_post_meta( $var->ID, 'sp_format', true );
if ( '' === $format ) { if ( '' === $format ) {
$format = 'number'; $format = 'number';
} }
$formats[ $var->post_name ] = $format; $formats[ $var->post_name ] = $format;
if ( 'number' === $format ) {
$is_timed = get_post_meta( $var->ID, 'sp_timed', true );
if ( $is_timed ) {
$timed[] = $var->post_name;
}
}
if ( 'equation' === $format ) { if ( 'equation' === $format ) {
$equation = get_post_meta( $var->ID, 'sp_equation', true ); $equation = get_post_meta( $var->ID, 'sp_equation', true );
$precision = get_post_meta( $var->ID, 'sp_precision', true ); $precision = get_post_meta( $var->ID, 'sp_precision', true );
@@ -162,7 +171,7 @@ class SP_Event extends SP_Custom_Post{
endif; endif;
if ( $admin ): if ( $admin ):
return array( $labels, $columns, $performance, $teams, $formats, $order ); return array( $labels, $columns, $performance, $teams, $formats, $order, $timed );
else: else:
// Add position to performance labels // Add position to performance labels
if ( taxonomy_exists( 'sp_position' ) ): if ( taxonomy_exists( 'sp_position' ) ):
@@ -220,6 +229,9 @@ class SP_Event extends SP_Custom_Post{
foreach ( $player_performance as $performance_key => $performance_value ): foreach ( $player_performance as $performance_key => $performance_value ):
// Continue if not timed
if ( ! in_array( $performance_key, $timed ) ) continue;
// Get performance times // Get performance times
$times = sp_array_value( $player_timeline, $performance_key, array() ); $times = sp_array_value( $player_timeline, $performance_key, array() );
$times = array_filter( $times ); $times = array_filter( $times );