From b355a7bb4c277eebd29c29df19668977f8250260 Mon Sep 17 00:00:00 2001 From: Takumi Date: Wed, 31 Jul 2013 00:39:12 +1000 Subject: [PATCH] Add per-league statistics editor to team --- event.php | 4 +++- helpers.php | 51 ++++++++++++++++++++++++++++++++------------ player.php | 16 ++++++++++---- sportspress-admin.js | 3 +++ team.php | 18 ++++++++++++++++ 5 files changed, 73 insertions(+), 19 deletions(-) diff --git a/event.php b/event.php index 07c57b10..54b17ffb 100644 --- a/event.php +++ b/event.php @@ -76,6 +76,8 @@ function sp_event_stats_meta( $post ) { $limit = get_option( 'sp_event_team_count' ); $teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 ); $stats = (array)get_post_meta( $post->ID, 'sp_stats', true ); + + // Teams foreach ( $teams as $key => $value ): $players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key ); $data = sp_array_combine( $players, sp_array_value( $stats, $value, array() ) ); @@ -86,7 +88,7 @@ function sp_event_stats_meta( $post ) {
  • ', sizeof( $parents ) ); ?> ', sizeof( $parents ) ); ?>
  • @@ -202,7 +212,8 @@ if ( !function_exists( 'sp_post_checklist' ) ) { } if ( !function_exists( 'sp_data_table' ) ) { - function sp_data_table( $data = array(), $index = 0, $columns = array( 'Name' ), $total = true, $auto = true ) { + function sp_data_table( $data = array(), $index = 0, $columns = array( 'Name' ), $total = true, $auto = true, $rowtype = 'post' ) { + global $pagenow; if ( !is_array( $data ) ) $data = array(); ?> @@ -222,20 +233,32 @@ if ( !function_exists( 'sp_data_table' ) ) { $i = 0; foreach ( $data as $key => $values ): if ( !$key ) continue; - $is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : 0; + $is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : $pagenow == 'post-new.php'; ?> - - + + + name;; + break; + endswitch; + if ( empty( $title ) ) + $title = __( '(no title)' ); + echo $title; + ?> + - /> + /> @@ -247,7 +270,7 @@ if ( !function_exists( 'sp_data_table' ) ) { if ( $total ): $values = array_key_exists( 0, $data ) ? $data[0] : array(); if ( $auto ) - $is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : 0; + $is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : $pagenow == 'post-new.php'; else $is_auto = $i; ?> @@ -262,7 +285,7 @@ if ( !function_exists( 'sp_data_table' ) ) { else $value = 0; ?> - /> + /> diff --git a/player.php b/player.php index 469e5046..79391fcc 100644 --- a/player.php +++ b/player.php @@ -36,16 +36,24 @@ function sp_player_stats_meta( $post ) { $teams = (array)get_post_meta( $post->ID, 'sp_team', false ); $leagues = (array)get_the_terms( $post->ID, 'sp_league' ); $stats = (array)get_post_meta( $post->ID, 'sp_stats', true ); + + // Overall + $data = sp_array_combine( $teams, sp_array_value( $stats, 0, array() ) ); + ?> +

    + + term_id, array() ) ); ?> -
    -

    name; ?>

    - term_id, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ) ); ?> -
    +

    name; ?>

    + term_id, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ) ); ?> ID, 'sp_league' ); + $stats = (array)get_post_meta( $post->ID, 'sp_stats', true ); + + $keys = array( 0 ); + foreach ( $leagues as $key => $value ): + if ( is_object( $value ) && property_exists( $value, 'term_id' ) ) + $keys[] = $value->term_id; + endforeach; + + $data = sp_array_combine( $keys, sp_array_value( $stats, 0, array() ) ); + ?> + \ No newline at end of file