Add player performance times to events
This commit is contained in:
@@ -124,7 +124,7 @@
|
|||||||
.sp-icon-statistics:before {
|
.sp-icon-statistics:before {
|
||||||
content: "\f489";
|
content: "\f489";
|
||||||
}
|
}
|
||||||
.sp-icon-stopwatch:before {
|
.sp-icon-time:before {
|
||||||
content: "\f469";
|
content: "\f469";
|
||||||
}
|
}
|
||||||
.sp-icon-ticket:before {
|
.sp-icon-ticket:before {
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ jQuery(document).ready(function($){
|
|||||||
if(event.keyCode == 40){
|
if(event.keyCode == 40){
|
||||||
row += 1;
|
row += 1;
|
||||||
}
|
}
|
||||||
$el.closest("tbody").find("tr:nth-child("+row+") td:nth-child("+col+") input:text").focus();
|
$el.closest("tbody").find("tr:nth-child("+row+") td:nth-child("+col+") input:text").first().focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
$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 ) = $event->performance( true );
|
||||||
|
|
||||||
|
if ( 'yes' == get_option( 'sportspress_event_performance_show_time', 'yes' ) )
|
||||||
|
$timeline = $event->timeline( true );
|
||||||
|
else
|
||||||
|
$timeline = false;
|
||||||
|
|
||||||
// Determine if columns are auto or manual
|
// Determine if columns are auto or manual
|
||||||
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) )
|
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) )
|
||||||
$manual = true;
|
$manual = true;
|
||||||
@@ -60,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 );
|
self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order, $numbers, $is_individual, $timeline );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,12 +75,13 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) );
|
update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) );
|
||||||
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
|
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
|
||||||
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
|
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
|
||||||
|
update_post_meta( $post_id, 'sp_timeline', sp_array_value( $_POST, 'sp_timeline', array() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 ) {
|
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() ) {
|
||||||
$sections = get_option( 'sportspress_event_performance_sections', -1 );
|
$sections = get_option( 'sportspress_event_performance_sections', -1 );
|
||||||
|
|
||||||
if ( $is_individual ) {
|
if ( $is_individual ) {
|
||||||
@@ -94,8 +100,23 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
$players[] = -1;
|
$players[] = -1;
|
||||||
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
|
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
|
||||||
|
|
||||||
|
// Get team timeline
|
||||||
|
if ( is_array( $timeline ) ):
|
||||||
|
$team_timeline = (array) sp_array_value( $timeline, $team_id, array() );
|
||||||
|
else:
|
||||||
|
$team_timeline = false;
|
||||||
|
endif;
|
||||||
|
|
||||||
foreach ( $data as $player_id => $player_performance ):
|
foreach ( $data as $player_id => $player_performance ):
|
||||||
self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, false, $numbers, -1, $formats );
|
|
||||||
|
// Get player timeline
|
||||||
|
if ( is_array( $team_timeline ) ):
|
||||||
|
$player_timeline = (array) sp_array_value( $team_timeline, $player_id, array() );
|
||||||
|
else:
|
||||||
|
$player_timeline = false;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, false, $numbers, -1, $formats, $player_timeline );
|
||||||
endforeach;
|
endforeach;
|
||||||
endforeach;
|
endforeach;
|
||||||
?>
|
?>
|
||||||
@@ -114,10 +135,17 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
$players = sp_array_between( (array)get_post_meta( $post_id, 'sp_player', false ), 0, $key );
|
$players = sp_array_between( (array)get_post_meta( $post_id, 'sp_player', false ), 0, $key );
|
||||||
$players[] = -1;
|
$players[] = -1;
|
||||||
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
|
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
|
||||||
|
|
||||||
|
// Get team timeline
|
||||||
|
if ( is_array( $timeline ) ):
|
||||||
|
$team_timeline = (array) sp_array_value( $timeline, $team_id, array() );
|
||||||
|
else:
|
||||||
|
$team_timeline = false;
|
||||||
|
endif;
|
||||||
?>
|
?>
|
||||||
<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 ); ?>
|
<?php self::table( $labels, $columns, $data, $team_id, $has_checkboxes, $positions, $status, -1, $formats, $order, $numbers, $team_timeline ); ?>
|
||||||
<?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 { ?>
|
||||||
@@ -167,6 +195,13 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
$players[] = -1;
|
$players[] = -1;
|
||||||
$data[0] = $data[1] = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
|
$data[0] = $data[1] = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get team timeline
|
||||||
|
if ( is_array( $timeline ) ):
|
||||||
|
$team_timeline = (array) sp_array_value( $timeline, $team_id, array() );
|
||||||
|
else:
|
||||||
|
$team_timeline = false;
|
||||||
|
endif;
|
||||||
|
|
||||||
// Determine order of sections
|
// Determine order of sections
|
||||||
if ( 1 == $sections ) {
|
if ( 1 == $sections ) {
|
||||||
@@ -179,7 +214,7 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
?>
|
?>
|
||||||
<div>
|
<div>
|
||||||
<p><strong><?php echo get_the_title( $team_id ); ?> — <?php echo $section_label; ?></strong></p>
|
<p><strong><?php echo get_the_title( $team_id ); ?> — <?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 ); ?>
|
<?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 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
|
||||||
@@ -193,7 +228,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 ) {
|
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() ) {
|
||||||
?>
|
?>
|
||||||
<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">
|
||||||
@@ -218,8 +253,18 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
}
|
}
|
||||||
$data = $players;
|
$data = $players;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $data as $player_id => $player_performance ):
|
foreach ( $data as $player_id => $player_performance ):
|
||||||
self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, $numbers, $section, $formats );
|
|
||||||
|
// Get player timeline
|
||||||
|
if ( is_array( $team_timeline ) ):
|
||||||
|
$player_timeline = (array) sp_array_value( $team_timeline, $player_id, array() );
|
||||||
|
else:
|
||||||
|
$player_timeline = false;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, $numbers, $section, $formats, $player_timeline );
|
||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
?>
|
?>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -309,7 +354,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() ) {
|
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() ) {
|
||||||
if ( $player_id <= 0 ) return;
|
if ( $player_id <= 0 ) return;
|
||||||
|
|
||||||
$value = sp_array_value( $player_performance, 'number', '' );
|
$value = sp_array_value( $player_performance, 'number', '' );
|
||||||
@@ -353,10 +398,29 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php foreach( $labels as $column => $label ):
|
<?php foreach( $labels as $column => $label ):
|
||||||
$value = sp_array_value( $player_performance, $column, '' );
|
$value = sp_array_value( $player_performance, $column, '' );
|
||||||
|
$intval = intval( $value );
|
||||||
$placeholder = sp_get_format_placeholder( sp_array_value( $formats, $column, 'number' ) );
|
$placeholder = sp_get_format_placeholder( sp_array_value( $formats, $column, 'number' ) );
|
||||||
?>
|
?>
|
||||||
<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
|
||||||
|
// Get performance times
|
||||||
|
if ( is_array( $player_timeline ) ) {
|
||||||
|
$times = sp_array_value( $player_timeline, $column, array() );
|
||||||
|
} else {
|
||||||
|
$times = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_array( $times ) ) {
|
||||||
|
?>
|
||||||
|
<hr>
|
||||||
|
<?php for ( $i = 0; $i < $intval; $i++ ) { ?><input class="sp-sync-input small-text" type="text" name="sp_timeline[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>][<?php echo $i; ?>]" value="<?php echo esc_attr( sp_array_value( $times, $i, '' ) ); ?>" placeholder="-" /><?php } ?>
|
||||||
|
<span class="description"><?php _e( 'mins', 'sportspress' ); ?></span>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
</td>
|
</td>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if ( apply_filters( 'sportspress_event_performance_show_status', $status, $section ) ) { ?>
|
<?php if ( apply_filters( 'sportspress_event_performance_show_status', $status, $section ) ) { ?>
|
||||||
|
|||||||
@@ -351,8 +351,8 @@ class SP_Settings_Events extends SP_Settings_Page {
|
|||||||
),
|
),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
'title' => __( 'Players', 'sportspress' ),
|
'title' => __( 'Display', 'sportspress' ),
|
||||||
'desc' => __( 'Display squad numbers', 'sportspress' ),
|
'desc' => __( 'Squad Number', 'sportspress' ),
|
||||||
'id' => 'sportspress_event_show_player_numbers',
|
'id' => 'sportspress_event_show_player_numbers',
|
||||||
'default' => 'yes',
|
'default' => 'yes',
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
@@ -360,12 +360,20 @@ class SP_Settings_Events extends SP_Settings_Page {
|
|||||||
),
|
),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
'desc' => __( 'Display positions', 'sportspress' ),
|
'desc' => __( 'Position', 'sportspress' ),
|
||||||
'id' => 'sportspress_event_show_position',
|
'id' => 'sportspress_event_show_position',
|
||||||
'default' => 'yes',
|
'default' => 'yes',
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'checkboxgroup' => '',
|
'checkboxgroup' => '',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
'desc' => __( 'Time', 'sportspress' ),
|
||||||
|
'id' => 'sportspress_event_performance_show_time',
|
||||||
|
'default' => 'yes',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'checkboxgroup' => 'end',
|
||||||
|
),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
'title' => __( 'Performance', 'sportspress' ),
|
'title' => __( 'Performance', 'sportspress' ),
|
||||||
|
|||||||
@@ -164,10 +164,47 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
if ( 'no' == get_option( 'sportspress_event_show_player_numbers', 'yes' ) ):
|
if ( 'no' == get_option( 'sportspress_event_show_player_numbers', 'yes' ) ):
|
||||||
unset( $labels['number'] );
|
unset( $labels['number'] );
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
if ( 'yes' == get_option( 'sportspress_event_performance_show_time', 'yes' ) ):
|
||||||
|
$timeline = $this->timeline();
|
||||||
|
if ( ! empty( $timeline ) ):
|
||||||
|
foreach ( $performance as $team => $players ):
|
||||||
|
|
||||||
|
// Get team timeline
|
||||||
|
$team_timeline = sp_array_value( $timeline, $team, array() );
|
||||||
|
if ( empty( $team_timeline ) ) continue;
|
||||||
|
|
||||||
|
foreach ( $players as $player => $player_performance ):
|
||||||
|
if ( ! $player_id ) continue;
|
||||||
|
|
||||||
|
// Get player timeline
|
||||||
|
$player_timeline = sp_array_value( $team_timeline, $player, array() );
|
||||||
|
if ( empty( $player_timeline ) ) continue;
|
||||||
|
|
||||||
|
foreach ( $player_performance as $performance_key => $performance_value ):
|
||||||
|
|
||||||
|
// Get performance times
|
||||||
|
$times = sp_array_value( $player_timeline, $performance_key, array() );
|
||||||
|
$times = array_filter( $times );
|
||||||
|
if ( empty( $times ) ) continue;
|
||||||
|
|
||||||
|
$performance[ $team ][ $player ][ $performance_key ] .= ' (' . implode( '\', ', $times ) . '\')';
|
||||||
|
endforeach;
|
||||||
|
endforeach;
|
||||||
|
endforeach;
|
||||||
|
endif;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Add labels to box score
|
||||||
$performance[0] = $labels;
|
$performance[0] = $labels;
|
||||||
|
|
||||||
return apply_filters( 'sportspress_get_event_performance', $performance );
|
return apply_filters( 'sportspress_get_event_performance', $performance );
|
||||||
endif;
|
endif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function timeline( $admin = false) {
|
||||||
|
return (array) get_post_meta( $this->ID, 'sp_timeline', true );
|
||||||
|
}
|
||||||
|
|
||||||
public function main_results() {
|
public function main_results() {
|
||||||
// Get main result option
|
// Get main result option
|
||||||
|
|||||||
@@ -407,6 +407,7 @@ class SP_Install {
|
|||||||
|
|
||||||
if ( version_compare( $version, '2.1', '<' ) ) {
|
if ( version_compare( $version, '2.1', '<' ) ) {
|
||||||
update_option( 'sportspress_player_show_selector', 'no' );
|
update_option( 'sportspress_player_show_selector', 'no' );
|
||||||
|
update_option( 'sportspress_event_performance_show_time', 'no' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,12 @@ class SportsPress_Icons {
|
|||||||
if ( null !== $icon && in_array( $icon, $this->icons ) ) {
|
if ( null !== $icon && in_array( $icon, $this->icons ) ) {
|
||||||
$title = get_the_title( $id );
|
$title = get_the_title( $id );
|
||||||
$color = get_post_meta( $id, 'sp_color', true );
|
$color = get_post_meta( $id, 'sp_color', true );
|
||||||
$icons = str_repeat( '<i class="sp-icon-' . $icon . '" title="' . $title . '" style="color:' . $color . '"></i>' . ' ', $value );
|
preg_match( '#\((.*?)\)#', $value, $match );
|
||||||
|
if ( ! empty( $match ) && isset( $match[1] ) ) {
|
||||||
|
$icons = '<i class="sp-icon-' . $icon . '" title="' . $title . '" style="color:' . $color . '"></i> ' . $match[1] . '<br>';
|
||||||
|
} else {
|
||||||
|
$icons = str_repeat( '<i class="sp-icon-' . $icon . '" title="' . $title . '" style="color:' . $color . '"></i> ', intval( $value ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $icons;
|
return $icons;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user