Add option to display player and staff dropdowns in profile

This commit is contained in:
Brian Miyaji
2016-08-20 23:43:03 +10:00
parent 7f97fc9ba0
commit c354f0be6b
6 changed files with 146 additions and 3 deletions

View File

@@ -71,6 +71,11 @@
display: none;
}
/* Profile selector */
.sp-profile-selector {
float: right;
}
/* Data Tables */
.sp-scrollable-table-wrapper {
width: 100%;

View File

@@ -79,7 +79,12 @@ function sp_viewport() {
/* Scrollable Tables */
$(".sp-scrollable-table").wrap("<div class=\"sp-scrollable-table-wrapper\"></div>");
/* Template tabs */
/* Selector Redirect */
$(".sp-selector-redirect").change(function() {
window.location = $(this).val();
});
/* Template Tabs */
$(".sp-tab-menu-item a").click(function() {
$template = $(this).data("sp-tab");
$(this).closest(".sp-tab-menu-item").addClass("sp-tab-menu-item-active").siblings(".sp-tab-menu-item").removeClass("sp-tab-menu-item-active");

View File

@@ -59,6 +59,14 @@ class SP_Settings_Players extends SP_Settings_Page {
'type' => 'checkbox',
),
array(
'title' => __( 'Dropdown', 'sportspress' ),
'desc' => __( 'Display dropdown', 'sportspress' ),
'id' => 'sportspress_player_show_selector',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Details', 'sportspress' ),
'desc' => __( 'Squad Number', 'sportspress' ),

View File

@@ -59,6 +59,14 @@ class SP_Settings_Staff extends SP_Settings_Page {
'type' => 'checkbox',
),
array(
'title' => __( 'Dropdown', 'sportspress' ),
'desc' => __( 'Display dropdown', 'sportspress' ),
'id' => 'sportspress_staff_show_selector',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Details', 'sportspress' ),
'desc' => __( 'Nationality', 'sportspress' ),

View File

@@ -406,8 +406,7 @@ class SP_Install {
}
if ( version_compare( $version, '2.1', '<' ) ) {
$option = get_option( 'sportspress_event_results_reverse_teams', 'no' );
update_option( 'sportspress_event_reverse_teams', $option );
update_option( 'sportspress_player_show_selector', 'no' );
}
}

View File

@@ -145,12 +145,130 @@ function sportspress_the_title( $title, $id = null ) {
if ( $number != null ):
$title = '<strong class="sp-player-number">' . $number . '</strong> ' . $title;
endif;
if ( 'yes' === get_option( 'sportspress_player_show_selector', 'yes' ) ):
$league_ids = sp_get_the_term_ids( $id, 'sp_league' );
$season_ids = sp_get_the_term_ids( $id, 'sp_season' );
$team = get_post_meta( $id, 'sp_current_team', true );
$args = array(
'post_type' => 'sp_player',
'numberposts' => 500,
'posts_per_page' => 500,
'meta_key' => 'sp_number',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
),
);
if ( $league_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'term_id',
'terms' => $league_ids
);
endif;
if ( $season_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'term_id',
'terms' => $season_ids
);
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
$args['meta_query'] = array(
array(
'key' => 'sp_team',
'value' => $team
),
);
endif;
$players = get_posts( $args );
$options = array();
if ( $players && is_array( $players ) ):
foreach ( $players as $player ):
$name = $player->post_title;
$number = get_post_meta( $player->ID, 'sp_number', true );
if ( isset( $number ) && '' !== $number ):
$name = $number . '. ' . $name;
endif;
$options[] = '<option value="' . get_post_permalink( $player->ID ) . '" ' . selected( $player->ID, $id, false ) . '>' . $name . '</option>';
endforeach;
endif;
if ( sizeof( $options ) > 1 ):
$title .= '<select class="sp-profile-selector sp-player-selector sp-selector-redirect">' . implode( $options ) . '</select>';
endif;
endif;
elseif ( is_singular( 'sp_staff' ) ):
$staff = new SP_Staff( $id );
$role = $staff->role();
if ( $role ):
$title = '<strong class="sp-staff-role">' . $role->name . '</strong> ' . $title;
endif;
if ( 'yes' === get_option( 'sportspress_staff_show_selector', 'yes' ) ):
$league_ids = sp_get_the_term_ids( $id, 'sp_league' );
$season_ids = sp_get_the_term_ids( $id, 'sp_season' );
$team = get_post_meta( $id, 'sp_current_team', true );
$args = array(
'post_type' => 'sp_staff',
'numberposts' => 500,
'posts_per_page' => 500,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
),
);
if ( $league_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'term_id',
'terms' => $league_ids
);
endif;
if ( $season_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'term_id',
'terms' => $season_ids
);
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
$args['meta_query'] = array(
array(
'key' => 'sp_team',
'value' => $team
),
);
endif;
$staffs = get_posts( $args );
$options = array();
if ( $staffs && is_array( $staffs ) ):
foreach ( $staffs as $staff ):
$options[] = '<option value="' . get_post_permalink( $staff->ID ) . '" ' . selected( $staff->ID, $id, false ) . '>' . $staff->post_title . '</option>';
endforeach;
endif;
if ( sizeof( $options ) > 1 ):
$title .= '<select class="sp-profile-selector sp-staff-selector sp-selector-redirect">' . implode( $options ) . '</select>';
endif;
endif;
endif;
endif;