Add fallback for offense and defense stats
This commit is contained in:
@@ -89,7 +89,7 @@ if ( is_array( $teams ) ):
|
||||
|
||||
// Determine order of sections
|
||||
if ( 1 == $sections ) {
|
||||
$section_order = array( __( 'Defense', 'sportspress' ), __( 'Offense', 'sportspress' ) );
|
||||
$section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) );
|
||||
} else {
|
||||
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
|
||||
}
|
||||
@@ -140,21 +140,32 @@ if ( is_array( $teams ) ):
|
||||
|
||||
$data = array();
|
||||
|
||||
// Get results for offensive players in the team
|
||||
$offense = sp_array_between( (array)get_post_meta( $id, 'sp_offense', false ), 0, $index );
|
||||
$data[0] = sp_array_combine( $offense, sp_array_value( $performance, $team_id, array() ) );
|
||||
$offense = (array)get_post_meta( $id, 'sp_offense', false );
|
||||
$defense = (array)get_post_meta( $id, 'sp_defense', false );
|
||||
|
||||
// Get results for defensive players in the team
|
||||
$defense = sp_array_between( (array)get_post_meta( $id, 'sp_defense', false ), 0, $index );
|
||||
$data[1] = sp_array_combine( $defense, sp_array_value( $performance, $team_id, array() ) );
|
||||
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 ) ) {
|
||||
if ( is_array( $player_order ) && sizeof( $player_order ) ) {
|
||||
$data[1] = sp_array_combine( $player_order, $data[1], true );
|
||||
}
|
||||
}
|
||||
@@ -167,7 +178,7 @@ if ( is_array( $teams ) ):
|
||||
'show_players' => $show_team_players,
|
||||
'show_numbers' => $show_numbers,
|
||||
'show_total' => $show_total,
|
||||
'caption' => 0 == $section_id && $team_id ? get_the_title( $team_id ) : null,
|
||||
'caption' => 0 == $s && $team_id ? get_the_title( $team_id ) : null,
|
||||
'labels' => $labels[ $section_id ],
|
||||
'formats' => $formats,
|
||||
'mode' => $mode,
|
||||
@@ -179,6 +190,8 @@ if ( is_array( $teams ) ):
|
||||
'class' => 'sp-template-event-performance-team-' . $index . '-section-' . $section_id,
|
||||
) );
|
||||
}
|
||||
|
||||
$s++;
|
||||
}
|
||||
} else {
|
||||
if ( 0 < $team_id ) {
|
||||
|
||||
Reference in New Issue
Block a user