Give teams option to show and hide seasons
This commit is contained in:
@@ -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() ) {
|
||||
?>
|
||||
<div class="sp-data-table-container">
|
||||
<table class="widefat sp-data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="check-column"><input class="sp-select-all" type="checkbox"></th>
|
||||
<th><?php _e( 'Season', 'sportspress' ); ?></th>
|
||||
<?php foreach ( $columns as $label ): ?>
|
||||
<th><?php echo $label; ?></th>
|
||||
@@ -643,32 +644,26 @@ if ( !function_exists( 'sportspress_edit_team_columns_table' ) ) {
|
||||
<tbody>
|
||||
<?php
|
||||
$i = 0;
|
||||
if ( empty( $data ) ):
|
||||
foreach ( $data as $div_id => $div_stats ):
|
||||
if ( !$div_id ) continue;
|
||||
$div = get_term( $div_id, 'sp_season' );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td><strong><?php printf( __( 'Select %s', 'sportspress' ), __( 'Season', 'sportspress' ) ); ?></strong></td>
|
||||
</tr>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<input type="checkbox" name="sp_leagues_seasons[<?php echo $league_id; ?>][<?php echo $div_id; ?>]" id="sp_leagues_seasons_<?php echo $league_id; ?>_<?php echo $div_id; ?>" value="1" <?php checked( sportspress_array_value( $seasons, $div_id, 0 ), 1 ); ?>>
|
||||
</td>
|
||||
<td>
|
||||
<label for="sp_leagues_seasons_<?php echo $league_id; ?>_<?php echo $div_id; ?>"><?php echo $div->name; ?></label>
|
||||
</td>
|
||||
<?php foreach( $columns as $column => $label ):
|
||||
$value = sportspress_array_value( sportspress_array_value( $data, $div_id, array() ), $column, 0 );
|
||||
?>
|
||||
<td><?php echo $value; ?></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<?php
|
||||
else:
|
||||
foreach ( $data as $div_id => $div_stats ):
|
||||
if ( !$div_id ) continue;
|
||||
$div = get_term( $div_id, 'sp_season' );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php echo $div->name; ?>
|
||||
</td>
|
||||
<?php foreach( $columns as $column => $label ):
|
||||
$value = sportspress_array_value( $div_stats, $column, '' );
|
||||
$placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $div_id, array() ), $column, 0 );
|
||||
?>
|
||||
<td><input type="text" name="sp_columns[<?php echo $div_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
endif;
|
||||
$i++;
|
||||
endforeach;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -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' );
|
||||
|
||||
|
||||
@@ -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() ) );
|
||||
|
||||
|
||||
@@ -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 ) {
|
||||
<?php
|
||||
endif;
|
||||
|
||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_team_columns_data( $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;
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 .= '<h4 class="sp-team-league-name">' . $league->name . '</h4>';
|
||||
|
||||
$data = sportspress_get_team_columns_data( $id, $league->term_id );
|
||||
|
||||
// The first row should be column labels
|
||||
$labels = $data[0];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user