diff --git a/admin-functions.php b/admin-functions.php index 7d337f59..92d98071 100644 --- a/admin-functions.php +++ b/admin-functions.php @@ -229,11 +229,14 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) { 'meta_value' => null, 'authors' => null, 'exclude_tree' => null, - 'post_type' => 'page' + 'post_type' => 'page', + 'values' => 'post_name', ); $args = array_merge( $defaults, $args ); $name = $args['name']; unset( $args['name'] ); + $values = $args['values']; + unset( $args['values'] ); $posts = get_posts( $args ); if ( $posts ) { printf( '' ); } @@ -671,13 +678,14 @@ if ( !function_exists( 'sportspress_edit_team_columns_table' ) ) { } if ( !function_exists( 'sportspress_edit_player_statistics_table' ) ) { - function sportspress_edit_player_statistics_table( $team_id, $columns = array(), $data = array(), $placeholders = array() ) { + function sportspress_edit_player_statistics_table( $league_id, $columns = array(), $data = array(), $placeholders = array() ) { ?>
+ @@ -694,11 +702,26 @@ if ( !function_exists( 'sportspress_edit_player_statistics_table' ) ) { + $label ): $value = sportspress_array_value( $div_stats, $column, '' ); $placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $div_id, array() ), $column, 0 ); ?> - + term_id; + endforeach; + $season_ids = array(); foreach( $seasons as $season ): $season_ids[] = $season->term_id; @@ -1053,7 +1082,14 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) { 'posts_per_page' => -1, 'orderby' => 'post_date', 'order' => 'ASC', + 'post_status' => 'any', 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_ids + ), array( 'taxonomy' => 'sp_season', 'field' => 'id', @@ -1073,8 +1109,215 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) { } } +if ( !function_exists( 'sportspress_get_team_columns_data' ) ) { + function sportspress_get_team_columns_data( $post_id, $league_id, $breakdown = false ) { + + $seasons = (array)get_the_terms( $post_id, 'sp_season' ); + $columns = (array)get_post_meta( $post_id, 'sp_columns', true ); + + // Equation Operating System + $eos = new eqEOS(); + + // Get labels from result variables + $result_labels = (array)sportspress_get_var_labels( 'sp_result' ); + + // Get labels from outcome variables + $outcome_labels = (array)sportspress_get_var_labels( 'sp_outcome' ); + + // Generate array of all season ids and season names + $div_ids = array(); + $season_names = array(); + foreach ( $seasons as $season ): + if ( is_object( $season ) && property_exists( $season, 'term_id' ) && property_exists( $season, 'name' ) ): + $div_ids[] = $season->term_id; + $season_names[ $season->term_id ] = $season->name; + endif; + endforeach; + + // Get all leagues populated with columns where available + $data = sportspress_array_combine( $div_ids, $columns ); + + // Get equations from column variables + $equations = sportspress_get_var_equations( 'sp_column' ); + + // Initialize placeholders array + $placeholders = array(); + + foreach ( $div_ids as $div_id ): + + $totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last10' => null ); + + foreach ( $result_labels as $key => $value ): + $totals[ $key . 'for' ] = 0; + $totals[ $key . 'against' ] = 0; + endforeach; + + foreach ( $outcome_labels as $key => $value ): + $totals[ $key ] = 0; + endforeach; + + // Initialize streaks counter + $streak = array( 'name' => '', 'count' => 0, 'fire' => 1 ); + + // Initialize last 10 counter + $last10 = array(); + + // Add outcome types to last 10 counter + foreach( $outcome_labels as $key => $value ): + $last10[ $key ] = 0; + endforeach; + + // Get all events involving the team in current season + $args = array( + 'post_type' => 'sp_event', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'order' => 'ASC', + 'meta_query' => array( + array( + 'key' => 'sp_team', + 'value' => $post_id + ) + ), + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_id + ), + array( + 'taxonomy' => 'sp_season', + 'field' => 'id', + 'terms' => $div_id + ) + ) + ); + $events = get_posts( $args ); + + foreach( $events as $event ): + $results = (array)get_post_meta( $event->ID, 'sp_results', true ); + foreach ( $results as $team_id => $team_result ): + foreach ( $team_result as $key => $value ): + if ( $team_id == $post_id ): + if ( $key == 'outcome' ): + + // Increment events played and outcome count + if ( array_key_exists( $value, $totals ) ): + $totals['eventsplayed']++; + $totals[ $value ]++; + endif; + + if ( $value && $value != '-1' ): + + // Add to streak counter + if ( $streak['fire'] && ( $streak['name'] == '' || $streak['name'] == $value ) ): + $streak['name'] = $value; + $streak['count'] ++; + else: + $streak['fire'] = 0; + endif; + + // Add to last 10 counter if sum is less than 10 + if ( array_key_exists( $value, $last10 ) && array_sum( $last10 ) < 10 ): + $last10[ $value ] ++; + endif; + + endif; + + else: + if ( array_key_exists( $key . 'for', $totals ) ): + $totals[ $key . 'for' ] += $value; + endif; + endif; + else: + if ( $key != 'outcome' ): + if ( array_key_exists( $key . 'against', $totals ) ): + $totals[ $key . 'against' ] += $value; + endif; + endif; + endif; + endforeach; + endforeach; + endforeach; + + // Compile streaks counter and add to totals + $args=array( + 'name' => $streak['name'], + 'post_type' => 'sp_outcome', + 'post_status' => 'publish', + 'posts_per_page' => 1 + ); + $outcomes = get_posts( $args ); + + if ( $outcomes ): + $outcome = $outcomes[0]; + $totals['streak'] = $outcome->post_title . $streak['count']; + endif; + + // Add last 10 to totals + $totals['last10'] = $last10; + + // Generate array of placeholder values for each league + $placeholders[ $div_id ] = array(); + foreach ( $equations as $key => $value ): + if ( $totals['eventsplayed'] > 0 ): + $placeholders[ $div_id ][ $key ] = sportspress_solve( $value, $totals ); + else: + $placeholders[ $div_id ][ $key ] = 0; + endif; + endforeach; + + endforeach; + + // Get columns from column variables + $columns = sportspress_get_var_labels( 'sp_column' ); + + // Merge the data and placeholders arrays + $merged = array(); + + foreach( $placeholders as $season_id => $season_data ): + + $include = sportspress_array_value( sportspress_array_value( $data, $season_id, array() ), 'include', 0 ); + + if ( ! $include && false ) #todo + continue; + + $season_name = sportspress_array_value( $season_names, $season_id, ' ' ); + + // Add season name to row + $merged[ $season_id ] = array( + 'name' => $season_name + ); + + foreach( $season_data as $key => $value ): + + // Use static data if key exists and value is not empty, else use placeholder + if ( array_key_exists( $season_id, $data ) && array_key_exists( $key, $data[ $season_id ] ) && $data[ $season_id ][ $key ] != '' ): + $merged[ $season_id ][ $key ] = $data[ $season_id ][ $key ]; + else: + $merged[ $season_id ][ $key ] = $value; + endif; + + endforeach; + + endforeach; + + if ( $breakdown ): + return array( $columns, $data, $placeholders, $merged ); + else: + $labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ) ), $columns ); + $merged[0] = $labels; + return $merged; + endif; + + } + +} + if ( !function_exists( 'sportspress_get_league_table_data' ) ) { function sportspress_get_league_table_data( $post_id, $breakdown = false ) { + $league_id = sportspress_get_the_term_id( $post_id, 'sp_league', 0 ); $div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 ); $team_ids = (array)get_post_meta( $post_id, 'sp_team', false ); $table_stats = (array)get_post_meta( $post_id, 'sp_teams', true ); @@ -1139,6 +1382,12 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) { 'posts_per_page' => -1, 'order' => 'ASC', 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_id + ), array( 'taxonomy' => 'sp_season', 'field' => 'id', @@ -1341,6 +1590,7 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) { if ( !function_exists( 'sportspress_get_player_list_data' ) ) { function sportspress_get_player_list_data( $post_id, $breakdown = false ) { + $league_id = sportspress_get_the_term_id( $post_id, 'sp_league', 0 ); $div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 ); $team_id = get_post_meta( $post_id, 'sp_team', true ); $player_ids = (array)get_post_meta( $post_id, 'sp_player', false ); @@ -1379,8 +1629,8 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) { $placeholders[ $player_id ] = array(); // Add static statistics to placeholders - if ( array_key_exists( $team_id, $static ) && array_key_exists( $div_id, $static[ $team_id ] ) ): - $placeholders[ $player_id ] = $static[ $team_id ][ $div_id ]; + if ( array_key_exists( $league_id, $static ) && array_key_exists( $div_id, $static[ $league_id ] ) ): + $placeholders[ $player_id ] = $static[ $league_id ][ $div_id ]; endif; endforeach; @@ -1389,6 +1639,12 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) { 'numberposts' => -1, 'posts_per_page' => -1, 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_id + ), array( 'taxonomy' => 'sp_season', 'field' => 'id', @@ -1569,7 +1825,7 @@ if ( !function_exists( 'sportspress_get_player_metrics_data' ) ) { } if ( !function_exists( 'sportspress_get_player_statistics_data' ) ) { - function sportspress_get_player_statistics_data( $post_id, $team_id, $breakdown = false ) { + function sportspress_get_player_statistics_data( $post_id, $league_id, $breakdown = false ) { $seasons = (array)get_the_terms( $post_id, 'sp_season' ); $stats = (array)get_post_meta( $post_id, 'sp_statistics', true ); @@ -1590,13 +1846,15 @@ if ( !function_exists( 'sportspress_get_player_statistics_data' ) ) { $tempdata = array(); // Get all seasons populated with stats where available - $tempdata = sportspress_array_combine( $div_ids, sportspress_array_value( $stats, $team_id, array() ) ); + $tempdata = sportspress_array_combine( $div_ids, sportspress_array_value( $stats, $league_id, array() ) ); // Get equations from statistics variables $equations = sportspress_get_var_equations( 'sp_statistic' ); foreach ( $div_ids as $div_id ): + $team_id = sportspress_array_value( sportspress_array_value( sportspress_array_value( $stats, $league_id, array() ), $div_id, 0 ), 'team', '-1' ); + $totals = array( 'eventsattended' => 0, 'eventsplayed' => 0 ); foreach ( $statistic_labels as $key => $value ): @@ -1619,6 +1877,12 @@ if ( !function_exists( 'sportspress_get_player_statistics_data' ) ) { ) ), 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_id + ), array( 'taxonomy' => 'sp_season', 'field' => 'id', @@ -1627,9 +1891,10 @@ if ( !function_exists( 'sportspress_get_player_statistics_data' ) ) { ) ); $events = get_posts( $args ); + foreach( $events as $event ): $totals['eventsattended']++; - $totals['eventsplayed']++; // TODO: create tab for substitutes in sidebar + $totals['eventsplayed']++; $team_statistics = (array)get_post_meta( $event->ID, 'sp_players', true ); if ( array_key_exists( $team_id, $team_statistics ) ): $players = sportspress_array_value( $team_statistics, $team_id, array() ); @@ -1676,8 +1941,20 @@ if ( !function_exists( 'sportspress_get_player_statistics_data' ) ) { foreach( $placeholders as $season_id => $season_data ): + $team_id = sportspress_array_value( sportspress_array_value( $tempdata, $season_id, array() ), 'team', 0 ); + + if ( ! $team_id || $team_id == '-1' ) + continue; + + $team_name = get_the_title( $team_id ); + + $season_name = sportspress_array_value( $season_names, $season_id, ' ' ); + // Add season name to row - $merged[ $season_id ] = array( 'name' => sportspress_array_value( $season_names, $season_id, ' ' ) ); + $merged[ $season_id ] = array( + 'name' => $season_name, + 'team' => $team_name + ); foreach( $season_data as $key => $value ): @@ -1695,7 +1972,7 @@ if ( !function_exists( 'sportspress_get_player_statistics_data' ) ) { if ( $breakdown ): return array( $columns, $tempdata, $placeholders, $merged ); else: - $labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ) ), $columns ); + $labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ), 'team' => __( 'Team', 'sportspress' ) ), $columns ); $merged[0] = $labels; return $merged; endif; diff --git a/admin/globals/countries.php b/admin/globals/countries.php index b0145a42..d9f4f904 100644 --- a/admin/globals/countries.php +++ b/admin/globals/countries.php @@ -3,202 +3,202 @@ function sportspress_define_countries_global() { global $sportspress_countries; $sportspress_countries = array( - 'AD' => __( "Andorra", 'sportspress' ), - 'AE' => __( "United Arab Emirates", 'sportspress' ), - 'AF' => __( "Afghanistan", 'sportspress' ), - 'AG' => __( "Antigua and Barbuda", 'sportspress' ), - 'AL' => __( "Albania", 'sportspress' ), - 'AM' => __( "Armenia", 'sportspress' ), - 'AO' => __( "Angola", 'sportspress' ), - 'AR' => __( "Argentina", 'sportspress' ), - 'AT' => __( "Austria", 'sportspress' ), - 'AU' => __( "Australia", 'sportspress' ), - 'AZ' => __( "Azerbaijan", 'sportspress' ), - 'BA' => __( "Bosnia and Herzegovina", 'sportspress' ), - 'BB' => __( "Barbados", 'sportspress' ), - 'BD' => __( "Bangladesh", 'sportspress' ), - 'BE' => __( "Belgium", 'sportspress' ), - 'BF' => __( "Burkina Faso", 'sportspress' ), - 'BG' => __( "Bulgaria", 'sportspress' ), - 'BH' => __( "Bahrain", 'sportspress' ), - 'BI' => __( "Burundi", 'sportspress' ), - 'BJ' => __( "Benin", 'sportspress' ), - 'BN' => __( "Brunei", 'sportspress' ), - 'BO' => __( "Bolivia", 'sportspress' ), - 'BR' => __( "Brazil", 'sportspress' ), - 'BS' => __( "Bahamas", 'sportspress' ), - 'BT' => __( "Bhutan", 'sportspress' ), - 'BW' => __( "Botswana", 'sportspress' ), - 'BY' => __( "Belarus", 'sportspress' ), - 'BZ' => __( "Belize", 'sportspress' ), - 'CA' => __( "Canada", 'sportspress' ), - 'CD' => __( "Democratic Republic of the Congo", 'sportspress' ), - 'CF' => __( "Central African Republic", 'sportspress' ), - 'CG' => __( "Republic of the Congo", 'sportspress' ), - 'CH' => __( "Switzerland", 'sportspress' ), - 'CI' => __( "Cote d'Ivoire", 'sportspress' ), - 'CL' => __( "Chile", 'sportspress' ), - 'CM' => __( "Cameroon", 'sportspress' ), - 'CN' => __( "China", 'sportspress' ), - 'CO' => __( "Colombia", 'sportspress' ), - 'CR' => __( "Costa Rica", 'sportspress' ), - 'CU' => __( "Cuba", 'sportspress' ), - 'CV' => __( "Cape Verde", 'sportspress' ), - 'CY' => __( "Cyprus", 'sportspress' ), - 'CZ' => __( "Czech Republic", 'sportspress' ), - 'DE' => __( "Germany", 'sportspress' ), - 'DJ' => __( "Djibouti", 'sportspress' ), - 'DK' => __( "Denmark", 'sportspress' ), - 'DM' => __( "Dominica", 'sportspress' ), - 'DO' => __( "Dominican Republic", 'sportspress' ), - 'DZ' => __( "Algeria", 'sportspress' ), - 'EC' => __( "Ecuador", 'sportspress' ), - 'EE' => __( "Estonia", 'sportspress' ), - 'EG' => __( "Egypt", 'sportspress' ), - 'EH' => __( "Western Sahara", 'sportspress' ), - 'ER' => __( "Eritrea", 'sportspress' ), - 'ES' => __( "Spain", 'sportspress' ), - 'ET' => __( "Ethiopia", 'sportspress' ), - 'FI' => __( "Finland", 'sportspress' ), - 'FJ' => __( "Fiji", 'sportspress' ), - 'FM' => __( "Micronesia", 'sportspress' ), - 'FR' => __( "France", 'sportspress' ), - 'GA' => __( "Gabon", 'sportspress' ), - 'GB' => __( "United Kingdom", 'sportspress' ), - 'GD' => __( "Grenada", 'sportspress' ), - 'GE' => __( "Georgia", 'sportspress' ), - 'GH' => __( "Ghana", 'sportspress' ), - 'GM' => __( "Gambia", 'sportspress' ), - 'GN' => __( "Guinea", 'sportspress' ), - 'GQ' => __( "Equatorial Guinea", 'sportspress' ), - 'GR' => __( "Greece", 'sportspress' ), - 'GT' => __( "Guatemala", 'sportspress' ), - 'GW' => __( "Guinea-Bissau", 'sportspress' ), - 'GY' => __( "Guyana", 'sportspress' ), - 'HK' => __( "Hong Kong", 'sportspress' ), - 'HN' => __( "Honduras", 'sportspress' ), - 'HR' => __( "Croatia", 'sportspress' ), - 'HT' => __( "Haiti", 'sportspress' ), - 'HU' => __( "Hungary", 'sportspress' ), - 'ID' => __( "Indonesia", 'sportspress' ), - 'IE' => __( "Ireland", 'sportspress' ), - 'IL' => __( "Israel", 'sportspress' ), - 'IN' => __( "India", 'sportspress' ), - 'IQ' => __( "Iraq", 'sportspress' ), - 'IR' => __( "Iran", 'sportspress' ), - 'IS' => __( "Iceland", 'sportspress' ), - 'IT' => __( "Italy", 'sportspress' ), - 'JM' => __( "Jamaica", 'sportspress' ), - 'JO' => __( "Jordan", 'sportspress' ), - 'JP' => __( "Japan", 'sportspress' ), - 'KE' => __( "Kenya", 'sportspress' ), - 'KG' => __( "Kyrgyzstan", 'sportspress' ), - 'KH' => __( "Cambodia", 'sportspress' ), - 'KI' => __( "Kiribati", 'sportspress' ), - 'KM' => __( "Comoros", 'sportspress' ), - 'KN' => __( "Saint Kitts and Nevis", 'sportspress' ), - 'KP' => __( "North Korea", 'sportspress' ), - 'KR' => __( "South Korea", 'sportspress' ), - 'KW' => __( "Kuwait", 'sportspress' ), - 'KZ' => __( "Kazakhstan", 'sportspress' ), - 'LA' => __( "Laos", 'sportspress' ), - 'LB' => __( "Lebanon", 'sportspress' ), - 'LC' => __( "Saint Lucia", 'sportspress' ), - 'LI' => __( "Liechtenstein", 'sportspress' ), - 'LK' => __( "Sri Lanka", 'sportspress' ), - 'LR' => __( "Liberia", 'sportspress' ), - 'LS' => __( "Lesotho", 'sportspress' ), - 'LT' => __( "Lithuania", 'sportspress' ), - 'LU' => __( "Luxembourg", 'sportspress' ), - 'LV' => __( "Latvia", 'sportspress' ), - 'LY' => __( "Libya", 'sportspress' ), - 'MA' => __( "Morocco", 'sportspress' ), - 'MC' => __( "Monaco", 'sportspress' ), - 'MD' => __( "Moldova", 'sportspress' ), - 'ME' => __( "Montenegro", 'sportspress' ), - 'MG' => __( "Madagascar", 'sportspress' ), - 'MH' => __( "Marshall Islands", 'sportspress' ), - 'MK' => __( "Macedonia", 'sportspress' ), - 'ML' => __( "Mali", 'sportspress' ), - 'MM' => __( "Myanmar", 'sportspress' ), - 'MN' => __( "Mongolia", 'sportspress' ), - 'MO' => __( "Macau", 'sportspress' ), - 'MR' => __( "Mauritania", 'sportspress' ), - 'MT' => __( "Malta", 'sportspress' ), - 'MU' => __( "Mauritius", 'sportspress' ), - 'MV' => __( "Maldives", 'sportspress' ), - 'MW' => __( "Malawi", 'sportspress' ), - 'MX' => __( "Mexico", 'sportspress' ), - 'MY' => __( "Malaysia", 'sportspress' ), - 'MZ' => __( "Mozambique", 'sportspress' ), - 'NA' => __( "Namibia", 'sportspress' ), - 'NE' => __( "Niger", 'sportspress' ), - 'NG' => __( "Nigeria", 'sportspress' ), - 'NI' => __( "Nicaragua", 'sportspress' ), - 'NL' => __( "Netherlands", 'sportspress' ), - 'NO' => __( "Norway", 'sportspress' ), - 'NP' => __( "Nepal", 'sportspress' ), - 'NR' => __( "Nauru", 'sportspress' ), - 'NZ' => __( "New Zealand", 'sportspress' ), - 'OM' => __( "Oman", 'sportspress' ), - 'PA' => __( "Panama", 'sportspress' ), - 'PE' => __( "Peru", 'sportspress' ), - 'PG' => __( "Papua New Guinea", 'sportspress' ), - 'PH' => __( "Philippines", 'sportspress' ), - 'PK' => __( "Pakistan", 'sportspress' ), - 'PL' => __( "Poland", 'sportspress' ), - 'PT' => __( "Portugal", 'sportspress' ), - 'PW' => __( "Palau", 'sportspress' ), - 'PY' => __( "Paraguay", 'sportspress' ), - 'QA' => __( "Qatar", 'sportspress' ), - 'RO' => __( "Romania", 'sportspress' ), - 'RS' => __( "Serbia", 'sportspress' ), - 'RU' => __( "Russia", 'sportspress' ), - 'RW' => __( "Rwanda", 'sportspress' ), - 'SA' => __( "Saudi Arabia", 'sportspress' ), - 'SB' => __( "Solomon Islands", 'sportspress' ), - 'SC' => __( "Seychelles", 'sportspress' ), - 'SD' => __( "Sudan", 'sportspress' ), - 'SE' => __( "Sweden", 'sportspress' ), - 'SG' => __( "Singapore", 'sportspress' ), - 'SI' => __( "Slovenia", 'sportspress' ), - 'SK' => __( "Slovakia", 'sportspress' ), - 'SL' => __( "Sierra Leone", 'sportspress' ), - 'SM' => __( "San Marino", 'sportspress' ), - 'SN' => __( "Senegal", 'sportspress' ), - 'SO' => __( "Somalia", 'sportspress' ), - 'SR' => __( "Suriname", 'sportspress' ), - 'ST' => __( "Sao Tome and Principe", 'sportspress' ), - 'SV' => __( "El Salvador", 'sportspress' ), - 'SZ' => __( "Swaziland", 'sportspress' ), - 'TD' => __( "Chad", 'sportspress' ), - 'TG' => __( "Togo", 'sportspress' ), - 'TH' => __( "Thailand", 'sportspress' ), - 'TJ' => __( "Tajikistan", 'sportspress' ), - 'TL' => __( "East Timor", 'sportspress' ), - 'TM' => __( "Turkmenistan", 'sportspress' ), - 'TN' => __( "Tunisia", 'sportspress' ), - 'TO' => __( "Tonga", 'sportspress' ), - 'TR' => __( "Turkey", 'sportspress' ), - 'TT' => __( "Trinidad and Tobago", 'sportspress' ), - 'TV' => __( "Tuvalu", 'sportspress' ), - 'TW' => __( "Taiwan", 'sportspress' ), - 'TZ' => __( "Tanzania", 'sportspress' ), - 'UA' => __( "Ukraine", 'sportspress' ), - 'UG' => __( "Uganda", 'sportspress' ), - 'US' => __( "United States", 'sportspress' ), - 'UY' => __( "Uruguay", 'sportspress' ), - 'UZ' => __( "Uzbekistan", 'sportspress' ), - 'VA' => __( "Vatican City", 'sportspress' ), - 'VC' => __( "Saint Vincent and the Grenadines", 'sportspress' ), - 'VE' => __( "Venezuela", 'sportspress' ), - 'VN' => __( "Vietnam", 'sportspress' ), - 'VU' => __( "Vanuatu", 'sportspress' ), - 'WS' => __( "Samoa", 'sportspress' ), - 'YE' => __( "Yemen", 'sportspress' ), - 'ZA' => __( "South Africa", 'sportspress' ), - 'ZM' => __( "Zambia", 'sportspress' ), - 'ZW' => __( "Zimbabwe", 'sportspress' ), + 'AD' => __( "Andorra", 'countries' ), + 'AE' => __( "United Arab Emirates", 'countries' ), + 'AF' => __( "Afghanistan", 'countries' ), + 'AG' => __( "Antigua and Barbuda", 'countries' ), + 'AL' => __( "Albania", 'countries' ), + 'AM' => __( "Armenia", 'countries' ), + 'AO' => __( "Angola", 'countries' ), + 'AR' => __( "Argentina", 'countries' ), + 'AT' => __( "Austria", 'countries' ), + 'AU' => __( "Australia", 'countries' ), + 'AZ' => __( "Azerbaijan", 'countries' ), + 'BA' => __( "Bosnia and Herzegovina", 'countries' ), + 'BB' => __( "Barbados", 'countries' ), + 'BD' => __( "Bangladesh", 'countries' ), + 'BE' => __( "Belgium", 'countries' ), + 'BF' => __( "Burkina Faso", 'countries' ), + 'BG' => __( "Bulgaria", 'countries' ), + 'BH' => __( "Bahrain", 'countries' ), + 'BI' => __( "Burundi", 'countries' ), + 'BJ' => __( "Benin", 'countries' ), + 'BN' => __( "Brunei", 'countries' ), + 'BO' => __( "Bolivia", 'countries' ), + 'BR' => __( "Brazil", 'countries' ), + 'BS' => __( "Bahamas", 'countries' ), + 'BT' => __( "Bhutan", 'countries' ), + 'BW' => __( "Botswana", 'countries' ), + 'BY' => __( "Belarus", 'countries' ), + 'BZ' => __( "Belize", 'countries' ), + 'CA' => __( "Canada", 'countries' ), + 'CD' => __( "Democratic Republic of the Congo", 'countries' ), + 'CF' => __( "Central African Republic", 'countries' ), + 'CG' => __( "Republic of the Congo", 'countries' ), + 'CH' => __( "Switzerland", 'countries' ), + 'CI' => __( "Cote d'Ivoire", 'countries' ), + 'CL' => __( "Chile", 'countries' ), + 'CM' => __( "Cameroon", 'countries' ), + 'CN' => __( "China", 'countries' ), + 'CO' => __( "Colombia", 'countries' ), + 'CR' => __( "Costa Rica", 'countries' ), + 'CU' => __( "Cuba", 'countries' ), + 'CV' => __( "Cape Verde", 'countries' ), + 'CY' => __( "Cyprus", 'countries' ), + 'CZ' => __( "Czech Republic", 'countries' ), + 'DE' => __( "Germany", 'countries' ), + 'DJ' => __( "Djibouti", 'countries' ), + 'DK' => __( "Denmark", 'countries' ), + 'DM' => __( "Dominica", 'countries' ), + 'DO' => __( "Dominican Republic", 'countries' ), + 'DZ' => __( "Algeria", 'countries' ), + 'EC' => __( "Ecuador", 'countries' ), + 'EE' => __( "Estonia", 'countries' ), + 'EG' => __( "Egypt", 'countries' ), + 'EH' => __( "Western Sahara", 'countries' ), + 'ER' => __( "Eritrea", 'countries' ), + 'ES' => __( "Spain", 'countries' ), + 'ET' => __( "Ethiopia", 'countries' ), + 'FI' => __( "Finland", 'countries' ), + 'FJ' => __( "Fiji", 'countries' ), + 'FM' => __( "Micronesia", 'countries' ), + 'FR' => __( "France", 'countries' ), + 'GA' => __( "Gabon", 'countries' ), + 'GB' => __( "United Kingdom", 'countries' ), + 'GD' => __( "Grenada", 'countries' ), + 'GE' => __( "Georgia", 'countries' ), + 'GH' => __( "Ghana", 'countries' ), + 'GM' => __( "Gambia", 'countries' ), + 'GN' => __( "Guinea", 'countries' ), + 'GQ' => __( "Equatorial Guinea", 'countries' ), + 'GR' => __( "Greece", 'countries' ), + 'GT' => __( "Guatemala", 'countries' ), + 'GW' => __( "Guinea-Bissau", 'countries' ), + 'GY' => __( "Guyana", 'countries' ), + 'HK' => __( "Hong Kong", 'countries' ), + 'HN' => __( "Honduras", 'countries' ), + 'HR' => __( "Croatia", 'countries' ), + 'HT' => __( "Haiti", 'countries' ), + 'HU' => __( "Hungary", 'countries' ), + 'ID' => __( "Indonesia", 'countries' ), + 'IE' => __( "Ireland", 'countries' ), + 'IL' => __( "Israel", 'countries' ), + 'IN' => __( "India", 'countries' ), + 'IQ' => __( "Iraq", 'countries' ), + 'IR' => __( "Iran", 'countries' ), + 'IS' => __( "Iceland", 'countries' ), + 'IT' => __( "Italy", 'countries' ), + 'JM' => __( "Jamaica", 'countries' ), + 'JO' => __( "Jordan", 'countries' ), + 'JP' => __( "Japan", 'countries' ), + 'KE' => __( "Kenya", 'countries' ), + 'KG' => __( "Kyrgyzstan", 'countries' ), + 'KH' => __( "Cambodia", 'countries' ), + 'KI' => __( "Kiribati", 'countries' ), + 'KM' => __( "Comoros", 'countries' ), + 'KN' => __( "Saint Kitts and Nevis", 'countries' ), + 'KP' => __( "North Korea", 'countries' ), + 'KR' => __( "South Korea", 'countries' ), + 'KW' => __( "Kuwait", 'countries' ), + 'KZ' => __( "Kazakhstan", 'countries' ), + 'LA' => __( "Laos", 'countries' ), + 'LB' => __( "Lebanon", 'countries' ), + 'LC' => __( "Saint Lucia", 'countries' ), + 'LI' => __( "Liechtenstein", 'countries' ), + 'LK' => __( "Sri Lanka", 'countries' ), + 'LR' => __( "Liberia", 'countries' ), + 'LS' => __( "Lesotho", 'countries' ), + 'LT' => __( "Lithuania", 'countries' ), + 'LU' => __( "Luxembourg", 'countries' ), + 'LV' => __( "Latvia", 'countries' ), + 'LY' => __( "Libya", 'countries' ), + 'MA' => __( "Morocco", 'countries' ), + 'MC' => __( "Monaco", 'countries' ), + 'MD' => __( "Moldova", 'countries' ), + 'ME' => __( "Montenegro", 'countries' ), + 'MG' => __( "Madagascar", 'countries' ), + 'MH' => __( "Marshall Islands", 'countries' ), + 'MK' => __( "Macedonia", 'countries' ), + 'ML' => __( "Mali", 'countries' ), + 'MM' => __( "Myanmar", 'countries' ), + 'MN' => __( "Mongolia", 'countries' ), + 'MO' => __( "Macau", 'countries' ), + 'MR' => __( "Mauritania", 'countries' ), + 'MT' => __( "Malta", 'countries' ), + 'MU' => __( "Mauritius", 'countries' ), + 'MV' => __( "Maldives", 'countries' ), + 'MW' => __( "Malawi", 'countries' ), + 'MX' => __( "Mexico", 'countries' ), + 'MY' => __( "Malaysia", 'countries' ), + 'MZ' => __( "Mozambique", 'countries' ), + 'NA' => __( "Namibia", 'countries' ), + 'NE' => __( "Niger", 'countries' ), + 'NG' => __( "Nigeria", 'countries' ), + 'NI' => __( "Nicaragua", 'countries' ), + 'NL' => __( "Netherlands", 'countries' ), + 'NO' => __( "Norway", 'countries' ), + 'NP' => __( "Nepal", 'countries' ), + 'NR' => __( "Nauru", 'countries' ), + 'NZ' => __( "New Zealand", 'countries' ), + 'OM' => __( "Oman", 'countries' ), + 'PA' => __( "Panama", 'countries' ), + 'PE' => __( "Peru", 'countries' ), + 'PG' => __( "Papua New Guinea", 'countries' ), + 'PH' => __( "Philippines", 'countries' ), + 'PK' => __( "Pakistan", 'countries' ), + 'PL' => __( "Poland", 'countries' ), + 'PT' => __( "Portugal", 'countries' ), + 'PW' => __( "Palau", 'countries' ), + 'PY' => __( "Paraguay", 'countries' ), + 'QA' => __( "Qatar", 'countries' ), + 'RO' => __( "Romania", 'countries' ), + 'RS' => __( "Serbia", 'countries' ), + 'RU' => __( "Russia", 'countries' ), + 'RW' => __( "Rwanda", 'countries' ), + 'SA' => __( "Saudi Arabia", 'countries' ), + 'SB' => __( "Solomon Islands", 'countries' ), + 'SC' => __( "Seychelles", 'countries' ), + 'SD' => __( "Sudan", 'countries' ), + 'SE' => __( "Sweden", 'countries' ), + 'SG' => __( "Singapore", 'countries' ), + 'SI' => __( "Slovenia", 'countries' ), + 'SK' => __( "Slovakia", 'countries' ), + 'SL' => __( "Sierra Leone", 'countries' ), + 'SM' => __( "San Marino", 'countries' ), + 'SN' => __( "Senegal", 'countries' ), + 'SO' => __( "Somalia", 'countries' ), + 'SR' => __( "Suriname", 'countries' ), + 'ST' => __( "Sao Tome and Principe", 'countries' ), + 'SV' => __( "El Salvador", 'countries' ), + 'SZ' => __( "Swaziland", 'countries' ), + 'TD' => __( "Chad", 'countries' ), + 'TG' => __( "Togo", 'countries' ), + 'TH' => __( "Thailand", 'countries' ), + 'TJ' => __( "Tajikistan", 'countries' ), + 'TL' => __( "East Timor", 'countries' ), + 'TM' => __( "Turkmenistan", 'countries' ), + 'TN' => __( "Tunisia", 'countries' ), + 'TO' => __( "Tonga", 'countries' ), + 'TR' => __( "Turkey", 'countries' ), + 'TT' => __( "Trinidad and Tobago", 'countries' ), + 'TV' => __( "Tuvalu", 'countries' ), + 'TW' => __( "Taiwan", 'countries' ), + 'TZ' => __( "Tanzania", 'countries' ), + 'UA' => __( "Ukraine", 'countries' ), + 'UG' => __( "Uganda", 'countries' ), + 'US' => __( "United States", 'countries' ), + 'UY' => __( "Uruguay", 'countries' ), + 'UZ' => __( "Uzbekistan", 'countries' ), + 'VA' => __( "Vatican City", 'countries' ), + 'VC' => __( "Saint Vincent and the Grenadines", 'countries' ), + 'VE' => __( "Venezuela", 'countries' ), + 'VN' => __( "Vietnam", 'countries' ), + 'VU' => __( "Vanuatu", 'countries' ), + 'WS' => __( "Samoa", 'countries' ), + 'YE' => __( "Yemen", 'countries' ), + 'ZA' => __( "South Africa", 'countries' ), + 'ZM' => __( "Zambia", 'countries' ), + 'ZW' => __( "Zimbabwe", 'countries' ), ); asort( $sportspress_countries ); diff --git a/admin/hooks/admin-menu.php b/admin/hooks/admin-menu.php index 140b9ce3..b6d11426 100644 --- a/admin/hooks/admin-menu.php +++ b/admin/hooks/admin-menu.php @@ -24,11 +24,17 @@ function sportspress_admin_menu( $position ) { $menu[ $position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' ); endif; - // Remove "Seasons" link from Players submenu + // Remove "Leagues" link from Players submenu unset( $submenu['edit.php?post_type=sp_player'][15] ); - // Remove "Seasons" link from Staff submenu + // Remove "Seasons" link from Players submenu + unset( $submenu['edit.php?post_type=sp_player'][16] ); + + // Remove "Leagues" link from Staff submenu unset( $submenu['edit.php?post_type=sp_staff'][15] ); + // Remove "Seasons" link from Staff submenu + unset( $submenu['edit.php?post_type=sp_staff'][16] ); + } -add_action( 'admin_menu', 'sportspress_admin_menu' ); \ No newline at end of file +add_action( 'admin_menu', 'sportspress_admin_menu' ); diff --git a/admin/hooks/manage-posts-custom-column.php b/admin/hooks/manage-posts-custom-column.php index 53eb15e3..129c8e84 100644 --- a/admin/hooks/manage-posts-custom-column.php +++ b/admin/hooks/manage-posts-custom-column.php @@ -69,6 +69,9 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) { case 'sp_event': echo get_post_meta ( $post_id, 'sp_event' ) ? sizeof( get_post_meta ( $post_id, 'sp_event' ) ) : '—'; break; + case 'sp_league': + echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '—'; + break; case 'sp_season': echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '—'; break; diff --git a/admin/hooks/save-post.php b/admin/hooks/save-post.php index 65dd59c8..63485ca6 100644 --- a/admin/hooks/save-post.php +++ b/admin/hooks/save-post.php @@ -32,6 +32,9 @@ function sportspress_save_post( $post_id ) { // Update staff array sportspress_update_post_meta_recursive( $post_id, 'sp_staff', sportspress_array_value( $_POST, 'sp_staff', array() ) ); + // Update league taxonomy + wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_league', 0 ), 'sp_league' ); + // Update season taxonomy wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' ); @@ -113,6 +116,9 @@ function sportspress_save_post( $post_id ) { // Update teams array update_post_meta( $post_id, 'sp_teams', sportspress_array_value( $_POST, 'sp_teams', array() ) ); + // Update league taxonomy + wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_league', 0 ), 'sp_league' ); + // Update season taxonomy wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' ); @@ -129,6 +135,9 @@ function sportspress_save_post( $post_id ) { // Update team array update_post_meta( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) ); + // Update league taxonomy + wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_league', 0 ), 'sp_league' ); + // Update season taxonomy wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' ); diff --git a/admin/hooks/the-content.php b/admin/hooks/the-content.php index b4c3945c..b12e45f0 100644 --- a/admin/hooks/the-content.php +++ b/admin/hooks/the-content.php @@ -1,10 +1,30 @@ ID ) . $content; + + elseif ( is_singular( 'sp_calendar' ) && in_the_loop() ): + + global $post; + + // Display events calendar + $content = sportspress_events_calendar( $post->ID ) . $content; + + elseif ( is_singular( 'sp_team' ) && in_the_loop() ): + + global $post; + + // Display team columns + $content = sportspress_team_columns( $post->ID ) . $content; + elseif ( is_singular( 'sp_table' ) && in_the_loop() ): - global $post; + global $post; // Display league table $content = sportspress_league_table( $post->ID ) . $content; @@ -21,7 +41,7 @@ function sportspress_the_content( $content ) { global $post; - // Display player list + // Display player metrics and statistics $content = sportspress_player_metrics( $post->ID ) . sportspress_player_statistics( $post->ID ) . $content; endif; diff --git a/admin/post-types/calendar.php b/admin/post-types/calendar.php index d78a262f..eb313e05 100644 --- a/admin/post-types/calendar.php +++ b/admin/post-types/calendar.php @@ -24,8 +24,9 @@ function sportspress_calendar_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Title' ), - 'sp_team' => __( 'Teams', 'sportspress' ), + 'sp_league' => __( 'Leagues', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ), + 'sp_venue' => __( 'Venues', 'sportspress' ), ); return $columns; } diff --git a/admin/post-types/event.php b/admin/post-types/event.php index 28bd29ad..58cd7397 100644 --- a/admin/post-types/event.php +++ b/admin/post-types/event.php @@ -45,18 +45,33 @@ function sportspress_event_meta_init( $post ) { } function sportspress_event_details_meta( $post ) { + $league_id = sportspress_get_the_term_id( $post->ID, 'sp_league', 0 ); $season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 ); $venue_id = sportspress_get_the_term_id( $post->ID, 'sp_venue', 0 ); ?>
+

+

+ 'sp_league', + 'name' => 'sp_league', + 'selected' => $league_id, + 'value' => 'term_id', + 'show_option_none' => __( '-- Not set --', 'sportspress' ), + ); + sportspress_dropdown_taxonomies( $args ); + ?> +

-

+

'sp_season', 'name' => 'sp_season', 'selected' => $season_id, 'value' => 'term_id', + 'show_option_none' => __( '-- Not set --', 'sportspress' ), ); sportspress_dropdown_taxonomies( $args ); ?> @@ -69,6 +84,7 @@ function sportspress_event_details_meta( $post ) { 'name' => 'sp_venue', 'selected' => $venue_id, 'value' => 'term_id', + 'show_option_none' => __( '-- Not set --', 'sportspress' ), ); sportspress_dropdown_taxonomies( $args ); ?> @@ -79,7 +95,6 @@ function sportspress_event_details_meta( $post ) { function sportspress_event_team_meta( $post ) { $teams = (array)get_post_meta( $post->ID, 'sp_team', false ); - $players = (array)get_post_meta( $post->ID, 'sp_player', false ); foreach ( $teams as $key => $value ): ?>

@@ -177,8 +192,9 @@ function sportspress_event_edit_columns() { 'cb' => '', 'title' => __( 'Event', 'sportspress' ), 'sp_team' => __( 'Teams', 'sportspress' ), - 'sp_season' => __( 'Seasons', 'sportspress' ), - 'sp_venue' => __( 'Venues', 'sportspress' ), + 'sp_league' => __( 'League', 'sportspress' ), + 'sp_season' => __( 'Season', 'sportspress' ), + 'sp_venue' => __( 'Venue', 'sportspress' ), 'sp_kickoff' => __( 'Date/Time', 'sportspress' ) ); return $columns; diff --git a/admin/post-types/list.php b/admin/post-types/list.php index c57fb62f..4bedf9d0 100644 --- a/admin/post-types/list.php +++ b/admin/post-types/list.php @@ -25,8 +25,9 @@ function sportspress_list_edit_columns() { 'cb' => '', 'title' => __( 'Title' ), 'sp_player' => __( 'Players', 'sportspress' ), - 'sp_team' => __( 'Teams', 'sportspress' ), - 'sp_season' => __( 'Seasons', 'sportspress' ) + 'sp_league' => __( 'League', 'sportspress' ), + 'sp_season' => __( 'Season', 'sportspress' ), + 'sp_team' => __( 'Team', 'sportspress' ), ); return $columns; } @@ -44,10 +45,23 @@ function sportspress_list_meta_init( $post ) { } function sportspress_list_player_meta( $post ) { + $league_id = sportspress_get_the_term_id( $post->ID, 'sp_league', 0 ); $season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 ); $team_id = get_post_meta( $post->ID, 'sp_team', true ); ?>
+

+

+ 'sp_league', + 'name' => 'sp_league', + 'selected' => $league_id, + 'value' => 'term_id' + ); + sportspress_dropdown_taxonomies( $args ); + ?> +

__( 'Name', 'sportspress' ), 'sp_position' => __( 'Positions', 'sportspress' ), 'sp_team' => __( 'Teams', 'sportspress' ), + 'sp_league' => __( 'Leagues', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ), ); return $columns; @@ -32,12 +33,9 @@ function sportspress_player_edit_columns() { add_filter( 'manage_edit-sp_player_columns', 'sportspress_player_edit_columns' ); function sportspress_player_meta_init( $post ) { - $teams = (array)get_post_meta( $post->ID, 'sp_team', false ); + $leagues = get_the_terms( $post->ID, 'sp_league' ); $seasons = (array)get_the_terms( $post->ID, 'sp_season' ); - // First one is empty - unset( $teams[0] ); - remove_meta_box( 'submitdiv', 'sp_player', 'side' ); add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_player', 'side', 'high' ); remove_meta_box( 'postimagediv', 'sp_player', 'side' ); @@ -45,7 +43,7 @@ function sportspress_player_meta_init( $post ) { add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_player_details_meta', 'sp_player', 'side', 'high' ); add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_player_team_meta', 'sp_player', 'side', 'high' ); - if ( $teams && ! empty( $teams ) && $seasons && is_array( $seasons ) && is_object( $seasons[0] ) ): + if ( $leagues && ! empty( $leagues ) && $seasons && is_array( $seasons ) && is_object( $seasons[0] ) ): add_meta_box( 'sp_statsdiv', __( 'Player Statistics', 'sportspress' ), 'sportspress_player_stats_meta', 'sp_player', 'normal', 'high' ); endif; @@ -98,28 +96,22 @@ function sportspress_player_team_meta( $post ) { } function sportspress_player_stats_meta( $post ) { - $team_ids = (array)get_post_meta( $post->ID, 'sp_team', false ); + $leagues = get_the_terms( $post->ID, 'sp_league' ); - // First one is empty - unset( $team_ids[0] ); + $league_num = sizeof( $leagues ); - // Initialize placeholders array - $placeholders = array(); - - $team_num = sizeof( $team_ids ); - - // Loop through statistics for each team - foreach ( $team_ids as $team_id ): + // Loop through statistics for each league + foreach ( $leagues as $league ): - if ( $team_num > 1 ): + if ( $league_num > 1 ): ?> -

+

name; ?>

ID, $team_id, true ); + list( $columns, $data, $placeholders, $merged ) = sportspress_get_player_statistics_data( $post->ID, $league->term_id, true ); - sportspress_edit_player_statistics_table( $team_id, $columns, $data, $placeholders ); + sportspress_edit_player_statistics_table( $league->term_id, $columns, $data, $placeholders ); endforeach; } diff --git a/admin/post-types/staff.php b/admin/post-types/staff.php index fa369e94..f73d8f8d 100644 --- a/admin/post-types/staff.php +++ b/admin/post-types/staff.php @@ -43,6 +43,7 @@ function sportspress_staff_edit_columns() { 'title' => __( 'Name', 'sportspress' ), 'sp_position' => __( 'Positions', 'sportspress' ), 'sp_team' => __( 'Teams', 'sportspress' ), + 'sp_league' => __( 'Leagues', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ), ); return $columns; diff --git a/admin/post-types/table.php b/admin/post-types/table.php index 4c99a7da..f11d5aba 100644 --- a/admin/post-types/table.php +++ b/admin/post-types/table.php @@ -24,8 +24,9 @@ function sportspress_table_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Title' ), + 'sp_league' => __( 'League', 'sportspress' ), + 'sp_season' => __( 'Season', 'sportspress' ), 'sp_team' => __( 'Teams', 'sportspress' ), - 'sp_season' => __( 'Seasons', 'sportspress' ), ); return $columns; } @@ -43,20 +44,35 @@ function sportspress_table_meta_init( $post ) { } function sportspress_table_team_meta( $post, $test ) { - $league_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 ); + $league_id = sportspress_get_the_term_id( $post->ID, 'sp_league', 0 ); + $season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 ); ?>
-

+

+

'sp_season', - 'name' => 'sp_season', + 'taxonomy' => 'sp_league', + 'name' => 'sp_league', 'selected' => $league_id, 'value' => 'term_id' ); sportspress_dropdown_taxonomies( $args ); ?>

+

+

+ 'sp_season', + 'name' => 'sp_season', + 'selected' => $season_id, + 'value' => 'term_id' + ); + sportspress_dropdown_taxonomies( $args ); + ?> +

+

ID, 'sp_team', 'block', 'sp_season' ); sportspress_post_adder( 'sp_team' ); diff --git a/admin/post-types/team.php b/admin/post-types/team.php index c088eca9..873cbc1c 100644 --- a/admin/post-types/team.php +++ b/admin/post-types/team.php @@ -20,14 +20,15 @@ function sportspress_team_post_init() { add_action( 'init', 'sportspress_team_post_init' ); function sportspress_team_meta_init( $post ) { - $leagues = (array)get_the_terms( $post->ID, 'sp_season' ); + $leagues = (array)get_the_terms( $post->ID, 'sp_league' ); + $seasons = (array)get_the_terms( $post->ID, 'sp_season' ); remove_meta_box( 'submitdiv', 'sp_team', 'side' ); add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_team', 'side', 'high' ); remove_meta_box( 'postimagediv', 'sp_team', 'side' ); add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' ); - if ( $leagues && $leagues != array(0) ): + if ( $leagues && $leagues != array(0) && $seasons && $seasons != array(0) ): add_meta_box( 'sp_columnssdiv', __( 'Table Columns', 'sportspress' ), 'sportspress_team_columns_meta', 'sp_team', 'normal', 'high' ); endif; } @@ -37,165 +38,32 @@ function sportspress_team_edit_columns() { 'cb' => '', 'sp_logo' => ' ', 'title' => __( 'Team', 'sportspress' ), - 'sp_season' => __( 'Seasons', 'sportspress' ) + 'sp_league' => __( 'Leagues', 'sportspress' ), + 'sp_season' => __( 'Seasons', 'sportspress' ), ); return $columns; } add_filter( 'manage_edit-sp_team_columns', 'sportspress_team_edit_columns' ); function sportspress_team_columns_meta( $post ) { - $leagues = (array)get_the_terms( $post->ID, 'sp_season' ); - $columns = (array)get_post_meta( $post->ID, 'sp_columns', true ); + $leagues = (array)get_the_terms( $post->ID, 'sp_league' ); - // Equation Operating System - $eos = new eqEOS(); + $league_num = sizeof( $leagues ); - // Get labels from result variables - $result_labels = (array)sportspress_get_var_labels( 'sp_result' ); - - // Get labels from outcome variables - $outcome_labels = (array)sportspress_get_var_labels( 'sp_outcome' ); - - // Generate array of all league ids - $div_ids = array(); - foreach ( $leagues as $key => $value ): - if ( is_object( $value ) && property_exists( $value, 'term_id' ) ) - $div_ids[] = $value->term_id; - endforeach; - - // Get all leagues populated with columns where available - $data = sportspress_array_combine( $div_ids, $columns ); - - // Get equations from column variables - $equations = sportspress_get_var_equations( 'sp_column' ); - - // Initialize placeholders array - $placeholders = array(); - - foreach ( $div_ids as $div_id ): - - $totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last10' => null ); - - foreach ( $result_labels as $key => $value ): - $totals[ $key . 'for' ] = 0; - $totals[ $key . 'against' ] = 0; - endforeach; - - foreach ( $outcome_labels as $key => $value ): - $totals[ $key ] = 0; - endforeach; - - // Initialize streaks counter - $streak = array( 'name' => '', 'count' => 0, 'fire' => 1 ); - - // Initialize last 10 counter - $last10 = array(); - - // Add outcome types to last 10 counter - foreach( $outcome_labels as $key => $value ): - $last10[ $key ] = 0; - endforeach; - - // Get all events involving the team in current season - $args = array( - 'post_type' => 'sp_event', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'order' => 'ASC', - 'meta_query' => array( - array( - 'key' => 'sp_team', - 'value' => $post->ID - ) - ), - 'tax_query' => array( - array( - 'taxonomy' => 'sp_season', - 'field' => 'id', - 'terms' => $div_id - ) - ) - ); - $events = get_posts( $args ); - - foreach( $events as $event ): - $results = (array)get_post_meta( $event->ID, 'sp_results', true ); - foreach ( $results as $team_id => $team_result ): - foreach ( $team_result as $key => $value ): - if ( $team_id == $post->ID ): - if ( $key == 'outcome' ): - - // Increment events played and outcome count - if ( array_key_exists( $value, $totals ) ): - $totals['eventsplayed']++; - $totals[ $value ]++; - endif; - - if ( $value && $value != '-1' ): - - // Add to streak counter - if ( $streak['fire'] && ( $streak['name'] == '' || $streak['name'] == $value ) ): - $streak['name'] = $value; - $streak['count'] ++; - else: - $streak['fire'] = 0; - endif; - - // Add to last 10 counter if sum is less than 10 - if ( array_key_exists( $value, $last10 ) && array_sum( $last10 ) < 10 ): - $last10[ $value ] ++; - endif; - - endif; - - else: - if ( array_key_exists( $key . 'for', $totals ) ): - $totals[ $key . 'for' ] += $value; - endif; - endif; - else: - if ( $key != 'outcome' ): - if ( array_key_exists( $key . 'against', $totals ) ): - $totals[ $key . 'against' ] += $value; - endif; - endif; - endif; - endforeach; - endforeach; - endforeach; - - // Compile streaks counter and add to totals - $args=array( - 'name' => $streak['name'], - 'post_type' => 'sp_outcome', - 'post_status' => 'publish', - 'posts_per_page' => 1 - ); - $outcomes = get_posts( $args ); - - if ( $outcomes ): - $outcome = $outcomes[0]; - $totals['streak'] = $outcome->post_title . $streak['count']; + // Loop through statistics for each league + foreach ( $leagues as $league ): + + if ( $league_num > 1 ): + ?> +

name; ?>

+ ID, $league->term_id, true ); - // Generate array of placeholder values for each league - $placeholders[ $div_id ] = array(); - foreach ( $equations as $key => $value ): - if ( $totals['eventsplayed'] > 0 ): - $placeholders[ $div_id ][ $key ] = sportspress_solve( $value, $totals ); - else: - $placeholders[ $div_id ][ $key ] = 0; - endif; - endforeach; + sportspress_edit_team_columns_table( $columns, $data, $placeholders ); endforeach; - // Get columns from statistics variables - $columns = sportspress_get_var_labels( 'sp_column' ); - - sportspress_edit_team_columns_table( $columns, $data, $placeholders ); sportspress_nonce(); } diff --git a/admin/terms/league.php b/admin/terms/league.php new file mode 100644 index 00000000..7bfa1659 --- /dev/null +++ b/admin/terms/league.php @@ -0,0 +1,21 @@ + $name, + 'labels' => $labels, + 'public' => true, + 'hierarchical' => true, + 'rewrite' => array( 'slug' => 'league' ) + ); + register_taxonomy( 'sp_league', $object_type, $args ); + register_taxonomy_for_object_type( 'sp_league', 'sp_calendar' ); + register_taxonomy_for_object_type( 'sp_league', 'sp_team' ); + register_taxonomy_for_object_type( 'sp_league', 'sp_player' ); + register_taxonomy_for_object_type( 'sp_league', 'sp_staff' ); +} +add_action( 'init', 'sportspress_league_term_init' ); diff --git a/functions.php b/functions.php index e10e9fe7..fb594e52 100644 --- a/functions.php +++ b/functions.php @@ -1,4 +1,153 @@ $team_id ): + if ( ! $team_id ) continue; + + // Get results for players in the team + $players = sportspress_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key ); + $data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) ); + + $output .= '

' . get_the_title( $team_id ) . '

'; + + $output .= '
name; ?> + 'sp_team', + 'name' => 'sp_statistics[' . $league_id . '][' . $div_id . '][team]', + 'show_option_none' => __( '-- Select --', 'sportspress' ), + 'sort_order' => 'ASC', + 'sort_column' => 'menu_order', + 'selected' => $value, + 'values' => 'ID', + ); + sportspress_dropdown_pages( $args ); + ?> +
' . '' . ''; + + $output .= ''; + $output .= ''; + + foreach( $statistic_labels as $key => $label ): + $output .= ''; + endforeach; + + $output .= '' . '' . ''; + + $i = 0; + + foreach( $data as $player_id => $row ): + + if ( ! $player_id ) + continue; + + $output .= ''; + + $number = get_post_meta( $player_id, 'sp_number', true ); + + // Player number + $output .= ''; + + // Name as link + $permalink = get_post_permalink( $player_id ); + $name = get_the_title( $player_id ); + $output .= ''; + + foreach( $statistic_labels as $key => $label ): + if ( $key == 'name' ) + continue; + if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): + $value = $row[ $key ]; + else: + $value = 0; + endif; + $output .= ''; + endforeach; + + $output .= ''; + + $i++; + + endforeach; + + $output .= ''; + + if ( array_key_exists( 0, $data ) ): + + $output .= ''; + + $number = get_post_meta( $player_id, 'sp_number', true ); + + // Player number + $output .= ''; + $output .= ''; + + $row = $data[0]; + + foreach( $statistic_labels as $key => $label ): + if ( $key == 'name' ): + continue; + endif; + $output .= ''; + endforeach; + + $output .= ''; + + endif; + + $output .= '
' . __( '#', 'sportspress' ) . '' . __( 'Player', 'sportspress' ) . '' . $label . '
' . $number . '' . '' . $name . '' . $value . '
 ' . __( 'Total', 'sportspress' ) . '' . sportspress_array_value( $row, $key, '—' ) . '
'; + + endforeach; + + // Initialize and check + $table_rows = ''; + + $i = 0; + + foreach( $results as $team_id => $result ): + if ( sportspress_array_value( $result, 'outcome', '-1' ) != '-1' ): + + unset( $result['outcome'] ); + + $table_rows .= ''; + + $table_rows .= '' . get_the_title( $team_id ) . ''; + + foreach( $result_labels as $key => $label ): + if ( $key == 'name' ) + continue; + if ( array_key_exists( $key, $result ) && $result[ $key ] != '' ): + $value = $result[ $key ]; + else: + $value = '—'; + endif; + $table_rows .= '' . $value . ''; + endforeach; + + $table_rows .= ''; + + $i++; + + endif; + endforeach; + + if ( ! empty( $table_rows ) ): + + $output .= '

' . __( 'Results', 'sportspress' ) . '

'; + + $output .= ''; + $output .= ''; + foreach( $result_labels as $key => $label ): + $output .= ''; + endforeach; + $output .= '' . '' . ''; + $output .= $table_rows; + $output .= '
' . __( 'Team', 'sportspress' ) . '' . $label . '
'; + + endif; + + return $output; + + } +} + if ( !function_exists( 'sportspress_league_table' ) ) { function sportspress_league_table( $id ) { @@ -23,7 +172,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) { foreach( $data as $team_id => $row ): - $output .= ''; + $output .= ''; // Position as number $output .= '' . $i . ''; @@ -53,6 +202,62 @@ if ( !function_exists( 'sportspress_league_table' ) ) { } } + +if ( !function_exists( 'sportspress_team_columns' ) ) { + function sportspress_team_columns( $id ) { + + $leagues = get_the_terms( $id, 'sp_league' ); + + $output = ''; + + // Loop through data for each league + foreach ( $leagues as $league ): + + if ( sizeof( $leagues ) > 1 ) + $output .= '

' . $league->name . '

'; + + $data = sportspress_get_team_columns_data( $id, $league->term_id ); + + // 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 .= '' . '' . ''; + + foreach( $labels as $key => $label ): + $output .= ''; + endforeach; + + $output .= '' . '' . ''; + + $i = 0; + + foreach( $data as $season_id => $row ): + + $output .= ''; + + foreach( $labels as $key => $value ): + $output .= ''; + endforeach; + + $output .= ''; + + $i++; + + endforeach; + + $output .= '' . '
' . $label . '
' . sportspress_array_value( $row, $key, '—' ) . '
'; + + + endforeach; + + return $output; + + } +} + if ( !function_exists( 'sportspress_player_list' ) ) { function sportspress_player_list( $id ) { @@ -77,7 +282,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) { foreach( $data as $player_id => $row ): - $output .= ''; + $output .= ''; // Player number $number = get_post_meta( $player_id, 'sp_number', true ); @@ -131,7 +336,7 @@ if ( !function_exists( 'sportspress_player_metrics' ) ) { foreach( $data as $label => $value ): - $output .= '' . $label . '' . $value . ''; + $output .= '' . $label . '' . $value . ''; $i++; @@ -148,20 +353,17 @@ if ( !function_exists( 'sportspress_player_metrics' ) ) { if ( !function_exists( 'sportspress_player_statistics' ) ) { function sportspress_player_statistics( $id ) { - $team_ids = (array)get_post_meta( $id, 'sp_team', false ); - - // First one is empty - unset( $team_ids[0] ); + $leagues = get_the_terms( $id, 'sp_league' ); $output = ''; - // Loop through statistics for each team - foreach ( $team_ids as $team_id ): + // Loop through statistics for each league + foreach ( $leagues as $league ): - if ( sizeof( $team_ids ) > 1 ) - $output .= '

' . get_the_title( $team_id ) . '

'; + if ( sizeof( $leagues ) > 1 ) + $output .= '

' . $league->name . '

'; - $data = sportspress_get_player_statistics_data( $id, $team_id ); + $data = sportspress_get_player_statistics_data( $id, $league->term_id ); // The first row should be column labels $labels = $data[0]; @@ -181,7 +383,7 @@ if ( !function_exists( 'sportspress_player_statistics' ) ) { foreach( $data as $season_id => $row ): - $output .= ''; + $output .= ''; foreach( $labels as $key => $value ): $output .= '' . sportspress_array_value( $row, $key, '—' ) . ''; diff --git a/sportspress.php b/sportspress.php index 49dda786..52473d19 100644 --- a/sportspress.php +++ b/sportspress.php @@ -54,6 +54,7 @@ require_once dirname( __FILE__ ) . '/admin/post-types/list.php'; require_once dirname( __FILE__ ) . '/admin/post-types/staff.php'; // Terms +require_once dirname( __FILE__ ) . '/admin/terms/league.php'; require_once dirname( __FILE__ ) . '/admin/terms/season.php'; require_once dirname( __FILE__ ) . '/admin/terms/venue.php'; require_once dirname( __FILE__ ) . '/admin/terms/position.php';