Add option to display outcomes in event results

This commit is contained in:
Brian Miyaji
2014-04-29 17:08:53 +10:00
parent 6c603768d5
commit 71b604294d
3 changed files with 36 additions and 0 deletions

View File

@@ -12,6 +12,12 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! isset( $id ) )
$id = get_the_ID();
$defaults = array(
'show_outcomes' => get_option( 'sportspress_event_show_outcomes', 'yes' ) == 'yes' ? true : false,
);
extract( $defaults, EXTR_SKIP );
$teams = (array)get_post_meta( $id, 'sp_team', false );
$results = array_filter( sp_array_combine( $teams, (array)get_post_meta( $id, 'sp_results', true ) ), 'array_filter' );
$result_labels = sp_get_var_labels( 'sp_result' );
@@ -29,6 +35,20 @@ if ( empty( $results ) )
foreach( $results as $team_id => $result ):
if ( sp_array_value( $result, 'outcome', '-1' ) != '-1' ):
if ( $show_outcomes ):
$outcomes = array();
$result_outcome = $result['outcome'];
if ( ! is_array( $result_outcome ) ):
$result_outcome = (array) $result_outcome;
endif;
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;
unset( $result['outcome'] );
$table_rows .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
@@ -46,6 +66,10 @@ foreach( $results as $team_id => $result ):
$table_rows .= '<td class="data-' . $key . '">' . $value . '</td>';
endforeach;
if ( $show_outcomes ):
$table_rows .= '<td class="data-outcome">' . implode( ', ', $outcomes ) . '</td>';
endif;
$table_rows .= '</tr>';
$i++;
@@ -67,6 +91,9 @@ else:
foreach( $result_labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
if ( $show_outcomes ):
$output .= '<th class="data-outcome">' . SP()->text->string('Outcome') . '</th>';
endif;
$output .= '</tr>' . '</thead>' . '<tbody>';
$output .= $table_rows;
$output .= '</tbody>' . '</table>' . '</div>';