Display league tables on team pages close #44

This commit is contained in:
Brian Miyaji
2014-08-25 00:17:26 +10:00
parent 0e7d8994fe
commit e29cfbe8e5
12 changed files with 198 additions and 169 deletions

View File

@@ -12,9 +12,7 @@ $strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{
countdown: "' . esc_js( __( 'Countdown', 'sportspress' ) ) . '",
performance: "' . esc_js( __( 'Performance', 'sportspress' ) ) . '",
calendar: "' . esc_js( __( 'Calendar', 'sportspress' ) ) . '",
team: "' . esc_js( __( 'Team', 'sportspress' ) ) . '",
statistics: "' . esc_js( __( 'Statistics', 'sportspress' ) ) . '",
table_columns: "' . esc_js( __( 'Table Columns', 'sportspress' ) ) . '",
league_table: "' . esc_js( __( 'League Table', 'sportspress' ) ) . '",
player_list: "' . esc_js( __( 'Player List', 'sportspress' ) ) . '",
list: "' . esc_js( __( 'List', 'sportspress' ) ) . '",

View File

@@ -88,21 +88,6 @@
}
]
},
{
text: ed.getLang( 'sportspress.team' ),
menu: [
{
text: ed.getLang( 'sportspress.table_columns' ),
onclick: function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.team' ) + ' - ' + ed.getLang( 'sportspress.table_columns' ), 'admin-ajax.php?action=sportspress_team_columns_shortcode&width=' + W + '&height=' + H );
}
}
]
},
{
text: ed.getLang( 'sportspress.league_table' ),
onclick : function() {

View File

@@ -63,6 +63,7 @@ class SP_Admin_Meta_Boxes {
add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Details::save', 10, 2 );
add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Columns::save', 20, 2 );
add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Lists::save', 30, 2 );
add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Tables::save', 40, 2 );
// Save Table Meta Boxes
add_action( 'sportspress_process_sp_table_meta', 'SP_Meta_Box_Table_Details::save', 10, 2 );
@@ -141,6 +142,7 @@ class SP_Admin_Meta_Boxes {
if ( isset( $post ) && isset( $post->ID ) ):
add_meta_box( 'sp_columnssdiv', __( 'Table Columns', 'sportspress' ), 'SP_Meta_Box_Team_Columns::output', 'sp_team', 'normal', 'high' );
add_meta_box( 'sp_listsdiv', __( 'Player Lists', 'sportspress' ), 'SP_Meta_Box_Team_Lists::output', 'sp_team', 'normal', 'high' );
add_meta_box( 'sp_tablesdiv', __( 'League Tables', 'sportspress' ), 'SP_Meta_Box_Team_Tables::output', 'sp_team', 'normal', 'high' );
endif;
add_meta_box( 'sp_editordiv', __( 'Profile', 'sportspress' ), 'SP_Meta_Box_Team_Editor::output', 'sp_team', 'normal', 'low' );
@@ -161,7 +163,7 @@ class SP_Admin_Meta_Boxes {
add_meta_box( 'sp_editordiv', __( 'Profile', 'sportspress' ), 'SP_Meta_Box_Player_Editor::output', 'sp_player', 'normal', 'low' );
// Lists
add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_List_Shortcode::output', 'sp_list', 'side', 'default' );
add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_List_Shortcode::output', 'sp_table', 'side', 'default' );
add_meta_box( 'sp_formatdiv', __( 'Layout', 'sportspress' ), 'SP_Meta_Box_List_Format::output', 'sp_list', 'side', 'default' );
add_meta_box( 'sp_columnsdiv', __( 'Columns', 'sportspress' ), 'SP_Meta_Box_List_Columns::output', 'sp_list', 'side', 'default' );
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_List_Details::output', 'sp_list', 'side', 'default' );

View File

@@ -1,32 +0,0 @@
<?php
/**
* Team Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Team_Shortcode
*/
class SP_Meta_Box_Team_Shortcode {
/**
* Output the metabox
*/
public static function output( $post ) {
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
</p>
<p>
<strong><?php _e( 'Table Columns', 'sportspress' ); ?></strong>
</p>
<p><input type="text" value="[team_columns <?php echo $post->ID; ?>]" readonly="readonly" class="code"></p>
<?php
}
}

View File

@@ -0,0 +1,117 @@
<?php
/**
* Team League Tables
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Team_Tables
*/
class SP_Meta_Box_Team_Tables {
/**
* Output the metabox
*/
public static function output( $post ) {
global $pagenow;
if ( $pagenow != 'post-new.php' ):
$team = new SP_Team( $post );
list( $data, $checked ) = $team->tables( true );
self::table( $data, $checked );
else:
printf( __( 'No results found.', 'sportspress' ) );
endif;
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_update_post_meta_recursive( $post_id, 'sp_table', sp_array_value( $_POST, 'sp_table', array() ) );
}
/**
* Admin edit table
*/
public static function table( $data = array(), $checked = array() ) {
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-team-table-table sp-select-all-range">
<thead>
<tr>
<th class="check-column"><input class="sp-select-all" type="checkbox"></th>
<th class="column-table">
<?php _e( 'League Table', 'sportspress' ); ?>
</th>
<th class="column-players">
<?php _e( 'Teams', 'sportspress' ); ?>
</th>
<th class="column-league">
<?php _e( 'League', 'sportspress' ); ?>
</th>
<th class="column-season">
<?php _e( 'Season', 'sportspress' ); ?>
</th>
</tr>
</thead>
<tbody>
<?php
if ( is_array( $data ) ):
if ( sizeof( $data ) > 0 ):
$i = 0;
foreach ( $data as $table ):
$players = array_filter( get_post_meta( $table->ID, 'sp_player' ) );
$format = get_post_meta( $table->ID, 'sp_format', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<input type="checkbox" name="sp_table[]" id="sp_table_<?php echo $table->ID; ?>" value="<?php echo $table->ID; ?>" <?php checked( in_array( $table->ID, $checked ) ); ?>>
</td>
<td>
<a href="<?php echo get_edit_post_link( $table->ID ); ?>">
<?php echo $table->post_title; ?>
</a>
</td>
<td><?php echo sizeof( $players ); ?></td>
<td><?php echo get_the_terms ( $table->ID, 'sp_league' ) ? the_terms( $table->ID, 'sp_league' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms ( $table->ID, 'sp_season' ) ? the_terms( $table->ID, 'sp_season' ) : '&mdash;'; ?></td>
</tr>
<?php
$i++;
endforeach;
else:
?>
<tr class="sp-row alternate">
<td colspan="6">
<?php _e( 'No results found.', 'sportspress' ); ?>
</td>
</tr>
<?php
endif;
else:
?>
<tr class="sp-row alternate">
<td colspan="5">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
</div>
<?php
}
}

View File

@@ -23,7 +23,6 @@ class SP_Shortcodes {
'event_calendar' => __CLASS__ . '::event_calendar',
'event_list' => __CLASS__ . '::event_list',
'event_blocks' => __CLASS__ . '::event_blocks',
'team_columns' => __CLASS__ . '::team_columns',
'league_table' => __CLASS__ . '::league_table',
'player_details' => __CLASS__ . '::player_details',
'player_statistics' => __CLASS__ . '::player_statistics',
@@ -141,17 +140,6 @@ class SP_Shortcodes {
return self::shortcode_wrapper( array( 'SP_Shortcode_Event_Blocks', 'output' ), $atts );
}
/**
* Team columns shortcode.
*
* @access public
* @param mixed $atts
* @return string
*/
public static function team_columns( $atts ) {
return self::shortcode_wrapper( array( 'SP_Shortcode_Team_Columns', 'output' ), $atts );
}
/**
* League table shortcode.
*

View File

@@ -78,7 +78,7 @@ class SP_Team extends SP_Custom_Post {
foreach ( $div_ids as $div_id ):
$totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last5' => null, 'last10' => null );
$totals = array( 'eventsplayed' => 0, 'eventminutes' => 0, 'streak' => 0, 'last5' => null, 'last10' => null );
foreach ( $result_labels as $key => $value ):
$totals[ $key . 'for' ] = 0;
@@ -145,6 +145,9 @@ class SP_Team extends SP_Custom_Post {
foreach( $events as $event ):
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
$minutes = get_post_meta( $event->ID, 'sp_minutes', true );
if ( $minutes === '' ) $minutes = get_option( 'sportspress_event_minutes', 90 );
foreach ( $results as $team_id => $team_result ):
foreach ( $team_result as $key => $value ):
if ( $team_id == $this->ID ):
@@ -159,8 +162,9 @@ class SP_Team extends SP_Custom_Post {
// Increment events played and outcome count
if ( array_key_exists( $outcome, $totals ) ):
$totals['eventsplayed']++;
$totals[ $outcome ]++;
$totals['eventsplayed'] ++;
$totals['eventminutes'] += $minutes;
$totals[ $outcome ] ++;
endif;
if ( $outcome && $outcome != '-1' ):
@@ -307,4 +311,38 @@ class SP_Team extends SP_Custom_Post {
return $lists;
endif;
}
/**
* Returns league tables
*
* @access public
* @return array
*/
public function tables( $admin = false ) {
if ( ! $this->ID ) return null;
$args = array(
'post_type' => 'sp_table',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_key' => 'sp_team',
'meta_value' => $this->ID,
);
$tables = get_posts( $args );
$checked = (array) get_post_meta( $this->ID, 'sp_table' );
if ( $admin ):
return array( $tables, $checked );
else:
foreach ( $tables as $key => $table ):
if ( ! in_array( $table->ID, $checked ) ):
unset( $tables[ $key ] );
endif;
endforeach;
return $tables;
endif;
}
}

View File

@@ -1,24 +0,0 @@
<?php
/**
* Team Columns Shortcode
*
* @author ThemeBoy
* @category Shortcodes
* @package SportsPress/Shortcodes/Team_Columns
* @version 1.3
*/
class SP_Shortcode_Team_Columns {
/**
* Output the team columns shortcode.
*
* @param array $atts
*/
public static function output( $atts ) {
if ( ! isset( $atts['id'] ) && isset( $atts[0] ) && is_numeric( $atts[0] ) )
$atts['id'] = $atts[0];
sp_get_template( 'team-columns.php', $atts );
}
}

View File

@@ -173,17 +173,17 @@ if ( ! function_exists( 'sportspress_output_team_link' ) ) {
sp_get_template( 'team-link.php' );
}
}
if ( ! function_exists( 'sportspress_output_team_columns' ) ) {
if ( ! function_exists( 'sportspress_output_team_tables' ) ) {
/**
* Output the team columns.
* Output the team tables.
*
* @access public
* @subpackage Team/Columns
* @subpackage Team/Tables
* @return void
*/
function sportspress_output_team_columns() {
sp_get_template( 'team-columns.php' );
function sportspress_output_team_tables() {
sp_get_template( 'team-tables.php' );
}
}
if ( ! function_exists( 'sportspress_output_team_lists' ) ) {

View File

@@ -50,11 +50,11 @@ add_action( 'sportspress_single_calendar_content', 'sportspress_output_br_tag',
* Single Team Content
*
* @see sportspress_output_team_link()
* @see sportspress_output_team_columns()
* @see sportspress_output_team_tables()
* @see sportspress_output_team_lists()
*/
add_action( 'sportspress_single_team_content', 'sportspress_output_team_lists', 20 );
add_action( 'sportspress_single_team_content', 'sportspress_output_team_columns', 30 );
add_action( 'sportspress_single_team_content', 'sportspress_output_team_tables', 30 );
add_action( 'sportspress_single_team_content', 'sportspress_output_br_tag', 100 );
add_action( 'sportspress_after_single_team', 'sportspress_output_team_link', 10 );

View File

@@ -1,73 +0,0 @@
<?php
/**
* Team Columns
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 1.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! isset( $id ) )
$id = get_the_ID();
$scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false;
$leagues = get_the_terms( $id, 'sp_league' );
if ( ! $leagues )
return false;
$team = new SP_Team( $id );
$output = '';
// Loop through data for each league
foreach ( $leagues as $league ):
$data = $team->columns( $league->term_id );
if ( sizeof( $data ) <= 1 )
continue;
// The first row should be column labels
$labels = $data[0];
// Remove the first row to leave us with the actual data
unset( $data[0] );
$output .= '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
'<div class="sp-table-wrapper' . ( $scrollable ? ' sp-scrollable-table-wrapper' : '' ) . '">' .
'<table class="sp-team-columns sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
foreach( $labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
foreach( $data as $season_id => $row ):
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
foreach( $labels as $key => $value ):
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>' . '</div>';
endforeach;
?>
<div class="sp-template sp-template-team-columns">
<?php echo $output; ?>
</div>

30
templates/team-tables.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
/**
* Team League Tables
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 1.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! isset( $id ) )
$id = get_the_ID();
$team = new SP_Team( $id );
$tables = $team->tables();
foreach ( $tables as $table ):
if ( ! $table ) continue;
if ( sizeof( $tables ) > 1 ):
?>
<h4 class="sp-table-caption"><?php echo $table->post_title; ?></h4>
<?php
endif;
sp_get_template( 'league-table.php', array( 'id' => $table->ID, 'highlight' => $id ) );
endforeach;
?>
<br>