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

@@ -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 );
}
}