Display staff in event performance section

This commit is contained in:
Brian Miyaji
2014-06-18 13:29:41 +10:00
parent 6333025646
commit fedbdb72e4
8 changed files with 239 additions and 112 deletions

View File

@@ -13,32 +13,35 @@ if ( ! isset( $id ) )
$id = get_the_ID();
$event = new SP_Event( $id );
$data = $event->performance();
// 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 );
$teams = (array)get_post_meta( $id, 'sp_team', false );
$staff = (array)get_post_meta( $id, 'sp_staff', false );
$status = $event->status();
$stats = (array)get_post_meta( $id, 'sp_players', true );
if ( $status == 'results' ):
$performance_labels = sp_get_var_labels( 'sp_performance' );
else:
$performance_labels = array();
endif;
$link_posts = get_option( 'sportspress_event_link_players', 'yes' ) == 'yes' ? true : false;
$sortable = get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false;
$responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false;
foreach( $teams as $key => $team_id ):
foreach( $teams as $index => $team_id ):
if ( ! $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;
if ( ! $has_players && $status != 'results' ) continue;
$totals = array();
// Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key );
$has_players = sizeof( $players ) > 1;
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
$data = sp_array_combine( $players, sp_array_value( $data, $team_id, array() ) );
?>
<h3><?php echo get_the_title( $team_id ); ?></h3>
<div class="sp-table-wrapper sp-scrollable-table-wrapper">
@@ -47,8 +50,8 @@ foreach( $teams as $key => $team_id ):
<tr>
<?php if ( $has_players ): ?>
<th class="data-number">#</th>
<th class="data-name"><?php echo __( 'Player'), 'sportspress' ; ?></th>
<?php endif; foreach( $performance_labels as $key => $label ): ?>
<th class="data-name"><?php _e( 'Player', 'sportspress' ); ?></th>
<?php endif; foreach( $labels as $key => $label ): ?>
<th class="data-<?php echo $key; ?>"><?php echo $label; ?></th>
<?php endforeach; ?>
</tr>
@@ -101,7 +104,7 @@ foreach( $teams as $key => $team_id ):
echo '<td class="data-name">' . $name . '</td>';
foreach( $performance_labels as $key => $label ):
foreach( $labels as $key => $label ):
if ( $key == 'name' )
continue;
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
@@ -135,7 +138,7 @@ foreach( $teams as $key => $team_id ):
$row = $data[0];
foreach( $performance_labels as $key => $label ):
foreach( $labels as $key => $label ):
if ( $key == 'name' ):
continue;
endif;
@@ -152,4 +155,5 @@ foreach( $teams as $key => $team_id ):
<?php endif; ?>
</table>
</div>
<?php if ( get_option( 'sportspress_event_show_staff', 'yes' ) == 'yes' ) sp_get_template( 'event-staff.php', array( 'id' => $id, 'index' => $index ) ); ?>
<?php endforeach;

View File

@@ -4,7 +4,7 @@
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 0.8
* @version 1.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -12,35 +12,39 @@ 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,
);
$event = new SP_Event( $id );
$status = $event->status();
extract( $defaults, EXTR_SKIP );
if ( 'results' != $status ) return;
$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' );
// Get event result data
$data = $event->results();
$output = '';
// The first row should be column labels
$labels = $data[0];
// Initialize and check
$table_rows = '';
// Remove the first row to leave us with the actual data
unset( $data[0] );
$i = 0;
$data = array_filter( $data );
if ( empty( $results ) )
if ( empty( $data ) )
return false;
foreach( $results as $team_id => $result ):
if ( count( array_filter( $results ) ) ):
$show_outcomes = array_key_exists( 'outcome', $labels );
if ( $show_outcomes ):
$outcomes = array();
$result_outcome = $result['outcome'];
if ( ! is_array( $result_outcome ) ):
$result_outcome = (array) $result_outcome;
endif;
// Initialize
$output = '';
$table_rows = '';
$i = 0;
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( '&mdash;' );
else:
foreach( $result_outcome as $outcome ):
$the_outcome = get_page_by_path( $outcome, OBJECT, 'sp_outcome' );
if ( is_object( $the_outcome ) ):
@@ -48,33 +52,32 @@ foreach( $results as $team_id => $result ):
endif;
endforeach;
endif;
unset( $result['outcome'] );
$table_rows .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$table_rows .= '<td class="data-name">' . get_the_title( $team_id ) . '</td>';
foreach( $result_labels as $key => $label ):
if ( $key == 'name' )
continue;
if ( array_key_exists( $key, $result ) && $result[ $key ] != '' ):
$value = $result[ $key ];
else:
$value = '&mdash;';
endif;
$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++;
endif;
unset( $result['outcome'] );
$table_rows .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$table_rows .= '<td class="data-name">' . get_the_title( $team_id ) . '</td>';
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 = '&mdash;';
endif;
$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++;
endforeach;
if ( empty( $table_rows ) ):
@@ -88,12 +91,9 @@ else:
$output .= '<div class="sp-table-wrapper sp-scrollable-table-wrapper">' .
'<table class="sp-event-results sp-data-table sp-responsive-table"><thead>' .
'<th class="data-name">' . __( 'Team', 'sportspress' ) . '</th>';
foreach( $result_labels as $key => $label ):
foreach( $labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
if ( $show_outcomes ):
$output .= '<th class="data-outcome">' . __( 'Outcome', 'sportspress' ) . '</th>';
endif;
$output .= '</tr>' . '</thead>' . '<tbody>';
$output .= $table_rows;
$output .= '</tbody>' . '</table>' . '</div>';

View File

@@ -4,15 +4,67 @@
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 0.8
* @version 1.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! isset( $id ) )
$id = get_the_ID();
$staff = (array)get_post_meta( $id, 'sp_staff', false );
$defaults = array(
'id' => get_the_ID(),
'index' => 0,
'number' => -1,
'link_posts' => get_option( 'sportspress_event_link_staff', 'yes' ) == 'yes' ? true : false,
'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false,
);
$output = '';
$staff = array_filter( sp_array_between( (array)get_post_meta( $id, 'sp_staff', false ), 0, $index ) );
echo apply_filters( 'sportspress_event_staff', $output );
if ( ! $staff ) return;
extract( $defaults, EXTR_SKIP );
?>
<div class="sp-table-wrapper sp-scrollable-table-wrapper">
<table class="sp-event-performance sp-data-table <?php if ( $responsive ) { ?> sp-responsive-table<?php } if ( $sortable ) { ?> sp-sortable-table<?php } ?>">
<thead>
<tr>
<th class="data-name"><?php _e( 'Staff', 'sportspress' ); ?></th>
<th class="data-role"><?php _e( 'Role', 'sportspress' ); ?></th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach( $staff as $staff_id ):
if ( ! $staff_id )
continue;
$name = get_the_title( $staff_id );
if ( ! $name )
continue;
echo '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
if ( $link_posts ):
$permalink = get_post_permalink( $staff_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
endif;
echo '<td class="data-name">' . $name . '</td>';
$role = get_post_meta( $staff_id, 'sp_role', true );
// Staff role
echo '<td class="data-role">' . $role . '</td>';
echo '</tr>';
$i++;
endforeach;
?>
</tbody>
</table>
</div>