Add combined table for individual mode
This commit is contained in:
@@ -54,7 +54,10 @@ class SP_Meta_Box_Event_Performance {
|
||||
// Apply filters to labels
|
||||
$labels = apply_filters( 'sportspress_event_performance_labels_admin', $labels );
|
||||
|
||||
self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order );
|
||||
// Check if individual mode
|
||||
$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, $is_individual );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,9 +72,35 @@ class SP_Meta_Box_Event_Performance {
|
||||
/**
|
||||
* 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() ) {
|
||||
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(), $is_individual = false ) {
|
||||
$sections = get_option( 'sportspress_event_performance_sections', -1 );
|
||||
|
||||
if ( $is_individual ) {
|
||||
?>
|
||||
<div class="sp-data-table-container">
|
||||
<table class="widefat sp-data-table sp-performance-table sp-sortable-table">
|
||||
<?php self::header( $columns, $labels, $positions, $has_checkboxes, $status, false, false, -1, $formats ); ?>
|
||||
<?php self::footer( sp_array_value( $stats, -1 ), $labels, 0, $positions, $status, false, false, -1, $formats ); ?>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ( $teams as $key => $team_id ):
|
||||
if ( -1 == $team_id ) continue;
|
||||
|
||||
// Get results for players in the team
|
||||
$players = sp_array_between( (array)get_post_meta( $post_id, 'sp_player', false ), 0, $key );
|
||||
$players[] = -1;
|
||||
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
|
||||
|
||||
foreach ( $data as $player_id => $player_performance ):
|
||||
self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, false, false, -1, $formats );
|
||||
endforeach;
|
||||
endforeach;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
$i = 0;
|
||||
|
||||
foreach ( $teams as $key => $team_id ):
|
||||
@@ -160,6 +189,7 @@ class SP_Meta_Box_Event_Performance {
|
||||
$i ++;
|
||||
endforeach;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin edit table
|
||||
|
||||
@@ -74,6 +74,10 @@ if ( ! isset( $class ) ) $class = null;
|
||||
foreach ( $labels as $key => $label ):
|
||||
if ( in_array( $key, array( 'number', 'name' ) ) )
|
||||
continue;
|
||||
|
||||
$format = sp_array_value( $formats, $key, 'number' );
|
||||
$placeholder = sp_get_format_placeholder( $format );
|
||||
|
||||
$value = '—';
|
||||
if ( $key == 'position' ):
|
||||
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
|
||||
@@ -89,13 +93,16 @@ if ( ! isset( $class ) ) $class = null;
|
||||
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
|
||||
$value = $row[ $key ];
|
||||
else:
|
||||
$value = 0;
|
||||
$value = $placeholder;
|
||||
endif;
|
||||
endif;
|
||||
if ( ! array_key_exists( $key, $totals ) ):
|
||||
$totals[ $key ] = 0;
|
||||
$totals[ $key ] = $placeholder;
|
||||
endif;
|
||||
|
||||
if ( 'text' !== $format ) {
|
||||
$totals[ $key ] += $value;
|
||||
}
|
||||
|
||||
if ( $mode == 'values' ):
|
||||
echo '<td class="data-' . $key . '">' . $value . '</td>';
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
$is_individual = get_option( 'sportspress_load_individual_mode_module', 'no' ) === 'yes' ? true : false;
|
||||
$show_players = get_option( 'sportspress_event_show_players', 'yes' ) === 'yes' ? true : false;
|
||||
$show_staff = get_option( 'sportspress_event_show_staff', 'yes' ) === 'yes' ? true : false;
|
||||
$show_total = get_option( 'sportspress_event_show_total', 'yes' ) === 'yes' ? true : false;
|
||||
@@ -84,6 +85,34 @@ if ( is_array( $teams ) ):
|
||||
$formats[ $column->post_name ] = $format;
|
||||
}
|
||||
|
||||
if ( $is_individual ) {
|
||||
// Combined table
|
||||
$data = array();
|
||||
foreach ( $performance as $players ) {
|
||||
foreach ( $players as $player_id => $player ) {
|
||||
if ( $player_id == 0 ) continue;
|
||||
$data[ $player_id ] = $player;
|
||||
}
|
||||
}
|
||||
|
||||
sp_get_template( 'event-performance-table-combined.php', array(
|
||||
'scrollable' => $scrollable,
|
||||
'sortable' => $sortable,
|
||||
'show_players' => $show_players,
|
||||
'show_numbers' => $show_numbers,
|
||||
'show_total' => $show_total,
|
||||
'caption' => __( 'Scorecard', 'sportspress' ),
|
||||
'labels' => $labels,
|
||||
'formats' => $formats,
|
||||
'mode' => $mode,
|
||||
'data' => $data,
|
||||
'event' => $event,
|
||||
'link_posts' => $link_posts,
|
||||
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
|
||||
'primary' => 'primary' == $total ? $primary : null,
|
||||
) );
|
||||
} else {
|
||||
|
||||
// Prepare for offense and defense sections
|
||||
if ( -1 != $sections ) {
|
||||
|
||||
@@ -122,7 +151,7 @@ if ( is_array( $teams ) ):
|
||||
endforeach;
|
||||
}
|
||||
|
||||
foreach( $teams as $index => $team_id ):
|
||||
foreach( $teams as $index => $team_id ) {
|
||||
if ( -1 == $team_id ) continue;
|
||||
|
||||
// Get results for players in the team
|
||||
@@ -226,12 +255,14 @@ if ( is_array( $teams ) ):
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $show_staff ):
|
||||
sp_get_template( 'event-staff.php', array( 'id' => $id, 'index' => $index ) );
|
||||
endif;
|
||||
?>
|
||||
<?php
|
||||
endforeach;
|
||||
}
|
||||
|
||||
do_action( 'sportspress_event_performance' );
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user