Improve stats table filters
This commit is contained in:
@@ -84,7 +84,7 @@ function sp_event_stats_meta( $post ) {
|
|||||||
?>
|
?>
|
||||||
<div>
|
<div>
|
||||||
<p><strong><?php echo $value ? get_the_title( $value ) : sprintf( __( 'Select %s' ), 'Team' ); ?></strong></p>
|
<p><strong><?php echo $value ? get_the_title( $value ) : sprintf( __( 'Select %s' ), 'Team' ); ?></strong></p>
|
||||||
<?php sp_stats_table( $data, array(), $value, array( 'Player', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), true, false ); ?>
|
<?php sp_stats_table( $data, array(), $value, array( 'Player', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), true ); ?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ $sportspress_texts = array(
|
|||||||
'Scheduled for: <b>%1$s</b>' => __( 'Joined', 'sportspress' ) . ': <b>%1$s</b>',
|
'Scheduled for: <b>%1$s</b>' => __( 'Joined', 'sportspress' ) . ': <b>%1$s</b>',
|
||||||
'Published on: <b>%1$s</b>' => __( 'Joined', 'sportspress' ) . ': <b>%1$s</b>',
|
'Published on: <b>%1$s</b>' => __( 'Joined', 'sportspress' ) . ': <b>%1$s</b>',
|
||||||
'Publish <b>immediately</b>' => __( 'Joined', 'sportspress' ) . ': <b>%1$s</b>'
|
'Publish <b>immediately</b>' => __( 'Joined', 'sportspress' ) . ': <b>%1$s</b>'
|
||||||
|
),
|
||||||
|
'sp_table' => array(
|
||||||
|
'Enter title here' => ''
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
49
helpers.php
49
helpers.php
@@ -115,7 +115,7 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
|
|||||||
printf( '<option value="-1">%s</option>', $args['show_option_none'] );
|
printf( '<option value="-1">%s</option>', $args['show_option_none'] );
|
||||||
}
|
}
|
||||||
foreach ( $terms as $term ) {
|
foreach ( $terms as $term ) {
|
||||||
printf( '<option value="%s" %s>%s</option>', $term->slug, selected( true, $args['selected'] == $term->slug ), $term->name );
|
printf( '<option value="%s" %s>%s</option>', $term->term_id, selected( true, $args['selected'] == $term->term_id, false ), $term->name );
|
||||||
}
|
}
|
||||||
print( '</select>' );
|
print( '</select>' );
|
||||||
}
|
}
|
||||||
@@ -179,8 +179,14 @@ if ( !function_exists( 'sp_post_checklist' ) ) {
|
|||||||
$posts = get_posts( array( 'post_type' => $meta, 'numberposts' => 0 ) );
|
$posts = get_posts( array( 'post_type' => $meta, 'numberposts' => 0 ) );
|
||||||
foreach ( $posts as $post ):
|
foreach ( $posts as $post ):
|
||||||
$parents = get_post_ancestors( $post );
|
$parents = get_post_ancestors( $post );
|
||||||
if ( $filter )
|
if ( $filter ):
|
||||||
$filter_values = (array)get_post_meta( $post->ID, $filter, false )
|
$filter_values = (array)get_post_meta( $post->ID, $filter, false );
|
||||||
|
$terms = (array)get_the_terms( $post->ID, 'sp_league' );
|
||||||
|
foreach ( $terms as $term ):
|
||||||
|
if ( is_object( $term ) && property_exists( $term, 'term_id' ) )
|
||||||
|
$filter_values[] = $term->term_id;
|
||||||
|
endforeach;
|
||||||
|
endif;
|
||||||
?>
|
?>
|
||||||
<li class="sp-post<?php
|
<li class="sp-post<?php
|
||||||
if ( $filter ):
|
if ( $filter ):
|
||||||
@@ -221,20 +227,17 @@ if ( !function_exists( 'sp_get_stats' ) ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sp_stats_table' ) ) {
|
if ( !function_exists( 'sp_stats_table' ) ) {
|
||||||
function sp_stats_table( $stats = array(), $placeholders = array(), $index = 0, $columns = array( 'Name' ), $total = true, $auto = true, $rowtype = 'post', $slug = 'sp_stats' ) {
|
function sp_stats_table( $stats = array(), $placeholders = array(), $index = 0, $columns = array( 'Name' ), $total = true, $rowtype = 'post', $slug = 'sp_stats' ) {
|
||||||
global $pagenow;
|
global $pagenow;
|
||||||
if ( !is_array( $stats ) )
|
if ( !is_array( $stats ) )
|
||||||
$stats = array();
|
$stats = array();
|
||||||
?>
|
?>
|
||||||
<table class="widefat sp-data-table">
|
<table class="widefat sp-stats-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<?php foreach ( $columns as $column ): ?>
|
<?php foreach ( $columns as $column ): ?>
|
||||||
<th><?php echo $column; ?></th>
|
<th><?php echo $column; ?></th>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if ( $auto ): ?>
|
|
||||||
<th><?php _e( 'Auto', 'sportspress' ); ?></th>
|
|
||||||
<?php endif; ?>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -242,9 +245,8 @@ if ( !function_exists( 'sp_stats_table' ) ) {
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ( $stats as $key => $values ):
|
foreach ( $stats as $key => $values ):
|
||||||
if ( !$key ) continue;
|
if ( !$key ) continue;
|
||||||
$is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : $pagenow == 'post-new.php';
|
|
||||||
?>
|
?>
|
||||||
<tr class="sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||||
<td>
|
<td>
|
||||||
<?php
|
<?php
|
||||||
switch( $rowtype ):
|
switch( $rowtype ):
|
||||||
@@ -262,41 +264,26 @@ if ( !function_exists( 'sp_stats_table' ) ) {
|
|||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $j ++ ):
|
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $j ++ ):
|
||||||
$value = (int)sp_array_value( $values, $j, 0 );
|
$value = sp_array_value( $values, $j, '' );
|
||||||
$placeholder = (int)sp_array_value( sp_array_value( $placeholders, $key, 0), $j, 0 );
|
$placeholder = (int)sp_array_value( sp_array_value( $placeholders, $key, 0), $j, 0 );
|
||||||
?>
|
?>
|
||||||
<td><input type="text" name="sportspress[<?php echo $slug; ?>][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /><?php echo $placeholder; ?></td>
|
<td><input type="text" name="sportspress[<?php echo $slug; ?>][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
<?php if ( $auto ): ?>
|
|
||||||
<td><input type="checkbox" name="sportspress[<?php echo $slug; ?>][<?php echo $index; ?>][<?php echo $key; ?>][auto]" value="1"<?php if ( $is_auto ) echo ' checked="checked"'; ?> /></td>
|
|
||||||
<?php endif; ?>
|
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
$i++;
|
$i++;
|
||||||
endforeach;
|
endforeach;
|
||||||
if ( $total ):
|
if ( $total ):
|
||||||
$values = array_key_exists( 0, $stats ) ? $stats[0] : array();
|
$values = array_key_exists( 0, $stats ) ? $stats[0] : array();
|
||||||
if ( $auto )
|
|
||||||
$is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : $pagenow == 'post-new.php';
|
|
||||||
else
|
|
||||||
$is_auto = $i;
|
|
||||||
?>
|
?>
|
||||||
<tr<?php
|
<tr class="sp-row sp-total<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||||
if ( $i % 2 == 0 )
|
|
||||||
echo ' class="alternate"';
|
|
||||||
?>>
|
|
||||||
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
|
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
|
||||||
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $j ++ ):
|
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $j ++ ):
|
||||||
if ( array_key_exists( $j, $values ) )
|
$value = sp_array_value( $values, $j, '' );
|
||||||
$value = (int)$values[ $j ];
|
$placeholder = 0;
|
||||||
else
|
|
||||||
$value = 0;
|
|
||||||
?>
|
?>
|
||||||
<td><input type="text" name="sportspress[<?php echo $slug; ?>][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>" /></td>
|
<td><input type="text" name="sportspress[<?php echo $slug; ?>][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
<?php if ( $auto ): ?>
|
|
||||||
<td><input type="checkbox" name="sportspress[<?php echo $slug; ?>][<?php echo $index; ?>][0][auto]" value="1"<?php if ( $is_auto ) echo ' checked="checked"'; ?> /></td>
|
|
||||||
<?php endif; ?>
|
|
||||||
</tr>
|
</tr>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
function sp_league_tax_init() {
|
function sp_league_tax_init() {
|
||||||
$name = __( 'Leagues', 'sportspress' );
|
$name = __( 'Leagues', 'sportspress' );
|
||||||
$singular_name = __( 'League', 'sportspress' );
|
$singular_name = __( 'League', 'sportspress' );
|
||||||
$object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' );
|
$object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_list' );
|
||||||
$labels = sp_tax_labels( $name, $singular_name );
|
$labels = sp_tax_labels( $name, $singular_name );
|
||||||
$args = array(
|
$args = array(
|
||||||
'label' => $name,
|
'label' => $name,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
jQuery(document).ready(function($){
|
jQuery(document).ready(function($){
|
||||||
|
|
||||||
// Switch tabs
|
// Tab switcher
|
||||||
$('.sp-tab-panel').siblings('.sp-tab-bar').find('a').click(function() {
|
$('.sp-tab-panel').siblings('.sp-tab-bar').find('a').click(function() {
|
||||||
$(this).closest('li').removeClass('wp-tab').addClass('wp-tab-active').siblings().removeClass('wp-tab-active').addClass('wp-tab').closest('.wp-tab-bar').siblings($(this).attr('href')).show().siblings('.wp-tab-panel').hide();
|
$(this).closest('li').removeClass('wp-tab').addClass('wp-tab-active').siblings().removeClass('wp-tab-active').addClass('wp-tab').closest('.wp-tab-bar').siblings($(this).attr('href')).show().siblings('.wp-tab-panel').hide();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Filter tabs
|
// Tab filter
|
||||||
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change(function() {
|
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change(function() {
|
||||||
var val = $(this).val();
|
var val = $(this).val();
|
||||||
$(this).closest('.sp-tab-select').siblings('.sp-tab-panel').find('.sp-post').hide(0, function() {
|
$(this).closest('.sp-tab-select').siblings('.sp-tab-panel').find('.sp-post').hide(0, function() {
|
||||||
@@ -17,37 +17,44 @@ jQuery(document).ready(function($){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Activate tab filters
|
// Trigger tab filter
|
||||||
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change();
|
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change();
|
||||||
|
|
||||||
// Data table checkboxes
|
// Title changer
|
||||||
$('.sp-data-table tr input[type=checkbox]').change(function() {
|
$('input[name=post_title]').on('updateTitle', function() {
|
||||||
$el = $(this).closest('tr').find('input[type=text], input[type=number]');
|
|
||||||
$el.prop('readonly', $(this).prop('checked'));
|
|
||||||
if($(this).prop('checked')) {
|
|
||||||
$el.each(function() {
|
|
||||||
$(this).val($(this).attr('placeholder'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Uncheck auto to edit
|
|
||||||
$('.sp-data-table tr input[type=text], .sp-data-table tr input[type=text]').click(function() {
|
|
||||||
$el = $(this).closest('tr').find('input[type=checkbox]');
|
|
||||||
if($el.size()) {
|
|
||||||
$el.prop('checked', false).change();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Activate checkboxes
|
|
||||||
$('.sp-data-table tr input[type=checkbox]').change();
|
|
||||||
|
|
||||||
// Change title
|
|
||||||
$('.sp-title-generator select').change(function() {
|
|
||||||
title = $('.sp-title-generator select[value!=0]').map(function(){
|
title = $('.sp-title-generator select[value!=0]').map(function(){
|
||||||
return $(this).find(':selected').html().replace(/&[^;]+;/g, '');
|
return $(this).find(':selected').html().replace(/&[^;]+;/g, '');
|
||||||
}).get().join(' vs ');
|
}).get().join(' vs ');
|
||||||
$('input[name=post_title]').val(title);
|
$(this).val(title);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Activate title changer
|
||||||
|
$('.sp-title-generator select').change(function() {
|
||||||
|
$('input[name=post_title]').trigger('updateTitle');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Total stats calculator
|
||||||
|
$('.sp-stats-table').on('updateTotals', function() {
|
||||||
|
$self = $(this);
|
||||||
|
$self.find('.sp-total input').each(function(i) {
|
||||||
|
var sum = 0;
|
||||||
|
$self.find('.sp-post').each(function() {
|
||||||
|
$el = $($(this).find('input')[i]);
|
||||||
|
if($el.val() != '')
|
||||||
|
if($.isNumeric($el.val())) sum += parseInt($el.val(), 10);
|
||||||
|
else
|
||||||
|
sum += parseInt($el.attr('placeholder'), 10);
|
||||||
|
});
|
||||||
|
$(this).attr('placeholder', sum);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Activate total stats calculator
|
||||||
|
$('.sp-stats-table .sp-post input').on('keyup', function() {
|
||||||
|
$(this).closest('.sp-stats-table').trigger('updateTotals');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Trigger total stats calculator
|
||||||
|
$('.sp-stats-table').trigger('updateTotals');
|
||||||
|
|
||||||
});
|
});
|
||||||
43
table.php
43
table.php
@@ -35,29 +35,38 @@ function sp_table_meta_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sp_table_team_meta( $post ) {
|
function sp_table_team_meta( $post ) {
|
||||||
sp_post_checklist( $post->ID, 'sp_team' );
|
$league = get_post_meta( $post->ID, 'sp_league', true );
|
||||||
sp_post_adder( 'sp_team' );
|
?>
|
||||||
|
<div>
|
||||||
|
<p class="sp-tab-select sp-title-generator">
|
||||||
|
<?php
|
||||||
|
$args = array(
|
||||||
|
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
|
||||||
|
'taxonomy' => 'sp_league',
|
||||||
|
'name' => 'sportspress[sp_league]',
|
||||||
|
'selected' => $league
|
||||||
|
);
|
||||||
|
sp_dropdown_taxonomies( $args );
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
sp_post_checklist( $post->ID, 'sp_team', 'block', 'sp_league' );
|
||||||
|
sp_post_adder( 'sp_team' );
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
sp_nonce();
|
sp_nonce();
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_table_stats_meta( $post ) {
|
function sp_table_stats_meta( $post ) {
|
||||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||||
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
||||||
$leagues = (array)get_the_terms( $post->ID, 'sp_league' );
|
$league = (int)get_post_meta( $post->ID, 'sp_league', true );
|
||||||
foreach ( $leagues as $league ):
|
$data = sp_array_combine( $teams, sp_array_value( $stats, $league, array() ) );
|
||||||
if ( is_object( $league ) && property_exists( $league, 'term_id' ) )
|
$placeholders = array();
|
||||||
$index = $league->term_id;
|
foreach ( $teams as $team ):
|
||||||
else
|
$placeholders[ $team ] = sp_get_stats( $team, 0, $league );
|
||||||
$index = 0;
|
|
||||||
|
|
||||||
$data = sp_array_combine( $teams, sp_array_value( $stats, $index, array() ) );
|
|
||||||
|
|
||||||
$placeholders = array();
|
|
||||||
foreach ( $teams as $team ):
|
|
||||||
$placeholders[ $team ] = sp_get_stats( $team, 0, $index );
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
sp_stats_table( $data, $placeholders, $index, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false );
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
sp_stats_table( $data, $placeholders, $league, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false );
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
2
team.php
2
team.php
@@ -48,7 +48,7 @@ function sp_team_stats_meta( $post ) {
|
|||||||
|
|
||||||
$data = sp_array_combine( $keys, sp_array_value( $stats, 0, array() ) );
|
$data = sp_array_combine( $keys, sp_array_value( $stats, 0, array() ) );
|
||||||
?>
|
?>
|
||||||
<?php sp_stats_table( $data, array(), 0, array( 'League', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), true, true, 'sp_league' );
|
<?php sp_stats_table( $data, array(), 0, array( 'League', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), true, 'sp_league' );
|
||||||
|
|
||||||
sp_nonce();
|
sp_nonce();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user