Add append and prepend options to page dropdown, sorting options per player list and default order option to widget

This commit is contained in:
Brian Miyaji
2014-02-17 07:24:08 +11:00
parent 630c23db52
commit 3bfeaef612
8 changed files with 116 additions and 19 deletions

View File

@@ -153,6 +153,12 @@ function sportspress_save_post( $post_id ) {
// Update season taxonomy
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
// Update orderby
update_post_meta( $post_id, 'sp_orderby', sportspress_array_value( $_POST, 'sp_orderby', array() ) );
// Update order
update_post_meta( $post_id, 'sp_order', sportspress_array_value( $_POST, 'sp_order', array() ) );
//Update player array
sportspress_update_post_meta_recursive( $post_id, 'sp_player', sportspress_array_value( $_POST, 'sp_player', array() ) );

View File

@@ -53,6 +53,8 @@ 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 );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
?>
<div>
<p><strong><?php _e( 'League', 'sportspress' ); ?></strong></p>
@@ -98,6 +100,32 @@ function sportspress_list_player_meta( $post ) {
endif;
?>
</p>
<p><strong><?php _e( 'Sort by:', 'sportspress' ); ?></strong></p>
<p>
<?php
$args = array(
'prepend_options' => array(
'number' => __( 'Number', 'sportspress' ),
'name' => __( 'Name', 'sportspress' ),
'eventsplayed' => __( 'Played', 'sportspress' )
),
'post_type' => 'sp_statistic',
'name' => 'sp_orderby',
'selected' => $orderby,
'values' => 'slug',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_list' );
endif;
?>
</p>
<p><strong><?php _e( 'Sort Order:', 'sportspress' ); ?></strong></p>
<p>
<select name="sp_order">
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
</select>
</p>
<p><strong><?php _e( 'Players', 'sportspress' ); ?></strong></p>
<?php
sportspress_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team' );

View File

@@ -7,7 +7,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
$defaults = array(
'statistics' => null,
'orderby' => 'number',
'orderby' => 'default',
'order' => 'ASC',
);
@@ -26,7 +26,10 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
$statistics = sportspress_array_value( $r, 'statistics', null );
if ( $r['orderby'] != 'number' || $r['order'] != 'ASC' ):
if ( $r['orderby'] == 'default' ):
$r['orderby'] = get_post_meta( $id, 'sp_orderby', true );
$r['order'] = get_post_meta( $id, 'sp_order', true );
else:
global $sportspress_statistic_priorities;
$sportspress_statistic_priorities = array(
array(
@@ -37,7 +40,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
uasort( $data, 'sportspress_sort_list_players' );
endif;
if ( $r['orderby'] == 'number' ):
if ( in_array( $r['orderby'], array( 'number', 'name' ) ) ):
$output .= '<th class="data-number">#</th>';
else:
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';

View File

@@ -11,7 +11,7 @@ class SportsPress_Widget_Player_list extends WP_Widget {
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
$statistics = $instance['statistics'];
$orderby = empty($instance['orderby']) ? 'number' : $instance['orderby'];
$orderby = empty($instance['orderby']) ? 'default' : $instance['orderby'];
$order = empty($instance['order']) ? 'ASC' : $instance['order'];
echo $before_widget;
if ( $title )
@@ -34,7 +34,7 @@ class SportsPress_Widget_Player_list extends WP_Widget {
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'statistics' => null, 'orderby' => 'number', 'order' => 'ASC' ) );
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'statistics' => null, 'orderby' => 'default', 'order' => 'ASC' ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$statistics = $instance['statistics'];
@@ -84,16 +84,18 @@ class SportsPress_Widget_Player_list extends WP_Widget {
<p><label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:', 'sportspress' ); ?></label>
<?php
$args = array(
'prepend_options' => array(
'default' => __( 'Default', 'sportspress' ),
'number' => __( 'Number', 'sportspress' ),
'name' => __( 'Name', 'sportspress' ),
'eventsplayed' => __( 'Played', 'sportspress' )
),
'post_type' => 'sp_statistic',
'show_option_all' => __( 'Number', 'sportspress' ),
'option_all_value' => 'number',
'show_option_none' => __( 'Played', 'sportspress' ),
'option_none_value' => 'eventsplayed',
'name' => $this->get_field_name('orderby'),
'id' => $this->get_field_id('orderby'),
'selected' => $orderby,
'values' => 'slug',
'class' => 'widefat',
'class' => 'sp-select-orderby widefat',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_list' );
@@ -102,7 +104,7 @@ class SportsPress_Widget_Player_list extends WP_Widget {
</p>
<p><label for="<?php echo $this->get_field_id('order'); ?>"><?php _e( 'Sort Order:', 'sportspress' ); ?></label>
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="widefat">
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="sp-select-order widefat" <?php disabled( $orderby, 'default' ); ?>>
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
</select></p>

View File

@@ -20,6 +20,11 @@ jQuery(document).ready(function($){
// Activate auto key placeholder
$("#poststuff #title").keyup();
// Orderby affects order select in widget options
$("body.widgets-php").on("change", ".sp-select-orderby", function() {
$(this).closest(".widget-content").find(".sp-select-order").prop("disabled", $(this).val() == "default");
});
// Tab switcher
$(".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();

View File

@@ -262,6 +262,8 @@ if ( !function_exists( 'sportspress_dropdown_taxonomies' ) ) {
if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
function sportspress_dropdown_pages( $args = array() ) {
$defaults = array(
'prepend_options' => null,
'append_options' => null,
'show_option_all' => false,
'show_option_none' => false,
'show_dates' => false,
@@ -305,7 +307,7 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
unset( $args['selected'] );
$posts = get_posts( $args );
if ( $posts ):
if ( $posts || $prepend || $append ):
printf( '<select name="%s" id="%s" class="postform %s">', $name, $id, $class );
if ( $args['show_option_all'] ):
printf( '<option value="%s" %s>%s</option>', $args['option_all_value'], selected( $selected, $args['option_all_value'], false ), $args['show_option_all'] );
@@ -313,6 +315,11 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
if ( $args['show_option_none'] ):
printf( '<option value="%s" %s>%s</option>', $args['option_none_value'], selected( $selected, $args['option_none_value'], false ), $args['show_option_none'] );
endif;
if ( $args['prepend_options'] && is_array( $args['prepend_options'] ) ):
foreach( $args['prepend_options'] as $slug => $label ):
printf( '<option value="%s" %s>%s</option>', $slug, selected( $selected, $slug, false ), $label );
endforeach;
endif;
foreach ( $posts as $post ):
setup_postdata( $post );
if ( $values == 'ID' ):
@@ -322,6 +329,11 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
endif;
endforeach;
wp_reset_postdata();
if ( $args['append_options'] && is_array( $args['append_options'] ) ):
foreach( $args['append_options'] as $slug => $label ):
printf( '<option value="%s" %s>%s</option>', $slug, selected( $selected, $slug, false ), $label );
endforeach;
endif;
print( '</select>' );
return true;
else:
@@ -1840,6 +1852,8 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) {
$team_id = get_post_meta( $post_id, 'sp_team', true );
$player_ids = (array)get_post_meta( $post_id, 'sp_player', false );
$stats = (array)get_post_meta( $post_id, 'sp_players', true );
$orderby = get_post_meta( $post_id, 'sp_orderby', true );
$order = get_post_meta( $post_id, 'sp_order', true );
// Get labels from result variables
$columns = (array)sportspress_get_var_labels( 'sp_statistic' );
@@ -2057,6 +2071,17 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) {
endforeach;
endforeach;
if ( $orderby != 'number' || $order != 'ASC' ):
global $sportspress_statistic_priorities;
$sportspress_statistic_priorities = array(
array(
'statistic' => $orderby,
'order' => $order,
),
);
uasort( $merged, 'sportspress_sort_list_players' );
endif;
// Rearrange data array to reflect statistics
$data = array();
foreach( $merged as $key => $value ):
@@ -2064,7 +2089,7 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) {
endforeach;
if ( $admin ):
return array( $columns, $tempdata, $placeholders, $merged );
return array( $columns, $data, $placeholders, $merged );
else:
$labels = array_merge( array( 'name' => __( 'Player', 'sportspress' ) ), $columns );
$merged[0] = $labels;
@@ -2084,8 +2109,16 @@ if ( !function_exists( 'sportspress_sort_list_players' ) ) {
// Proceed if columns are not equal
if ( sportspress_array_value( $a, $priority['statistic'], 0 ) != sportspress_array_value( $b, $priority['statistic'], 0 ) ):
// Compare statistic values
$output = sportspress_array_value( $a, $priority['statistic'], 0 ) - sportspress_array_value( $b, $priority['statistic'], 0 );
if ( $priority['statistic'] == 'name' ):
$output = strcmp( sportspress_array_value( $a, 'name', null ), sportspress_array_value( $b, 'name', null ) );
else:
// Compare statistic values
$output = sportspress_array_value( $a, $priority['statistic'], 0 ) - sportspress_array_value( $b, $priority['statistic'], 0 );
endif;
// Flip value if descending order
if ( $priority['order'] == 'DESC' ) $output = 0 - $output;
@@ -2097,7 +2130,7 @@ if ( !function_exists( 'sportspress_sort_list_players' ) ) {
endforeach;
// Default sort by number
return strcmp( sportspress_array_value( $a, 'number', '' ), sportspress_array_value( $b, 'number', '' ) );
return sportspress_array_value( $a, 'number', 0 ) - sportspress_array_value( $b, 'number', 0 );
}
}

View File

@@ -4,7 +4,7 @@ Tags: sports, sports journalism, teams, team management, fixtures, results, stan
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=support@themeboy.com&item_name=Donation+for+SportsPress
Requires at least: 3.8
Tested up to: 3.8.1
Stable tag: 0.3.1
Stable tag: 0.3.3
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -14,6 +14,18 @@ SportsPress is a fully configurable sports plugin that seemlessly automates leag
Add schedules, results, league tables, player profiles and statistics to your team or league site with SportsPress. It is designed to work with virtually every WordPress theme, and includes several language translations.
= Features =
* Team Profiles
* League Tables
* Events (Fixtures & Results)
* Events Calendar
* Player Profiles & Statistics Per Position
* Player Lists
* Staff Profiles
* Season Archives
* Venue Information & Maps
* Statistics & League Table Columns Configuration
= Customizable =
League table columns, player statistics, and match results can be customized to fit any sport. Presets are available for some of the most popular sports including soccer, rugby, American football, Australian Rules football, baseball, basketball, cricket, and hockey.
@@ -94,6 +106,14 @@ SportsPress is currently in beta and is undergoing testing. We are still activel
== Changelog ==
= 0.3.3 =
* Feature - Add default sorting options per player list.
* Feature - Add option to sort player list alphabetically by name or by default.
= 0.3.2 =
* Feature - Add England, Scotland, Northern Ireland, and Wales to countries selector.
* Feature - Enable searching for countries in dropdown.
= 0.3.1 =
* Feature - Import tool added for importing teams from CSV file.
* Tweak - Added option to select custom sport and enter sport name.

View File

@@ -6,7 +6,7 @@
Plugin Name: SportsPress
Plugin URI: http://themeboy.com/sportspress
Description: Manage your club and its players, staff, events, league tables, and player lists.
Version: 0.3.1
Version: 0.3.3
Author: ThemeBoy
Author URI: http://themeboy.com/
License: GPLv3
@@ -18,7 +18,7 @@ if ( !function_exists( 'add_action' ) ) {
exit;
}
define( 'SPORTSPRESS_VERSION', '0.3.1' );
define( 'SPORTSPRESS_VERSION', '0.3.3' );
define( 'SPORTSPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'SPORTSPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
define( 'SPORTSPRESS_PLUGIN_FILE', __FILE__ );