Add combined table for individual mode
This commit is contained in:
@@ -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;
|
||||
$totals[ $key ] += $value;
|
||||
|
||||
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;
|
||||
@@ -83,155 +84,185 @@ if ( is_array( $teams ) ):
|
||||
}
|
||||
$formats[ $column->post_name ] = $format;
|
||||
}
|
||||
|
||||
// Prepare for offense and defense sections
|
||||
if ( -1 != $sections ) {
|
||||
|
||||
// Determine order of sections
|
||||
if ( 1 == $sections ) {
|
||||
$section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) );
|
||||
} else {
|
||||
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
|
||||
}
|
||||
|
||||
// Initialize labels
|
||||
$labels = array( array(), array() );
|
||||
|
||||
// Add positions if applicable
|
||||
if ( 'yes' == get_option( 'sportspress_event_show_position', 'yes' ) ) {
|
||||
$labels[0]['position'] = $labels[1]['position'] = __( 'Position', 'sportspress' );
|
||||
}
|
||||
|
||||
// Get labels by section
|
||||
foreach ( $columns as $column ):
|
||||
$section = get_post_meta( $column->ID, 'sp_section', true );
|
||||
if ( '' === $section ) {
|
||||
$section = -1;
|
||||
|
||||
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;
|
||||
}
|
||||
switch ( $section ):
|
||||
case 1:
|
||||
$labels[1][ $column->post_name ] = $column->post_title;
|
||||
break;
|
||||
case 0:
|
||||
$labels[0][ $column->post_name ] = $column->post_title;
|
||||
break;
|
||||
default:
|
||||
$labels[0][ $column->post_name ] = $column->post_title;
|
||||
$labels[1][ $column->post_name ] = $column->post_title;
|
||||
endswitch;
|
||||
endforeach;
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
foreach( $teams as $index => $team_id ):
|
||||
if ( -1 == $team_id ) continue;
|
||||
// Prepare for offense and defense sections
|
||||
if ( -1 != $sections ) {
|
||||
|
||||
// Determine order of sections
|
||||
if ( 1 == $sections ) {
|
||||
$section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) );
|
||||
} else {
|
||||
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
|
||||
}
|
||||
|
||||
// Initialize labels
|
||||
$labels = array( array(), array() );
|
||||
|
||||
// Add positions if applicable
|
||||
if ( 'yes' == get_option( 'sportspress_event_show_position', 'yes' ) ) {
|
||||
$labels[0]['position'] = $labels[1]['position'] = __( 'Position', 'sportspress' );
|
||||
}
|
||||
|
||||
// Get results for players in the team
|
||||
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $index );
|
||||
$has_players = sizeof( $players ) > 1;
|
||||
|
||||
$players = apply_filters( 'sportspress_event_performance_split_team_players', $players );
|
||||
|
||||
$show_team_players = $show_players && $has_players;
|
||||
|
||||
if ( ! $show_team_players && ! $show_staff && ! $show_total ) continue;
|
||||
|
||||
if ( $show_team_players || $show_total ) {
|
||||
if ( -1 != $sections ) {
|
||||
|
||||
$data = array();
|
||||
|
||||
$offense = (array)get_post_meta( $id, 'sp_offense', false );
|
||||
$defense = (array)get_post_meta( $id, 'sp_defense', false );
|
||||
|
||||
if ( sizeof( $offense ) || sizeof( $defense ) ) {
|
||||
// Get results for offensive players in the team
|
||||
$offense = sp_array_between( $offense, 0, $index );
|
||||
$data[0] = sp_array_combine( $offense, sp_array_value( $performance, $team_id, array() ) );
|
||||
|
||||
// Get results for defensive players in the team
|
||||
$defense = sp_array_between( $defense, 0, $index );
|
||||
$data[1] = sp_array_combine( $defense, sp_array_value( $performance, $team_id, array() ) );
|
||||
} else {
|
||||
// Get results for all players in the team
|
||||
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $index );
|
||||
$data[0] = $data[1] = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
||||
// Get labels by section
|
||||
foreach ( $columns as $column ):
|
||||
$section = get_post_meta( $column->ID, 'sp_section', true );
|
||||
if ( '' === $section ) {
|
||||
$section = -1;
|
||||
}
|
||||
|
||||
$s = 0;
|
||||
switch ( $section ):
|
||||
case 1:
|
||||
$labels[1][ $column->post_name ] = $column->post_title;
|
||||
break;
|
||||
case 0:
|
||||
$labels[0][ $column->post_name ] = $column->post_title;
|
||||
break;
|
||||
default:
|
||||
$labels[0][ $column->post_name ] = $column->post_title;
|
||||
$labels[1][ $column->post_name ] = $column->post_title;
|
||||
endswitch;
|
||||
endforeach;
|
||||
}
|
||||
|
||||
foreach( $teams as $index => $team_id ) {
|
||||
if ( -1 == $team_id ) continue;
|
||||
|
||||
// Get results for players in the team
|
||||
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $index );
|
||||
$has_players = sizeof( $players ) > 1;
|
||||
|
||||
$players = apply_filters( 'sportspress_event_performance_split_team_players', $players );
|
||||
|
||||
$show_team_players = $show_players && $has_players;
|
||||
|
||||
if ( ! $show_team_players && ! $show_staff && ! $show_total ) continue;
|
||||
|
||||
if ( $show_team_players || $show_total ) {
|
||||
if ( -1 != $sections ) {
|
||||
|
||||
foreach ( $section_order as $section_id => $section_label ) {
|
||||
if ( sizeof( $data[ $section_id ] ) ) {
|
||||
if ( 1 == $section_id ) {
|
||||
$order = (array)get_post_meta( $id, 'sp_order', true );
|
||||
if ( is_array( $order ) && sizeof( $order ) ) {
|
||||
$player_order = sp_array_value( $order, $team_id, array() );
|
||||
if ( is_array( $player_order ) && sizeof( $player_order ) ) {
|
||||
$data[1] = sp_array_combine( $player_order, $data[1], true );
|
||||
$data = array();
|
||||
|
||||
$offense = (array)get_post_meta( $id, 'sp_offense', false );
|
||||
$defense = (array)get_post_meta( $id, 'sp_defense', false );
|
||||
|
||||
if ( sizeof( $offense ) || sizeof( $defense ) ) {
|
||||
// Get results for offensive players in the team
|
||||
$offense = sp_array_between( $offense, 0, $index );
|
||||
$data[0] = sp_array_combine( $offense, sp_array_value( $performance, $team_id, array() ) );
|
||||
|
||||
// Get results for defensive players in the team
|
||||
$defense = sp_array_between( $defense, 0, $index );
|
||||
$data[1] = sp_array_combine( $defense, sp_array_value( $performance, $team_id, array() ) );
|
||||
} else {
|
||||
// Get results for all players in the team
|
||||
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $index );
|
||||
$data[0] = $data[1] = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
||||
}
|
||||
|
||||
$s = 0;
|
||||
|
||||
foreach ( $section_order as $section_id => $section_label ) {
|
||||
if ( sizeof( $data[ $section_id ] ) ) {
|
||||
if ( 1 == $section_id ) {
|
||||
$order = (array)get_post_meta( $id, 'sp_order', true );
|
||||
if ( is_array( $order ) && sizeof( $order ) ) {
|
||||
$player_order = sp_array_value( $order, $team_id, array() );
|
||||
if ( is_array( $player_order ) && sizeof( $player_order ) ) {
|
||||
$data[1] = sp_array_combine( $player_order, $data[1], true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sp_get_template( 'event-performance-table.php', array(
|
||||
'section' => $section_label,
|
||||
'scrollable' => $scrollable,
|
||||
'sortable' => $sortable,
|
||||
'show_players' => $show_team_players,
|
||||
'show_numbers' => $show_numbers,
|
||||
'show_total' => $show_total,
|
||||
'caption' => 0 == $s && $team_id ? get_the_title( $team_id ) : null,
|
||||
'labels' => $labels[ $section_id ],
|
||||
'formats' => $formats,
|
||||
'mode' => $mode,
|
||||
'data' => $data[ $section_id ],
|
||||
'event' => $event,
|
||||
'link_posts' => $link_posts,
|
||||
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
|
||||
'primary' => 'primary' == $total ? $primary : null,
|
||||
'class' => 'sp-template-event-performance-team-' . $index . '-section-' . $section_id,
|
||||
) );
|
||||
}
|
||||
|
||||
sp_get_template( 'event-performance-table.php', array(
|
||||
'section' => $section_label,
|
||||
'scrollable' => $scrollable,
|
||||
'sortable' => $sortable,
|
||||
'show_players' => $show_team_players,
|
||||
'show_numbers' => $show_numbers,
|
||||
'show_total' => $show_total,
|
||||
'caption' => 0 == $s && $team_id ? get_the_title( $team_id ) : null,
|
||||
'labels' => $labels[ $section_id ],
|
||||
'formats' => $formats,
|
||||
'mode' => $mode,
|
||||
'data' => $data[ $section_id ],
|
||||
'event' => $event,
|
||||
'link_posts' => $link_posts,
|
||||
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
|
||||
'primary' => 'primary' == $total ? $primary : null,
|
||||
'class' => 'sp-template-event-performance-team-' . $index . '-section-' . $section_id,
|
||||
) );
|
||||
}
|
||||
|
||||
$s++;
|
||||
}
|
||||
} else {
|
||||
if ( 0 < $team_id ) {
|
||||
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
||||
} elseif ( 0 == $team_id ) {
|
||||
$data = array();
|
||||
foreach ( $players as $player_id ) {
|
||||
if ( isset( $performance[ $player_id ][ $player_id ] ) ) {
|
||||
$data[ $player_id ] = $performance[ $player_id ][ $player_id ];
|
||||
}
|
||||
$s++;
|
||||
}
|
||||
} else {
|
||||
$data = sp_array_value( array_values( $performance ), $index );
|
||||
}
|
||||
|
||||
sp_get_template( 'event-performance-table.php', array(
|
||||
'scrollable' => $scrollable,
|
||||
'sortable' => $sortable,
|
||||
'show_players' => $show_team_players,
|
||||
'show_numbers' => $show_numbers,
|
||||
'show_total' => $show_total,
|
||||
'caption' => $team_id ? get_the_title( $team_id ) : null,
|
||||
'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,
|
||||
if ( 0 < $team_id ) {
|
||||
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
||||
} elseif ( 0 == $team_id ) {
|
||||
$data = array();
|
||||
foreach ( $players as $player_id ) {
|
||||
if ( isset( $performance[ $player_id ][ $player_id ] ) ) {
|
||||
$data[ $player_id ] = $performance[ $player_id ][ $player_id ];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$data = sp_array_value( array_values( $performance ), $index );
|
||||
}
|
||||
|
||||
sp_get_template( 'event-performance-table.php', array(
|
||||
'scrollable' => $scrollable,
|
||||
'sortable' => $sortable,
|
||||
'show_players' => $show_team_players,
|
||||
'show_numbers' => $show_numbers,
|
||||
'show_total' => $show_total,
|
||||
'caption' => $team_id ? get_the_title( $team_id ) : null,
|
||||
'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,
|
||||
|
||||
) );
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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