diff --git a/actions.php b/actions.php index 44004a7b..a7a16dff 100644 --- a/actions.php +++ b/actions.php @@ -23,6 +23,9 @@ function sp_manage_posts_custom_column( $column, $post_id ) { $result = get_post_meta( $post_id, 'sp_result', false ); echo get_post_meta ( $post_id, 'sp_team' ) ? sp_the_posts( $post_id, 'sp_team', '', '
', $result, ( empty( $result ) ? ' — ' : ' ' ) ) : '—'; break; + case 'sp_player': + echo sp_the_posts( $post_id, 'sp_player' ); + break; case 'sp_event': echo get_post_meta ( $post_id, 'sp_event' ) ? sizeof( get_post_meta ( $post_id, 'sp_event' ) ) : '—'; break; @@ -124,6 +127,12 @@ function sp_save_post( $post_id ) { wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' ); sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); break; + case ( 'sp_list' ): + update_post_meta( $post_id, 'sp_stats', sp_array_value( $_POST, 'sp_stats', array() ) ); + update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); + wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' ); + sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) ); + break; endswitch; /* diff --git a/event.php b/event.php index 6effb381..51bf7c2e 100644 --- a/event.php +++ b/event.php @@ -2,7 +2,8 @@ function sp_event_cpt_init() { $name = __( 'Events', 'sportspress' ); $singular_name = __( 'Event', 'sportspress' ); - $labels = sp_cpt_labels( $name, $singular_name ); + $lowercase_name = __( 'events', 'sportspress' ); + $labels = sp_cpt_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, diff --git a/helpers.php b/helpers.php index 50436bd0..67a2263a 100644 --- a/helpers.php +++ b/helpers.php @@ -65,7 +65,8 @@ if ( !function_exists( 'sp_num_to_letter' ) ) { } if ( !function_exists( 'sp_cpt_labels' ) ) { - function sp_cpt_labels( $name, $singular_name ) { + function sp_cpt_labels( $name, $singular_name, $lowercase_name = null ) { + if ( !$lowercase_name ) $lowercase_name = $name; $labels = array( 'name' => $name, 'singular_name' => $singular_name, @@ -75,8 +76,8 @@ if ( !function_exists( 'sp_cpt_labels' ) ) { 'new_item' => sprintf( __( 'New %s', 'sportspress' ), $singular_name ), 'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ), 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ), - 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $name ), - 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $name ), + 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ), + 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $lowercase_name ), 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':' ); return $labels; @@ -84,7 +85,8 @@ if ( !function_exists( 'sp_cpt_labels' ) ) { } if ( !function_exists( 'sp_tax_labels' ) ) { - function sp_tax_labels( $name, $singular_name ) { + function sp_tax_labels( $name, $singular_name, $lowercase_name = null ) { + if ( !$lowercase_name ) $lowercase_name = $name; $labels = array( 'name' => $name, 'singular_name' => $singular_name, @@ -97,7 +99,7 @@ if ( !function_exists( 'sp_tax_labels' ) ) { 'parent_item' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ), 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':', 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ), - 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $name ) + 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ) ); return $labels; } @@ -125,7 +127,7 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) { 'show_option_none' => false, 'taxonomy' => null, 'name' => null, - 'selected' => null, + 'selected' => null ); $args = array_merge( $defaults, $args ); $terms = get_terms( $args['taxonomy'] ); @@ -354,7 +356,7 @@ if ( !function_exists( 'sp_get_stats_row' ) ) { else: $output = $dynamic; - + endif; return $output; diff --git a/league.php b/league.php index 1cb203ff..4f3f6881 100644 --- a/league.php +++ b/league.php @@ -2,8 +2,9 @@ function sp_league_tax_init() { $name = __( 'Leagues', 'sportspress' ); $singular_name = __( 'League', 'sportspress' ); - $object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_list' ); - $labels = sp_tax_labels( $name, $singular_name ); + $lowercase_name = __( 'leagues', 'sportspress' ); + $object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff' ); + $labels = sp_tax_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, diff --git a/list.php b/list.php index 3612f619..df14e5c5 100644 --- a/list.php +++ b/list.php @@ -2,13 +2,15 @@ function sp_list_cpt_init() { $name = __( 'Player Lists', 'sportspress' ); $singular_name = __( 'Player List', 'sportspress' ); - $labels = sp_cpt_labels( $name, $singular_name ); + $lowercase_name = __( 'player lists', 'sportspress' ); + $labels = sp_cpt_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, 'public' => true, 'hierarchical' => false, - 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ), + 'supports' => array( 'title', 'author', 'thumbnail', 'page-attributes' ), + 'register_meta_box_cb' => 'sp_list_meta_init', 'rewrite' => array( 'slug' => 'list' ) ); register_post_type( 'sp_list', $args ); @@ -19,10 +21,85 @@ function sp_list_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Title' ), + 'sp_player' => __( 'Players', 'sportspress' ), 'sp_team' => __( 'Teams', 'sportspress' ), 'sp_league' => __( 'Leagues', 'sportspress' ) ); return $columns; } add_filter( 'manage_edit-sp_list_columns', 'sp_list_edit_columns' ); + +function sp_list_meta_init() { + add_meta_box( 'sp_playerdiv', __( 'Players', 'sportspress' ), 'sp_list_player_meta', 'sp_list', 'side', 'high' ); + add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sp_list_stats_meta', 'sp_list', 'normal', 'high' ); +} + +function sp_list_player_meta( $post ) { + $league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 ); + $team_id = get_post_meta( $post->ID, 'sp_team', true ); + ?> +
+

+ sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ), + 'taxonomy' => 'sp_league', + 'name' => 'sp_league', + 'selected' => $league_id + ); + sp_dropdown_taxonomies( $args ); + ?> +

+

+ sprintf( __( 'All %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ), + 'option_none_value' => '0', + 'post_type' => 'sp_team', + 'name' => 'sp_team', + 'selected' => $team_id + ); + wp_dropdown_pages( $args ); + ?> +

+ ID, 'sp_player', 'block', 'sp_team' ); + sp_post_adder( 'sp_player' ); + ?> +
+ ID, 'sp_player', false ); + $stats = (array)get_post_meta( $post->ID, 'sp_stats', true ); + $league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 ); + $team_id = get_post_meta( $post->ID, 'sp_team', true ); + $data = sp_array_combine( $players, sp_array_value( $stats, $league_id, array() ) ); + + // Generate array of placeholder values for each player + $placeholders = array(); + foreach ( $players as $player ): + $args = array( + 'post_type' => 'sp_event', + 'meta_query' => array( + array( + 'key' => 'sp_player', + 'value' => $player + ) + ), + 'tax_query' => array( + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_id + ) + ) + ); + $placeholders[ $player ] = sp_get_stats_row( 'sp_player', $args, true ); + endforeach; + + sp_stats_table( $data, $placeholders, $league_id, array( 'Player', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), false ); +} ?> \ No newline at end of file diff --git a/player.php b/player.php index d57ba0e1..12bb2f5f 100644 --- a/player.php +++ b/player.php @@ -2,7 +2,8 @@ function sp_player_cpt_init() { $name = __( 'Players', 'sportspress' ); $singular_name = __( 'Player', 'sportspress' ); - $labels = sp_cpt_labels( $name, $singular_name ); + $lowercase_name = __( 'players', 'sportspress' ); + $labels = sp_cpt_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, diff --git a/position.php b/position.php index c556cdcb..9f85b30b 100644 --- a/position.php +++ b/position.php @@ -2,8 +2,9 @@ function sp_position_tax_init() { $name = __( 'Positions', 'sportspress' ); $singular_name = __( 'Position', 'sportspress' ); + $lowercase_name = __( 'position', 'sportspress' ); $object_type = array( 'sp_player', 'sp_staff' ); - $labels = sp_tax_labels( $name, $singular_name ); + $labels = sp_tax_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, diff --git a/sponsor.php b/sponsor.php index a766d1ed..9dea5ca7 100644 --- a/sponsor.php +++ b/sponsor.php @@ -2,8 +2,9 @@ function sp_sponsor_tax_init() { $name = __( 'Sponsors', 'sportspress' ); $singular_name = __( 'Sponsor', 'sportspress' ); + $lowercase_name = __( 'sponsors', 'sportspress' ); $object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_tournament', 'sp_venue' ); - $labels = sp_tax_labels( $name, $singular_name ); + $labels = sp_tax_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, diff --git a/sportspress-admin.js b/sportspress-admin.js index 7efbaacc..b5b076ec 100644 --- a/sportspress-admin.js +++ b/sportspress-admin.js @@ -9,9 +9,16 @@ jQuery(document).ready(function($){ // Tab filter $('.sp-tab-panel').siblings('.sp-tab-select').find('select').change(function() { var val = $(this).val(); + var filter = '.sp-filter-'+val; + var $filters = $(this).closest('.sp-tab-select').siblings('.sp-tab-select'); + if($filters.length) { + $filters.each(function() { + filter += '.sp-filter-'+$(this).find('select').val(); + }); + } $(this).closest('.sp-tab-select').siblings('.sp-tab-panel').find('.sp-post').hide(0, function() { $(this).find('input').prop('disabled', true); - $(this).filter('.sp-filter-'+val).show(0, function() { + $(this).filter(filter).show(0, function() { $(this).find('input').prop('disabled', false); }); }); diff --git a/staff.php b/staff.php index 689b26d2..54a04d8c 100644 --- a/staff.php +++ b/staff.php @@ -2,7 +2,8 @@ function sp_staff_cpt_init() { $name = __( 'Staff', 'sportspress' ); $singular_name = __( 'Staff', 'sportspress' ); - $labels = sp_cpt_labels( $name, $singular_name ); + $lowercase_name = __( 'staff', 'sportspress' ); + $labels = sp_cpt_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, diff --git a/table.php b/table.php index dc42b26c..6d8b08da 100644 --- a/table.php +++ b/table.php @@ -2,7 +2,8 @@ function sp_table_cpt_init() { $name = __( 'League Tables', 'sportspress' ); $singular_name = __( 'League Table', 'sportspress' ); - $labels = sp_cpt_labels( $name, $singular_name ); + $lowercase_name = __( 'league tables', 'sportspress' ); + $labels = sp_cpt_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, @@ -28,8 +29,6 @@ function sp_table_edit_columns() { add_filter( 'manage_edit-sp_table_columns', 'sp_table_edit_columns' ); function sp_table_meta_init() { - remove_meta_box( 'submitdiv', 'sp_table', 'side' ); - add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_table', 'side', 'high' ); add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_table_team_meta', 'sp_table', 'side', 'high' ); add_meta_box( 'sp_statsdiv', __( 'League Table', 'sportspress' ), 'sp_table_stats_meta', 'sp_table', 'normal', 'high' ); } diff --git a/team.php b/team.php index 51df8cc0..b465abad 100644 --- a/team.php +++ b/team.php @@ -2,7 +2,8 @@ function sp_team_cpt_init() { $name = __( 'Teams', 'sportspress' ); $singular_name = __( 'Team', 'sportspress' ); - $labels = sp_cpt_labels( $name, $singular_name ); + $lowercase_name = __( 'teams', 'sportspress' ); + $labels = sp_cpt_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, diff --git a/tournament.php b/tournament.php index 0acf23d3..fd85904d 100644 --- a/tournament.php +++ b/tournament.php @@ -2,7 +2,8 @@ function sp_tournament_cpt_init() { $name = __( 'Tournaments', 'sportspress' ); $singular_name = __( 'Tournament', 'sportspress' ); - $labels = sp_cpt_labels( $name, $singular_name ); + $lowercase_name = __( 'tournaments', 'sportspress' ); + $labels = sp_cpt_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, diff --git a/venue.php b/venue.php index b899b376..13e971c1 100644 --- a/venue.php +++ b/venue.php @@ -2,7 +2,8 @@ function sp_venue_cpt_init() { $name = __( 'Venues', 'sportspress' ); $singular_name = __( 'Venue', 'sportspress' ); - $labels = sp_cpt_labels( $name, $singular_name ); + $lowercase_name = __( 'venues', 'sportspress' ); + $labels = sp_cpt_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels,