From e3a04bc8c94dbd1d1cabda07cd68cefaf6ff69fd Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 15 Jan 2014 14:55:30 +1100 Subject: [PATCH] Give teams option to show and hide seasons --- admin-functions.php | 60 ++++++++++++++++----------------------- admin/hooks/save-post.php | 7 ++--- admin/post-types/team.php | 6 ++-- assets/js/admin.js | 21 ++++++++++++++ functions.php | 7 +++-- 5 files changed, 56 insertions(+), 45 deletions(-) diff --git a/admin-functions.php b/admin-functions.php index 92d98071..69aa86ff 100644 --- a/admin-functions.php +++ b/admin-functions.php @@ -628,12 +628,13 @@ if ( !function_exists( 'sportspress_edit_player_list_table' ) ) { } if ( !function_exists( 'sportspress_edit_team_columns_table' ) ) { - function sportspress_edit_team_columns_table( $columns = array(), $data = array(), $placeholders = array() ) { + function sportspress_edit_team_columns_table( $league_id, $columns = array(), $data = array(), $seasons = array() ) { ?>
+ @@ -643,32 +644,26 @@ if ( !function_exists( 'sportspress_edit_team_columns_table' ) ) { $div_stats ): + if ( !$div_id ) continue; + $div = get_term( $div_id, 'sp_season' ); ?> - - - + + + + $label ): + $value = sportspress_array_value( sportspress_array_value( $data, $div_id, array() ), $column, 0 ); + ?> + + + $div_stats ): - if ( !$div_id ) continue; - $div = get_term( $div_id, 'sp_season' ); - ?> - - - $label ): - $value = sportspress_array_value( $div_stats, $column, '' ); - $placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $div_id, array() ), $column, 0 ); - ?> - - - -
+ > + + +
- name; ?> -
@@ -1114,9 +1109,7 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) { $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(); + $leagues_seasons = sportspress_array_value( (array)get_post_meta( $post_id, 'sp_leagues_seasons', true ), $league_id, array() ); // Get labels from result variables $result_labels = (array)sportspress_get_var_labels( 'sp_result' ); @@ -1135,7 +1128,7 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) { endforeach; // Get all leagues populated with columns where available - $data = sportspress_array_combine( $div_ids, $columns ); + $data = $div_ids; // Get equations from column variables $equations = sportspress_get_var_equations( 'sp_column' ); @@ -1278,9 +1271,7 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) { foreach( $placeholders as $season_id => $season_data ): - $include = sportspress_array_value( sportspress_array_value( $data, $season_id, array() ), 'include', 0 ); - - if ( ! $include && false ) #todo + if ( ! sportspress_array_value( $leagues_seasons, $season_id, 0 ) ) continue; $season_name = sportspress_array_value( $season_names, $season_id, ' ' ); @@ -1304,7 +1295,7 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) { endforeach; if ( $breakdown ): - return array( $columns, $data, $placeholders, $merged ); + return array( $columns, $placeholders, $merged, $leagues_seasons ); else: $labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ) ), $columns ); $merged[0] = $labels; @@ -1596,9 +1587,6 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) { $player_ids = (array)get_post_meta( $post_id, 'sp_player', false ); $stats = (array)get_post_meta( $post_id, 'sp_players', true ); - // Equation Operating System - $eos = new eqEOS(); - // Get labels from result variables $columns = (array)sportspress_get_var_labels( 'sp_statistic' ); diff --git a/admin/hooks/save-post.php b/admin/hooks/save-post.php index 63485ca6..e920dff9 100644 --- a/admin/hooks/save-post.php +++ b/admin/hooks/save-post.php @@ -7,8 +7,8 @@ function sportspress_save_post( $post_id ) { switch ( $_POST['post_type'] ): case ( 'sp_team' ): - // Update columns - update_post_meta( $post_id, 'sp_columns', sportspress_array_value( $_POST, 'sp_columns', array() ) ); + // Update leagues seasons to show + update_post_meta( $post_id, 'sp_leagues_seasons', sportspress_array_value( $_POST, 'sp_leagues_seasons', array() ) ); break; @@ -87,9 +87,6 @@ function sportspress_save_post( $post_id ) { case ( 'sp_player' ): - // Update player statistics - update_post_meta( $post_id, 'sp_statistics', sportspress_array_value( $_POST, 'sp_statistics', array() ) ); - // Update team array sportspress_update_post_meta_recursive( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) ); diff --git a/admin/post-types/team.php b/admin/post-types/team.php index 873cbc1c..7a62b6fd 100644 --- a/admin/post-types/team.php +++ b/admin/post-types/team.php @@ -52,6 +52,8 @@ function sportspress_team_columns_meta( $post ) { // Loop through statistics for each league foreach ( $leagues as $league ): + + $league_id = $league->term_id; if ( $league_num > 1 ): ?> @@ -59,9 +61,9 @@ function sportspress_team_columns_meta( $post ) { ID, $league->term_id, true ); + list( $columns, $data, $data, $leagues_seasons ) = sportspress_get_team_columns_data( $post->ID, $league_id, true ); - sportspress_edit_team_columns_table( $columns, $data, $placeholders ); + sportspress_edit_team_columns_table( $league_id, $columns, $data, $leagues_seasons ); endforeach; diff --git a/assets/js/admin.js b/assets/js/admin.js index 5e06571f..87e6fbdc 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -72,6 +72,27 @@ jQuery(document).ready(function($){ }); } + // Select all checkboxes + $(".sp-data-table thead .sp-select-all").change(function() { + $table = $(this).closest(".sp-data-table"); + $table.find("tbody input[type=checkbox]").prop("checked", $(this).prop("checked")); + }); + + // Check if all checkboxes are checked already + $(".sp-data-table").on("checkCheck", function() { + $(this).each(function() { + $(this).find("thead .sp-select-all").prop("checked", $(this).find("tbody input[type=checkbox]:checked").length == $(this).find("tbody input[type=checkbox]").length); + }); + }); + + // Activate check check when a checkbox is checked + $(".sp-data-table tbody input[type=checkbox]").change(function() { + $(this).closest(".sp-data-table").trigger("checkCheck"); + }); + + // Trigger check check + $(".sp-data-table").trigger("checkCheck"); + // Equation selector $(".sp-equation-selector select:last").change(function() { $(this).siblings().change(function() { diff --git a/functions.php b/functions.php index fb594e52..631f2d9c 100644 --- a/functions.php +++ b/functions.php @@ -213,11 +213,14 @@ if ( !function_exists( 'sportspress_team_columns' ) ) { // Loop through data for each league foreach ( $leagues as $league ): + $data = sportspress_get_team_columns_data( $id, $league->term_id ); + + if ( sizeof( $data ) <= 1 ) + continue; + 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];