status(); if ( 'results' != $status ) { return; } if ( ! isset( $caption ) ) { $caption = esc_attr__( 'Results', 'sportspress' ); } // Get event result data $data = $event->results(); // The first row should be column labels $labels = $data[0]; // Remove the first row to leave us with the actual data unset( $data[0] ); $data = array_filter( $data ); if ( empty( $data ) ) { return false; } $scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false; $link_teams = get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false; $show_outcomes = array_key_exists( 'outcome', $labels ); // Initialize $output = ''; $table_rows = ''; $i = 0; // Event Results row order is controlled in SportsPress > Settings > Events > Event Results. $row_order = get_option( 'tony_sportspress_event_results_row_order', '' ); if ( '' === $row_order ) { // Backward compatibility with the legacy checkbox option. $legacy_away_first = get_option( 'tony_sportspress_event_results_away_first', 'no' ) === 'yes'; $row_order = $legacy_away_first ? 'away_home' : 'home_away'; } $teams = array_values( array_filter( array_map( 'absint', (array) get_post_meta( $id, 'sp_team', false ) ) ) ); if ( 'away_home' === $row_order ) { $teams = array_reverse( $teams ); } if ( ! empty( $teams ) ) { $ordered = array(); foreach ( $teams as $index => $team_id ) { if ( array_key_exists( $team_id, $data ) ) { $ordered[ $team_id ] = $data[ $team_id ]; continue; } // SportsPress can store positional rows in team order (0,1,...) depending on context. if ( array_key_exists( $index, $data ) ) { $ordered[ $team_id ] = $data[ $index ]; } } foreach ( $data as $team_id => $result ) { if ( ! array_key_exists( $team_id, $ordered ) ) { $ordered[ $team_id ] = $result; } } if ( ! empty( $ordered ) ) { $data = $ordered; } } foreach ( $data as $team_id => $result ) : if ( $show_outcomes ) : $outcomes = array(); $result_outcome = sp_array_value( $result, 'outcome' ); if ( ! is_array( $result_outcome ) ) : $outcomes = array( '—' ); else : foreach ( $result_outcome as $outcome ) : $the_outcome = get_page_by_path( $outcome, OBJECT, 'sp_outcome' ); if ( is_object( $the_outcome ) ) : $outcomes[] = $the_outcome->post_title; endif; endforeach; endif; endif; unset( $result['outcome'] ); $table_rows .= ''; $team_name = sp_team_short_name( $team_id ); if ( $link_teams && sp_post_exists( $team_id ) ) : $team_name = '' . $team_name . ''; endif; $table_rows .= '' . $team_name . ''; foreach ( $labels as $key => $label ) : if ( in_array( $key, array( 'name', 'outcome' ) ) ) { continue; } if ( array_key_exists( $key, $result ) && $result[ $key ] != '' ) : $value = $result[ $key ]; else : $value = apply_filters( 'sportspress_event_empty_result_string', '—' ); endif; $table_rows .= '' . $value . ''; endforeach; if ( $show_outcomes ) : $table_rows .= '' . implode( ', ', $outcomes ) . ''; endif; $table_rows .= ''; $i++; endforeach; if ( empty( $table_rows ) ) : return false; else : $output .= '

' . $caption . '

'; $output .= '
' . '' . ''; foreach ( $labels as $key => $label ) : $output .= ''; endforeach; $output .= '' . '' . ''; $output .= $table_rows; $output .= '' . '
' . esc_attr__( 'Team', 'sportspress' ) . '' . $label . '
' . '
'; endif; ?>