From c354f0be6bff88bc1bc89c1f39e4eadfcada3d87 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sat, 20 Aug 2016 23:43:03 +1000 Subject: [PATCH] Add option to display player and staff dropdowns in profile --- assets/css/sportspress.css | 5 + assets/js/sportspress.js | 7 +- .../settings/class-sp-settings-players.php | 8 ++ .../settings/class-sp-settings-staff.php | 8 ++ includes/class-sp-install.php | 3 +- includes/sp-template-hooks.php | 118 ++++++++++++++++++ 6 files changed, 146 insertions(+), 3 deletions(-) diff --git a/assets/css/sportspress.css b/assets/css/sportspress.css index af3009de..78d50028 100644 --- a/assets/css/sportspress.css +++ b/assets/css/sportspress.css @@ -71,6 +71,11 @@ display: none; } +/* Profile selector */ +.sp-profile-selector { + float: right; +} + /* Data Tables */ .sp-scrollable-table-wrapper { width: 100%; diff --git a/assets/js/sportspress.js b/assets/js/sportspress.js index 17173a16..358b9468 100644 --- a/assets/js/sportspress.js +++ b/assets/js/sportspress.js @@ -78,8 +78,13 @@ function sp_viewport() { /* Scrollable Tables */ $(".sp-scrollable-table").wrap("
"); + + /* Selector Redirect */ + $(".sp-selector-redirect").change(function() { + window.location = $(this).val(); + }); - /* Template tabs */ + /* 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"); diff --git a/includes/admin/settings/class-sp-settings-players.php b/includes/admin/settings/class-sp-settings-players.php index 9fce8167..44d0fe9c 100644 --- a/includes/admin/settings/class-sp-settings-players.php +++ b/includes/admin/settings/class-sp-settings-players.php @@ -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' ), diff --git a/includes/admin/settings/class-sp-settings-staff.php b/includes/admin/settings/class-sp-settings-staff.php index 0a879424..ff676b79 100644 --- a/includes/admin/settings/class-sp-settings-staff.php +++ b/includes/admin/settings/class-sp-settings-staff.php @@ -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' ), diff --git a/includes/class-sp-install.php b/includes/class-sp-install.php index dcb7a63d..3675e2b1 100644 --- a/includes/class-sp-install.php +++ b/includes/class-sp-install.php @@ -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' ); } } diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php index e02309e7..d523d676 100644 --- a/includes/sp-template-hooks.php +++ b/includes/sp-template-hooks.php @@ -145,12 +145,130 @@ function sportspress_the_title( $title, $id = null ) { if ( $number != null ): $title = '' . $number . ' ' . $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[] = ''; + endforeach; + endif; + + if ( sizeof( $options ) > 1 ): + $title .= ''; + endif; + endif; elseif ( is_singular( 'sp_staff' ) ): $staff = new SP_Staff( $id ); $role = $staff->role(); if ( $role ): $title = '' . $role->name . ' ' . $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[] = ''; + endforeach; + endif; + + if ( sizeof( $options ) > 1 ): + $title .= ''; + endif; + endif; endif; endif;