From 5d5368d1bff50ac7366c2c47031eba8eb14cca9f Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 25 Jan 2015 16:45:21 +1100 Subject: [PATCH] Apply players (individual sport) mode throughout --- includes/admin/class-sp-admin-importers.php | 6 +- includes/admin/class-sp-admin-sample-data.php | 482 +++++++++--------- includes/admin/class-sp-admin-settings.php | 5 +- includes/admin/class-sp-admin-welcome.php | 8 +- .../post-types/class-sp-admin-meta-boxes.php | 17 +- .../class-sp-meta-box-calendar-details.php | 36 +- .../class-sp-meta-box-event-teams.php | 4 +- .../class-sp-meta-box-list-data.php | 42 +- .../class-sp-meta-box-list-details.php | 36 +- .../class-sp-meta-box-player-details.php | 66 +-- .../class-sp-meta-box-player-statistics.php | 61 ++- .../class-sp-meta-box-staff-details.php | 65 +-- .../settings/class-sp-settings-general.php | 20 +- .../settings/class-sp-settings-modules.php | 4 +- includes/admin/sp-admin-functions.php | 2 + includes/admin/views/html-admin-config.php | 258 +++++----- includes/class-sp-player-list.php | 4 +- includes/class-sp-post-types.php | 90 ++-- templates/event-performance.php | 9 +- 19 files changed, 656 insertions(+), 559 deletions(-) diff --git a/includes/admin/class-sp-admin-importers.php b/includes/admin/class-sp-admin-importers.php index 64cd1608..e6aced70 100644 --- a/includes/admin/class-sp-admin-importers.php +++ b/includes/admin/class-sp-admin-importers.php @@ -28,8 +28,10 @@ class SP_Admin_Importers { * Add menu items */ public function register_importers() { - register_importer( 'sp_event_csv', __( 'SportsPress Events (CSV)', 'sportspress' ), __( 'Import events from a csv file.', 'sportspress'), array( $this, 'events_importer' ) ); - register_importer( 'sp_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import teams from a csv file.', 'sportspress'), array( $this, 'teams_importer' ) ); + if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { + register_importer( 'sp_event_csv', __( 'SportsPress Events (CSV)', 'sportspress' ), __( 'Import events from a csv file.', 'sportspress'), array( $this, 'events_importer' ) ); + register_importer( 'sp_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import teams from a csv file.', 'sportspress'), array( $this, 'teams_importer' ) ); + } register_importer( 'sp_player_csv', __( 'SportsPress Players (CSV)', 'sportspress' ), __( 'Import players from a csv file.', 'sportspress'), array( $this, 'players_importer' ) ); register_importer( 'sp_staff_csv', __( 'SportsPress Staff (CSV)', 'sportspress' ), __( 'Import staff from a csv file.', 'sportspress'), array( $this, 'staff_importer' ) ); } diff --git a/includes/admin/class-sp-admin-sample-data.php b/includes/admin/class-sp-admin-sample-data.php index 5dfac1ed..d7db3ff7 100644 --- a/includes/admin/class-sp-admin-sample-data.php +++ b/includes/admin/class-sp-admin-sample-data.php @@ -131,33 +131,35 @@ class SP_Admin_Sample_Data { /* * Insert teams */ - foreach ( $teams as $index => $team ) { - $post['post_title'] = $team['name']; - $post['post_type'] = 'sp_team'; - $post['post_status'] = 'publish'; - $post['post_content'] = sprintf( $sample_content, __( 'Team', 'sportspress' ), __( 'Teams', 'sportspress' ), admin_url() ); + if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { + foreach ( $teams as $index => $team ) { + $post['post_title'] = $team['name']; + $post['post_type'] = 'sp_team'; + $post['post_status'] = 'publish'; + $post['post_content'] = sprintf( $sample_content, __( 'Team', 'sportspress' ), __( 'Teams', 'sportspress' ), admin_url() ); - // Terms - $post['tax_input'] = array(); - $taxonomies = array( 'sp_league', 'sp_season' ); - foreach ( $taxonomies as $taxonomy ) { - $post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); - }; + // Terms + $post['tax_input'] = array(); + $taxonomies = array( 'sp_league', 'sp_season' ); + foreach ( $taxonomies as $taxonomy ) { + $post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); + }; - $post['tax_input']['sp_venue'] = get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $index ) ); + $post['tax_input']['sp_venue'] = get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $index ) ); - // Insert post - $id = wp_insert_post( $post ); + // Insert post + $id = wp_insert_post( $post ); - // Add to inserted ids array - $inserted_ids['sp_team'][] = $id; + // Add to inserted ids array + $inserted_ids['sp_team'][] = $id; - // Flag as sample - update_post_meta( $id, '_sp_sample', 1 ); + // Flag as sample + update_post_meta( $id, '_sp_sample', 1 ); - // Update meta - update_post_meta( $id, 'sp_abbreviation', $team['abbreviation'] ); - update_post_meta( $id, 'sp_url', $team['url'] ); + // Update meta + update_post_meta( $id, 'sp_abbreviation', $team['abbreviation'] ); + update_post_meta( $id, 'sp_url', $team['url'] ); + } } // Define players @@ -345,31 +347,175 @@ class SP_Admin_Sample_Data { /* * Insert events */ - for ( $index = 0; $index < 6; $index ++ ) { - // Determine team index and post status - $i = $index % 3; - if ( $index < 3 ) { - $post_status = 'publish'; - $post_year = $current_year - 1; - $event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); - } else { - $post_status = 'future'; - $post_year = $current_year + 1; - $event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'DESC', 'number' => 1 ) ); + if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { + for ( $index = 0; $index < 6; $index ++ ) { + // Determine team index and post status + $i = $index % 3; + if ( $index < 3 ) { + $post_status = 'publish'; + $post_year = $current_year - 1; + $event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); + } else { + $post_status = 'future'; + $post_year = $current_year + 1; + $event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'DESC', 'number' => 1 ) ); + } + // The away team should be the next inserted team, or the first if this is the last event + if ( $i == 2 ) $away_index = 0; + else $away_index = $i + 1; + $post = array( + 'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'], + 'post_type' => 'sp_event', + 'post_status' => $post_status, + 'post_content' => sprintf( $sample_content, __( 'Event', 'sportspress' ), __( 'Events', 'sportspress' ), admin_url() ), + 'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00', + 'tax_input' => array( + 'sp_league' => get_terms( 'sp_league', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ), + 'sp_season' => $event_season, + 'sp_venue' => get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $i ) ), + ), + ); + + // Insert post + $id = wp_insert_post( $post ); + + // Add to inserted ids array + $inserted_ids['sp_event'][] = $id; + + // Flag as sample + update_post_meta( $id, '_sp_sample', 1 ); + + // Calculate home and away team ids + $home_team_index = ( $i ) % 3; + $away_team_index = ( $i + 1 ) % 3; + $home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 ); + $away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 ); + $event_teams = array( + $home_team_id, + $away_team_id, + ); + + // Initialize meta + $event_players = array( 0 ); + $performance = $results = array(); + + if ( $home_team_id ) { + // Add home team player performance + $performance[ $home_team_id ] = array(); + for ( $j = 0; $j < 4; $j ++ ) { + $player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j ); + $event_players[] = $player_id; + $player_performance = array(); + foreach ( $performance_posts as $performance_post ) { + $player_performance[ $performance_post->post_name ] = rand( 0, 1 ); + } + $performance[ $home_team_id ][ $player_id ] = $player_performance; + } + + // Add home team results + $results[ $home_team_id ] = array(); + foreach ( $result_posts as $result_post_index => $result_post ) { + $results[ $home_team_id ][ $result_post->post_name ] = 1 + $result_post_index; + } + $outcome = reset( $outcome_posts ); + if ( is_object( $outcome ) ) $results[ $home_team_id ]['outcome'] = array( $outcome->post_name ); + } + + // Separate teams with zero + $event_players[] = 0; + + if ( $away_team_id ) { + $performance[ $away_team_id ] = array(); + for ( $j = 0; $j < 4; $j ++ ) { + $player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j ); + $event_players[] = $player_id; + $player_performance = array(); + foreach ( $performance_posts as $performance_post ) { + $player_performance[ $performance_post->post_name ] = rand( 0, 1 ); + } + $performance[ $away_team_id ][ $player_id ] = $player_performance; + } + + // Add away team results + $results[ $away_team_id ] = array(); + foreach ( $result_posts as $result_post ) { + $results[ $away_team_id ][ $result_post->post_name ] = '0'; + } + $outcome = next( $outcome_posts ); + if ( is_object( $outcome ) ) $results[ $away_team_id ]['outcome'] = array( $outcome->post_name ); + } + + if ( 'publish' === $post_status ) { + // Swap results for last event only + if ( $i == 2 ) { + $k = array_keys( $results ); + $v = array_values( $results ); + $rv = array_reverse( $v ); + $results = array_combine( $k, $rv ); + } + + // Update future post meta + update_post_meta( $id, 'sp_players', $performance ); + update_post_meta( $id, 'sp_results', $results ); + } + + // Update general meta + sp_update_post_meta_recursive( $id, 'sp_team', $event_teams ); + sp_update_post_meta_recursive( $id, 'sp_player', $event_players ); + update_post_meta( $id, 'sp_columns', $columns ); + update_post_meta( $id, 'sp_format', 'league' ); + update_post_meta( $id, 'sp_video', $event_videos[ $i ] ); } - // The away team should be the next inserted team, or the first if this is the last event - if ( $i == 2 ) $away_index = 0; - else $away_index = $i + 1; + } + + /* + * Insert calendar + */ + if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { $post = array( - 'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'], - 'post_type' => 'sp_event', - 'post_status' => $post_status, - 'post_content' => sprintf( $sample_content, __( 'Event', 'sportspress' ), __( 'Events', 'sportspress' ), admin_url() ), - 'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00', + 'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ), + 'post_type' => 'sp_calendar', + 'post_status' => 'publish', + 'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), admin_url() ) + ); + + // Insert post + $id = wp_insert_post( $post ); + + // Add to inserted ids array + $inserted_ids['sp_calendar'][] = $id; + + // Flag as sample + update_post_meta( $id, '_sp_sample', 1 ); + + // Define columns + $columns = array( 'event', 'time', 'article' ); + + // Update meta + update_post_meta( $id, 'sp_format', 'list' ); + update_post_meta( $id, 'sp_status', 'any' ); + update_post_meta( $id, 'sp_date', 0 ); + update_post_meta( $id, 'sp_team', 0 ); + update_post_meta( $id, 'sp_order', 'ASC' ); + update_post_meta( $id, 'sp_columns', $columns ); + } + + /* + * Insert league table + */ + if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { + $leagues = get_terms( 'sp_league', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); + $league = reset( $leagues ); + $seasons = get_terms( 'sp_season', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); + $season = reset( $seasons ); + $post = array( + 'post_title' => $league->name . ' ' . $season->name, + 'post_type' => 'sp_table', + 'post_status' => 'publish', + 'post_content' => sprintf( $sample_content, __( 'League Table', 'sportspress' ), __( 'League Tables', 'sportspress' ), admin_url() ), 'tax_input' => array( - 'sp_league' => get_terms( 'sp_league', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ), - 'sp_season' => $event_season, - 'sp_venue' => get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $i ) ), + 'sp_league' => $league->term_id, + 'sp_season' => $season->term_id, ), ); @@ -377,196 +523,16 @@ class SP_Admin_Sample_Data { $id = wp_insert_post( $post ); // Add to inserted ids array - $inserted_ids['sp_event'][] = $id; + $inserted_ids['sp_table'][] = $id; // Flag as sample update_post_meta( $id, '_sp_sample', 1 ); - // Calculate home and away team ids - $home_team_index = ( $i ) % 3; - $away_team_index = ( $i + 1 ) % 3; - $home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 ); - $away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 ); - $event_teams = array( - $home_team_id, - $away_team_id, - ); - - // Initialize meta - $event_players = array( 0 ); - $performance = $results = array(); - - if ( $home_team_id ) { - // Add home team player performance - $performance[ $home_team_id ] = array(); - for ( $j = 0; $j < 4; $j ++ ) { - $player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j ); - $event_players[] = $player_id; - $player_performance = array(); - foreach ( $performance_posts as $performance_post ) { - $player_performance[ $performance_post->post_name ] = rand( 0, 1 ); - } - $performance[ $home_team_id ][ $player_id ] = $player_performance; - } - - // Add home team results - $results[ $home_team_id ] = array(); - foreach ( $result_posts as $result_post_index => $result_post ) { - $results[ $home_team_id ][ $result_post->post_name ] = 1 + $result_post_index; - } - $outcome = reset( $outcome_posts ); - if ( is_object( $outcome ) ) $results[ $home_team_id ]['outcome'] = array( $outcome->post_name ); - } - - // Separate teams with zero - $event_players[] = 0; - - if ( $away_team_id ) { - $performance[ $away_team_id ] = array(); - for ( $j = 0; $j < 4; $j ++ ) { - $player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j ); - $event_players[] = $player_id; - $player_performance = array(); - foreach ( $performance_posts as $performance_post ) { - $player_performance[ $performance_post->post_name ] = rand( 0, 1 ); - } - $performance[ $away_team_id ][ $player_id ] = $player_performance; - } - - // Add away team results - $results[ $away_team_id ] = array(); - foreach ( $result_posts as $result_post ) { - $results[ $away_team_id ][ $result_post->post_name ] = '0'; - } - $outcome = next( $outcome_posts ); - if ( is_object( $outcome ) ) $results[ $away_team_id ]['outcome'] = array( $outcome->post_name ); - } - - if ( 'publish' === $post_status ) { - // Swap results for last event only - if ( $i == 2 ) { - $k = array_keys( $results ); - $v = array_values( $results ); - $rv = array_reverse( $v ); - $results = array_combine( $k, $rv ); - } - - // Update future post meta - update_post_meta( $id, 'sp_players', $performance ); - update_post_meta( $id, 'sp_results', $results ); - } - - // Update general meta - sp_update_post_meta_recursive( $id, 'sp_team', $event_teams ); - sp_update_post_meta_recursive( $id, 'sp_player', $event_players ); - update_post_meta( $id, 'sp_columns', $columns ); - update_post_meta( $id, 'sp_format', 'league' ); - update_post_meta( $id, 'sp_video', $event_videos[ $i ] ); - } - - /* - * Insert calendar - */ - $post = array( - 'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ), - 'post_type' => 'sp_calendar', - 'post_status' => 'publish', - 'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), admin_url() ) - ); - - // Insert post - $id = wp_insert_post( $post ); - - // Add to inserted ids array - $inserted_ids['sp_calendar'][] = $id; - - // Flag as sample - update_post_meta( $id, '_sp_sample', 1 ); - - // Define columns - $columns = array( 'event', 'time', 'article' ); - - // Update meta - update_post_meta( $id, 'sp_format', 'list' ); - update_post_meta( $id, 'sp_status', 'any' ); - update_post_meta( $id, 'sp_date', 0 ); - update_post_meta( $id, 'sp_team', 0 ); - update_post_meta( $id, 'sp_order', 'ASC' ); - update_post_meta( $id, 'sp_columns', $columns ); - - /* - * Insert league table - */ - $leagues = get_terms( 'sp_league', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); - $league = reset( $leagues ); - $seasons = get_terms( 'sp_season', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); - $season = reset( $seasons ); - $post = array( - 'post_title' => $league->name . ' ' . $season->name, - 'post_type' => 'sp_table', - 'post_status' => 'publish', - 'post_content' => sprintf( $sample_content, __( 'League Table', 'sportspress' ), __( 'League Tables', 'sportspress' ), admin_url() ), - 'tax_input' => array( - 'sp_league' => $league->term_id, - 'sp_season' => $season->term_id, - ), - ); - - // Insert post - $id = wp_insert_post( $post ); - - // Add to inserted ids array - $inserted_ids['sp_table'][] = $id; - - // Flag as sample - update_post_meta( $id, '_sp_sample', 1 ); - - // Get columns - $columns = array(); - $args = array( - 'post_type' => 'sp_column', - 'posts_per_page' => 8, - 'orderby' => 'menu_order', - 'order' => 'ASC', - ); - $column_posts = get_posts( $args ); - foreach ( $column_posts as $column_post ) { - $columns[] = $column_post->post_name; - } - - // Update meta - sp_update_post_meta_recursive( $id, 'sp_team', $inserted_ids['sp_team'] ); - update_post_meta( $id, 'sp_columns', $columns ); - update_post_meta( $id, 'sp_highlight', reset( $inserted_ids['sp_team'] ) ); - - /* - * Insert player list for each team - */ - foreach ( $inserted_ids['sp_team'] as $index => $team_id ) { - $post = array( - 'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ), - 'post_type' => 'sp_list', - 'post_status' => 'publish', - 'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), admin_url() ), - ); - - // Insert post - $id = wp_insert_post( $post ); - - // Add to inserted ids array - $inserted_ids['sp_list'][] = $id; - - // Flag as sample - update_post_meta( $id, '_sp_sample', 1 ); - - // Get players from team - $list_players = array_slice( $inserted_ids['sp_player'], $index * 4, 4 ); - // Get columns $columns = array(); $args = array( - 'post_type' => array( 'sp_metric' ), - 'posts_per_page' => 2, + 'post_type' => 'sp_column', + 'posts_per_page' => 8, 'orderby' => 'menu_order', 'order' => 'ASC', ); @@ -576,13 +542,57 @@ class SP_Admin_Sample_Data { } // Update meta - update_post_meta( $id, 'sp_format', 'list' ); - sp_update_post_meta_recursive( $id, 'sp_player', $list_players ); + sp_update_post_meta_recursive( $id, 'sp_team', $inserted_ids['sp_team'] ); update_post_meta( $id, 'sp_columns', $columns ); - update_post_meta( $id, 'sp_grouping', 'position' ); - update_post_meta( $id, 'sp_orderby', 'name' ); - update_post_meta( $id, 'sp_order', 'ASC' ); - update_post_meta( $id, 'sp_team', $team_id ); + update_post_meta( $id, 'sp_highlight', reset( $inserted_ids['sp_team'] ) ); + } + + /* + * Insert player list for each team + */ + if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { + foreach ( $inserted_ids['sp_team'] as $index => $team_id ) { + $post = array( + 'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ), + 'post_type' => 'sp_list', + 'post_status' => 'publish', + 'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), admin_url() ), + ); + + // Insert post + $id = wp_insert_post( $post ); + + // Add to inserted ids array + $inserted_ids['sp_list'][] = $id; + + // Flag as sample + update_post_meta( $id, '_sp_sample', 1 ); + + // Get players from team + $list_players = array_slice( $inserted_ids['sp_player'], $index * 4, 4 ); + + // Get columns + $columns = array(); + $args = array( + 'post_type' => array( 'sp_metric' ), + 'posts_per_page' => 2, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); + $column_posts = get_posts( $args ); + foreach ( $column_posts as $column_post ) { + $columns[] = $column_post->post_name; + } + + // Update meta + update_post_meta( $id, 'sp_format', 'list' ); + sp_update_post_meta_recursive( $id, 'sp_player', $list_players ); + update_post_meta( $id, 'sp_columns', $columns ); + update_post_meta( $id, 'sp_grouping', 'position' ); + update_post_meta( $id, 'sp_orderby', 'name' ); + update_post_meta( $id, 'sp_order', 'ASC' ); + update_post_meta( $id, 'sp_team', $team_id ); + } } /* @@ -620,9 +630,11 @@ class SP_Admin_Sample_Data { /* * Update player list and league table per team */ - foreach ( $inserted_ids['sp_team'] as $index => $team_id ) { - update_post_meta( $team_id, 'sp_list', sp_array_value( $inserted_ids['sp_list'], $index, 0 ) ); - update_post_meta( $team_id, 'sp_table', sp_array_value( $inserted_ids['sp_table'], 0 ) ); + if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { + foreach ( $inserted_ids['sp_team'] as $index => $team_id ) { + update_post_meta( $team_id, 'sp_list', sp_array_value( $inserted_ids['sp_list'], $index, 0 ) ); + update_post_meta( $team_id, 'sp_table', sp_array_value( $inserted_ids['sp_table'], 0 ) ); + } } } diff --git a/includes/admin/class-sp-admin-settings.php b/includes/admin/class-sp-admin-settings.php index 937921b6..775e2cd9 100644 --- a/includes/admin/class-sp-admin-settings.php +++ b/includes/admin/class-sp-admin-settings.php @@ -34,7 +34,10 @@ class SP_Admin_Settings { $settings[] = include( 'settings/class-sp-settings-modules.php' ); $settings[] = include( 'settings/class-sp-settings-general.php' ); $settings[] = include( 'settings/class-sp-settings-events.php' ); - $settings[] = include( 'settings/class-sp-settings-teams.php' ); + + if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) + $settings[] = include( 'settings/class-sp-settings-teams.php' ); + $settings[] = include( 'settings/class-sp-settings-players.php' ); $settings[] = include( 'settings/class-sp-settings-staff.php' ); diff --git a/includes/admin/class-sp-admin-welcome.php b/includes/admin/class-sp-admin-welcome.php index aebc028e..5285618b 100644 --- a/includes/admin/class-sp-admin-welcome.php +++ b/includes/admin/class-sp-admin-welcome.php @@ -194,14 +194,16 @@ class SP_Admin_Welcome {

- +

@@ -265,7 +267,7 @@ class SP_Admin_Welcome { 'type' => 'radio', 'options' => array( 'team' => __( 'Teams', 'sportspress' ), - 'player' => __( 'Players', 'sportspress' ), + 'player' => __( 'Players', 'sportspress' ) . ' ' . __( '(Beta)', 'sportspress' ), ), 'desc_tip' => _x( 'Who competes in events?', 'mode setting description', 'sportspress' ), ), diff --git a/includes/admin/post-types/class-sp-admin-meta-boxes.php b/includes/admin/post-types/class-sp-admin-meta-boxes.php index 83135bd5..e91fc340 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -129,8 +129,14 @@ class SP_Admin_Meta_Boxes { if ( 'yes' == get_option( 'sportspress_load_videos_module', 'yes' ) ) { add_meta_box( 'sp_videodiv', __( 'Video', 'sportspress' ), 'SP_Meta_Box_Event_Video::output', 'sp_event', 'side', 'low' ); } - add_meta_box( 'sp_resultsdiv', __( 'Team Results', 'sportspress' ), 'SP_Meta_Box_Event_Results::output', 'sp_event', 'normal', 'high' ); - add_meta_box( 'sp_performancediv', __( 'Player Performance', 'sportspress' ), 'SP_Meta_Box_Event_Performance::output', 'sp_event', 'normal', 'high' ); + $teams = array_filter( sp_array_value( $post_meta, 'sp_team', array() ), array( $this, 'positive' ) ); + if ( ! empty( $teams ) ) { + add_meta_box( 'sp_resultsdiv', __( 'Team Results', 'sportspress' ), 'SP_Meta_Box_Event_Results::output', 'sp_event', 'normal', 'high' ); + } + $players = array_filter( sp_array_value( $post_meta, 'sp_player', array() ), array( $this, 'positive' ) ); + if ( ! empty( $players ) ) { + add_meta_box( 'sp_performancediv', __( 'Player Performance', 'sportspress' ), 'SP_Meta_Box_Event_Performance::output', 'sp_event', 'normal', 'high' ); + } add_meta_box( 'sp_editordiv', __( 'Article', 'sportspress' ), 'SP_Meta_Box_Event_Editor::output', 'sp_event', 'normal', 'low' ); if ( 'yes' == get_option( 'sportspress_load_calendars_module', 'yes' ) ) { @@ -263,6 +269,13 @@ class SP_Admin_Meta_Boxes { do_action( 'sportspress_process_' . $post->post_type . '_meta', $post_id, $post ); } + /* + * Array filter removes values that are not positive. + */ + public function positive( $var = 0 ) { + return $var > 0; + } + } new SP_Admin_Meta_Boxes(); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php index 7f6eee5c..8766c92a 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php @@ -104,21 +104,23 @@ class SP_Meta_Box_Calendar_Details { endif; ?>

-

-

- __( 'All', 'sportspress' ), - 'post_type' => 'sp_team', - 'name' => 'sp_team', - 'selected' => $team_id, - 'values' => 'ID' - ); - if ( ! sp_dropdown_pages( $args ) ): - sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); - endif; - ?> -

+ +

+

+ __( 'All', 'sportspress' ), + 'post_type' => 'sp_team', + 'name' => 'sp_team', + 'selected' => $team_id, + 'values' => 'ID' + ); + if ( ! sp_dropdown_pages( $args ) ): + sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); + endif; + ?> +

+

> - - + + + $label ): ?>

-

-

- 'sp_team', - 'name' => 'sp_team', - 'show_option_all' => __( 'All', 'sportspress' ), - 'selected' => $team_id, - 'values' => 'ID', - ); - if ( ! sp_dropdown_pages( $args ) ): - sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); - endif; - ?> -

+ +

+

+ 'sp_team', + 'name' => 'sp_team', + 'show_option_all' => __( 'All', 'sportspress' ), + 'selected' => $team_id, + 'values' => 'ID', + ); + if ( ! sp_dropdown_pages( $args ) ): + sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); + endif; + ?> +

+

> + + + + + + - - - - - + + + $label ): if ( $key == 'team' ) continue; ?> @@ -87,18 +89,29 @@ class SP_Meta_Box_Player_Statistics { ?> - name; - ?> - - - -   - - + + + + name; + ?> + + + + + +   + + + 'sp_team', @@ -127,10 +140,8 @@ class SP_Meta_Box_Player_Statistics { _e( '— None —', 'sportspress' ); endif; ?> - - > - - + + $label ): if ( $column == 'team' ) continue; diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-staff-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-staff-details.php index a81a78a0..86991237 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-staff-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-staff-details.php @@ -81,35 +81,37 @@ class SP_Meta_Box_Staff_Details {

+

-

'sp_team', - 'name' => 'sp_current_team[]', - 'selected' => $current_teams, - 'values' => 'ID', - 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ), - 'class' => 'sp-current-teams widefat', - 'property' => 'multiple', - 'chosen' => true, - ); - sp_dropdown_pages( $args ); - ?>

+

'sp_team', + 'name' => 'sp_current_team[]', + 'selected' => $current_teams, + 'values' => 'ID', + 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ), + 'class' => 'sp-current-teams widefat', + 'property' => 'multiple', + 'chosen' => true, + ); + sp_dropdown_pages( $args ); + ?>

-

-

'sp_team', - 'name' => 'sp_past_team[]', - 'selected' => $past_teams, - 'values' => 'ID', - 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ), - 'class' => 'sp-past-teams widefat', - 'property' => 'multiple', - 'chosen' => true, - ); - sp_dropdown_pages( $args ); - ?>

+

+

'sp_team', + 'name' => 'sp_past_team[]', + 'selected' => $past_teams, + 'values' => 'ID', + 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ), + 'class' => 'sp-past-teams widefat', + 'property' => 'multiple', + 'chosen' => true, + ); + sp_dropdown_pages( $args ); + ?>

+

id, array( $this, 'output' ) ); add_action( 'sportspress_admin_field_timezone', array( $this, 'timezone_setting' ) ); add_action( 'sportspress_admin_field_frontend_styles', array( $this, 'frontend_styles_setting' ) ); + add_action( 'sportspress_admin_field_current_mode', array( $this, 'current_mode_setting' ) ); add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) ); } @@ -64,10 +65,12 @@ class SP_Settings_General extends SP_Settings_Page { 'type' => 'radio', 'options' => array( 'team' => __( 'Teams', 'sportspress' ), - 'player' => __( 'Players', 'sportspress' ), + 'player' => __( 'Players', 'sportspress' ) . ' ' . __( '(Beta)', 'sportspress' ), ), 'desc_tip' => _x( 'Who competes in events?', 'mode setting description', 'sportspress' ), ), + + array( 'type' => 'current_mode' ), )), array( @@ -335,6 +338,21 @@ class SP_Settings_General extends SP_Settings_Page {

'; } + + /** + * Output script to refresh page when mode is changed. + */ + function current_mode_setting() { + ?> + + + + get_screenshot(); ?>" class="sp-theme-screenshot">

Your theme does not declare SportsPress support – if you encounter layout issues please read our integration guide or choose a SportsPress theme :)', 'sportspress' ); ?>

- + +

@@ -194,6 +195,7 @@ class SP_Settings_Modules extends SP_Settings_Page {
modules->data as $section => $modules ) { ?> +
diff --git a/includes/admin/sp-admin-functions.php b/includes/admin/sp-admin-functions.php index d6cc3b20..0ba7c6ae 100755 --- a/includes/admin/sp-admin-functions.php +++ b/includes/admin/sp-admin-functions.php @@ -21,6 +21,8 @@ function sp_get_screen_ids() { 'widgets', 'dashboard', 'dashboard_page_sp-about', + 'dashboard_page_sp-credits', + 'dashboard_page_sp-translators', 'toplevel_page_sportspress', 'edit-sp_result', 'sp_result', diff --git a/includes/admin/views/html-admin-config.php b/includes/admin/views/html-admin-config.php index d472f146..5677f690 100644 --- a/includes/admin/views/html-admin-config.php +++ b/includes/admin/views/html-admin-config.php @@ -55,79 +55,81 @@
- - - +
+ + 'sp_result', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'orderby' => 'menu_order', - 'order' => 'ASC' - ); - $data = get_posts( $args ); - ?> - - -
- -

-
- -
- - - - - - - - - + $args = array( + 'post_type' => 'sp_result', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ); + $data = get_posts( $args ); + ?> + + + - - -
+ +

+
+ + + + + + + + + + + + + + + + + + + + + > + + + + + + + + + - - - - - - - - - > - - - - - - - - - - - -
>
post_name ); ?>>post_name; ?>for, post_name; ?>against

post_excerpt; ?>

>
post_name ); ?>>post_name; ?>for, post_name; ?>against

post_excerpt; ?>

- -
- - -
-
-
+ +
+ +
+ + +
+
+ + + + +
- - - 'sp_column', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'orderby' => 'menu_order', - 'order' => 'ASC' - ); - $data = get_posts( $args ); - ?> - - - - - -
- -

-
- - - - - - - - - - - - - - > - - - - - - - - - - - - - -
post_title; ?>post_name; ?>ID ); ?>ID ); ?>ID ); ?>

post_excerpt; ?>

-
- - -
-
- -
+ + + + 'sp_column', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ); + $data = get_posts( $args ); + ?> + + + + + +
+ +

+
+ + + + + + + + + + + + + + > + + + + + + + + + + + + + +
post_title; ?>post_name; ?>ID ); ?>ID ); ?>ID ); ?>

post_excerpt; ?>

+
+ + +
+
+ +
+ columns as $key ): if ( $key == 'number' ): $labels[ $key ] = '#'; - elseif ( $key == 'team' ): + elseif ( $key == 'team' && 'team' == get_option( 'sportspress_mode', 'team' ) ): $labels[ $key ] = __( 'Team', 'sportspress' ); elseif ( array_key_exists( $key, $columns ) ): $labels[ $key ] = $columns[ $key ]; @@ -469,7 +469,7 @@ class SP_Player_List extends SP_Custom_Post { $labels = array(); if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#'; $labels['name'] = __( 'Player', 'sportspress' ); - if ( in_array( 'team', $this->columns ) ) $labels['team'] = __( 'Team', 'sportspress' ); + if ( in_array( 'team', $this->columns ) && 'team' == get_option( 'sportspress_mode', 'team' ) ) $labels['team'] = __( 'Team', 'sportspress' ); $merged[0] = array_merge( $labels, $columns ); return $merged; diff --git a/includes/class-sp-post-types.php b/includes/class-sp-post-types.php index 1b87d890..007f382e 100644 --- a/includes/class-sp-post-types.php +++ b/includes/class-sp-post-types.php @@ -429,67 +429,69 @@ class SP_Post_types { ); } - register_post_type( 'sp_team', - apply_filters( 'sportspress_register_post_type_team', - array( - 'labels' => array( - 'name' => __( 'Teams', 'sportspress' ), - 'singular_name' => __( 'Team', 'sportspress' ), - 'add_new_item' => __( 'Add New Team', 'sportspress' ), - 'edit_item' => __( 'Edit Team', 'sportspress' ), - 'new_item' => __( 'New', 'sportspress' ), - 'view_item' => __( 'View Team', 'sportspress' ), - 'search_items' => __( 'Search', 'sportspress' ), - 'not_found' => __( 'No results found.', 'sportspress' ), - 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), - ), - 'public' => true, - 'show_ui' => true, - 'capability_type' => 'sp_team', - 'map_meta_cap' => true, - 'publicly_queryable' => true, - 'exclude_from_search' => false, - 'hierarchical' => true, - 'rewrite' => array( 'slug' => get_option( 'sportspress_team_slug', 'team' ) ), - 'supports' => array( 'title', 'author', 'thumbnail', 'page-attributes', 'excerpt' ), - 'has_archive' => false, - 'show_in_nav_menus' => true, - 'menu_icon' => 'dashicons-shield-alt', - ) - ) - ); - - if ( 'yes' == get_option( 'sportspress_load_league_tables_module', 'yes' ) ) { - register_post_type( 'sp_table', - apply_filters( 'sportspress_register_post_type_table', + if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { + register_post_type( 'sp_team', + apply_filters( 'sportspress_register_post_type_team', array( 'labels' => array( - 'name' => __( 'League Tables', 'sportspress' ), - 'singular_name' => __( 'League Table', 'sportspress' ), - 'add_new_item' => __( 'Add New League Table', 'sportspress' ), - 'edit_item' => __( 'Edit League Table', 'sportspress' ), + 'name' => __( 'Teams', 'sportspress' ), + 'singular_name' => __( 'Team', 'sportspress' ), + 'add_new_item' => __( 'Add New Team', 'sportspress' ), + 'edit_item' => __( 'Edit Team', 'sportspress' ), 'new_item' => __( 'New', 'sportspress' ), - 'view_item' => __( 'View League Table', 'sportspress' ), + 'view_item' => __( 'View Team', 'sportspress' ), 'search_items' => __( 'Search', 'sportspress' ), 'not_found' => __( 'No results found.', 'sportspress' ), 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), ), 'public' => true, 'show_ui' => true, - 'capability_type' => 'sp_table', + 'capability_type' => 'sp_team', 'map_meta_cap' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, - 'hierarchical' => false, - 'rewrite' => array( 'slug' => get_option( 'sportspress_table_slug', 'table' ) ), - 'supports' => array( 'title', 'page-attributes', 'thumbnail' ), + 'hierarchical' => true, + 'rewrite' => array( 'slug' => get_option( 'sportspress_team_slug', 'team' ) ), + 'supports' => array( 'title', 'author', 'thumbnail', 'page-attributes', 'excerpt' ), 'has_archive' => false, 'show_in_nav_menus' => true, - 'show_in_menu' => 'edit.php?post_type=sp_team', - 'show_in_admin_bar' => true, + 'menu_icon' => 'dashicons-shield-alt', ) ) ); + + if ( 'yes' == get_option( 'sportspress_load_league_tables_module', 'yes' ) ) { + register_post_type( 'sp_table', + apply_filters( 'sportspress_register_post_type_table', + array( + 'labels' => array( + 'name' => __( 'League Tables', 'sportspress' ), + 'singular_name' => __( 'League Table', 'sportspress' ), + 'add_new_item' => __( 'Add New League Table', 'sportspress' ), + 'edit_item' => __( 'Edit League Table', 'sportspress' ), + 'new_item' => __( 'New', 'sportspress' ), + 'view_item' => __( 'View League Table', 'sportspress' ), + 'search_items' => __( 'Search', 'sportspress' ), + 'not_found' => __( 'No results found.', 'sportspress' ), + 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), + ), + 'public' => true, + 'show_ui' => true, + 'capability_type' => 'sp_table', + 'map_meta_cap' => true, + 'publicly_queryable' => true, + 'exclude_from_search' => false, + 'hierarchical' => false, + 'rewrite' => array( 'slug' => get_option( 'sportspress_table_slug', 'table' ) ), + 'supports' => array( 'title', 'page-attributes', 'thumbnail' ), + 'has_archive' => false, + 'show_in_nav_menus' => true, + 'show_in_menu' => 'edit.php?post_type=sp_team', + 'show_in_admin_bar' => true, + ) + ) + ); + } } register_post_type( 'sp_player', diff --git a/templates/event-performance.php b/templates/event-performance.php index 9a1d84cc..e7b8135c 100644 --- a/templates/event-performance.php +++ b/templates/event-performance.php @@ -61,8 +61,15 @@ if ( is_array( $teams ) ): $totals = array(); - if ( $team_id ) { + if ( 0 < $team_id ) { $data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) ); + } elseif ( 0 == $team_id ) { + $data = array(); + foreach ( $players as $player_id ) { + if ( isset( $performance[ $player_id ][ $player_id ] ) ) { + $data[ $player_id ] = $performance[ $player_id ][ $player_id ]; + } + } } else { $data = sp_array_value( array_values( $performance ), $index ); }