Add option to display outcomes in event results
This commit is contained in:
@@ -60,6 +60,14 @@ class SP_Settings_Events extends SP_Settings_Page {
|
||||
'checkboxgroup' => 'end',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Results', 'sportspress' ),
|
||||
'desc' => __( 'Display outcomes', 'sportspress' ),
|
||||
'id' => 'sportspress_event_show_outcomes',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Player Performance', 'sportspress' ),
|
||||
'desc' => __( 'Link players', 'sportspress' ),
|
||||
|
||||
@@ -3216,6 +3216,7 @@ function sp_get_text_options() {
|
||||
'event' => __( 'Event', 'sportspress' ),
|
||||
'league' => __( 'League', 'sportspress' ),
|
||||
'nationality' => __( 'Nationality', 'sportspress' ),
|
||||
'outcome' => __( 'Outcome', 'sportspress' ),
|
||||
'past_teams' => __( 'Past Teams', 'sportspress' ),
|
||||
'played' => __( 'Played', 'sportspress' ),
|
||||
'player' => __( 'Player', 'sportspress' ),
|
||||
|
||||
@@ -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>';
|
||||
|
||||
Reference in New Issue
Block a user