Add ability to edit and display player statistics

This commit is contained in:
Brian Miyaji
2014-04-25 15:57:52 +10:00
parent a64b2c3923
commit ccdbc7c978
7 changed files with 461 additions and 35 deletions

View File

@@ -67,7 +67,7 @@ class SP_Admin_Meta_Boxes {
// Save Player Meta Boxes
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Details::save', 10, 2 );
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Metrics::save', 20, 2 );
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Performance::save', 30, 2 );
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Statistics::save', 30, 2 );
// Save List Meta Boxes
add_action( 'sportspress_process_sp_list_meta', 'SP_Meta_Box_List_Format::save', 10, 2 );
@@ -130,8 +130,8 @@ class SP_Admin_Meta_Boxes {
// Players
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Player_Details::output', 'sp_player', 'side', 'default' );
add_meta_box( 'sp_metricsdiv', __( 'Player Metrics', 'sportspress' ), 'SP_Meta_Box_Player_Metrics::output', 'sp_player', 'side', 'default' );
add_meta_box( 'sp_performancediv', __( 'Player Performance', 'sportspress' ), 'SP_Meta_Box_Player_Performance::output', 'sp_player', 'normal', 'high' );
add_meta_box( 'sp_metricsdiv', __( 'Metrics', 'sportspress' ), 'SP_Meta_Box_Player_Metrics::output', 'sp_player', 'side', 'default' );
add_meta_box( 'sp_statisticsdiv', __( 'Statistics', 'sportspress' ), 'SP_Meta_Box_Player_Statistics::output', 'sp_player', 'normal', 'high' );
add_meta_box( 'sp_editordiv', __( 'Profile', 'sportspress' ), 'SP_Meta_Box_Player_Editor::output', 'sp_player', 'normal', 'high' );
// Lists

View File

@@ -0,0 +1,54 @@
<?php
/**
* Player Statistics
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Player_Statistics
*/
class SP_Meta_Box_Player_Statistics {
/**
* Output the metabox
*/
public static function output( $post ) {
$leagues = get_the_terms( $post->ID, 'sp_league' );
$league_num = sizeof( $leagues );
// Loop through statistics for each league
if ( $leagues ): foreach ( $leagues as $league ):
if ( $league_num > 1 ):
?>
<p><strong><?php echo $league->name; ?></strong></p>
<?php
endif;
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = sp_get_player_statistics_data( $post->ID, $league->term_id, true );
sp_edit_player_statistics_table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_teams' ) );
endforeach; else:
printf( __( 'Select %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) );
endif;
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_leagues', sp_array_value( $_POST, 'sp_leagues', array() ) );
if ( current_user_can( 'edit_sp_teams' ) )
update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) );
}
}

View File

@@ -49,7 +49,7 @@ class SP_Meta_Box_Team_Columns {
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_leagues_seasons', sp_array_value( $_POST, 'sp_leagues_seasons', array() ) );
update_post_meta( $post_id, 'sp_leagues', sp_array_value( $_POST, 'sp_leagues', array() ) );
if ( current_user_can( 'edit_sp_tables' ) )
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
}