From b6f79cec1325cf583da1c9dcfb5e59be0104f9db Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Thu, 16 Mar 2017 13:49:51 +1100 Subject: [PATCH] Add option to choose individual/team mode per event --- assets/css/admin.css | 5 + assets/css/menu.css | 3 +- .../post-types/class-sp-admin-meta-boxes.php | 7 + .../class-sp-meta-box-event-mode.php | 38 +++ .../class-sp-meta-box-event-performance.php | 11 +- .../class-sp-meta-box-event-teams.php | 44 ++-- .../class-sp-meta-box-list-data.php | 4 +- .../class-sp-meta-box-list-details.php | 2 - .../class-sp-meta-box-player-details.php | 2 - .../class-sp-meta-box-staff-details.php | 2 - .../class-sp-meta-box-table-data.php | 15 +- .../class-sp-meta-box-table-details.php | 7 +- .../class-sp-meta-box-table-mode.php | 38 +++ .../settings/class-sp-settings-events.php | 28 +- includes/class-sp-install.php | 7 + includes/class-sp-league-table.php | 5 +- includes/class-sp-player-list.php | 36 ++- includes/sp-core-functions.php | 57 +++++ modules/sportspress-individual-mode.php | 240 +----------------- modules/sportspress-league-tables.php | 7 + modules/sportspress-template-selector.php | 5 +- templates/event-performance.php | 2 +- templates/league-table.php | 10 +- templates/player-selector.php | 2 +- templates/staff-selector.php | 2 +- 25 files changed, 253 insertions(+), 326 deletions(-) create mode 100644 includes/admin/post-types/meta-boxes/class-sp-meta-box-event-mode.php create mode 100644 includes/admin/post-types/meta-boxes/class-sp-meta-box-table-mode.php diff --git a/assets/css/admin.css b/assets/css/admin.css index d9e3aef4..3f5eb4d8 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -15,10 +15,15 @@ content: "\f328"; } +.post-state-format.post-format-player:before, .post-format-icon.post-format-player:before, a.post-state-format.format-player:before, .post-state-format.post-format-roster:before, .post-format-icon.post-format-roster:before, a.post-state-format.format-roster:before { content: "\f307"; } +.post-state-format.post-format-team:before, .post-format-icon.post-format-team:before, a.post-state-format.format-team:before { + content: "\f334"; +} + .post-state-format.post-format-list:before, .post-format-icon.post-format-list:before, a.post-state-format.format-list:before { content: "\f163"; } diff --git a/assets/css/menu.css b/assets/css/menu.css index f5f7e0c3..5733c684 100644 --- a/assets/css/menu.css +++ b/assets/css/menu.css @@ -185,7 +185,8 @@ #adminmenu #menu-posts-sp_team .menu-icon-sp_team div.wp-menu-image:before, #adminmenu #menu-posts-sp_player .menu-icon-sp_player div.wp-menu-image:before, #adminmenu #menu-posts-sp_staff .menu-icon-sp_staff div.wp-menu-image:before, -#sp_formatdiv #post-formats-select .post-format-icon:before { +#sp_formatdiv #post-formats-select .post-format-icon:before, +#sp_modediv #post-formats-select .post-format-icon:before { font-family: sportspress, dashicons; width: 20px; text-align: center; diff --git a/includes/admin/post-types/class-sp-admin-meta-boxes.php b/includes/admin/post-types/class-sp-admin-meta-boxes.php index c5f8e386..63400702 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -123,6 +123,13 @@ class SP_Admin_Meta_Boxes { 'context' => 'side', 'priority' => 'default', ), + 'mode' => array( + 'title' => __( 'Mode', 'sportspress' ), + 'save' => 'SP_Meta_Box_Event_Mode::save', + 'output' => 'SP_Meta_Box_Event_Mode::output', + 'context' => 'side', + 'priority' => 'default', + ), 'details' => array( 'title' => __( 'Details', 'sportspress' ), 'save' => 'SP_Meta_Box_Event_Details::save', diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-mode.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-mode.php new file mode 100644 index 00000000..09749f0e --- /dev/null +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-mode.php @@ -0,0 +1,38 @@ +ID ); + ?> +
+ __( 'Team vs team', 'sportspress' ), 'player' => __( 'Player vs player', 'sportspress' ) ) as $key => $mode ): ?> + >
+ +
+ ID ); + + // Get status option + $status = ! $is_individual; self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order, $numbers, $is_individual, $timeline, $timed ); } diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-teams.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-teams.php index 52808bcd..e5e5d99d 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-teams.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-teams.php @@ -21,7 +21,8 @@ class SP_Meta_Box_Event_Teams { public static function output( $post ) { $limit = get_option( 'sportspress_event_teams', 2 ); $teams = (array) get_post_meta( $post->ID, 'sp_team', false ); - if ( $limit ) { + $post_type = sp_get_post_mode_type( $post->ID ); + if ( $limit && 'sp_player' !== $post_type ) { for ( $i = 0; $i < $limit; $i ++ ): $team = array_shift( $teams ); ?> @@ -29,7 +30,7 @@ class SP_Meta_Box_Event_Teams {

'sp_team', + 'post_type' => $post_type, 'name' => 'sp_team[]', 'class' => 'sportspress-pages', 'show_option_none' => __( '— None —', 'sportspress' ), @@ -119,10 +120,10 @@ class SP_Meta_Box_Event_Teams { endfor; } else { ?> -

+

ID ) ); ?>

'sp_team', + 'post_type' => $post_type, 'name' => 'sp_team[]', 'selected' => $teams, 'values' => 'ID', @@ -132,7 +133,7 @@ class SP_Meta_Box_Event_Teams { 'placeholder' => __( 'None', 'sportspress' ), ); if ( ! sp_dropdown_pages( $args ) ): - sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); + sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) ); endif; } wp_nonce_field( 'sp-get-players', 'sp-get-players-nonce', false ); @@ -142,17 +143,30 @@ class SP_Meta_Box_Event_Teams { * Save meta box data */ public static function save( $post_id, $post ) { - sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); - $tabs = array(); - $sections = get_option( 'sportspress_event_performance_sections', -1 ); - if ( -1 == $sections ) { - sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) ); - } else { - $players = array_merge( sp_array_value( $_POST, 'sp_offense', array() ), sp_array_value( $_POST, 'sp_defense', array() ) ); - sp_update_post_meta_recursive( $post_id, 'sp_offense', sp_array_value( $_POST, 'sp_offense', array() ) ); - sp_update_post_meta_recursive( $post_id, 'sp_defense', sp_array_value( $_POST, 'sp_defense', array() ) ); + $teams = sp_array_value( $_POST, 'sp_team', array() ); + + sp_update_post_meta_recursive( $post_id, 'sp_team', $teams ); + + $post_type = sp_get_post_mode_type( $post->ID ); + + if ( 'sp_player' === $post_type ) { + $players = array(); + foreach ( $teams as $player ) { + $players[] = array( 0, $player ); + } sp_update_post_meta_recursive( $post_id, 'sp_player', $players ); + } else { + $tabs = array(); + $sections = get_option( 'sportspress_event_performance_sections', -1 ); + if ( -1 == $sections ) { + sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) ); + } else { + $players = array_merge( sp_array_value( $_POST, 'sp_offense', array() ), sp_array_value( $_POST, 'sp_defense', array() ) ); + sp_update_post_meta_recursive( $post_id, 'sp_offense', sp_array_value( $_POST, 'sp_offense', array() ) ); + sp_update_post_meta_recursive( $post_id, 'sp_defense', sp_array_value( $_POST, 'sp_defense', array() ) ); + sp_update_post_meta_recursive( $post_id, 'sp_player', $players ); + } + sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) ); } - sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) ); } } diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-data.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-data.php index 2e022925..388e5db1 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-data.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-data.php @@ -51,7 +51,7 @@ class SP_Meta_Box_List_Data { - + @@ -103,7 +103,7 @@ class SP_Meta_Box_List_Data { - + -

>

-

-

-

data( true ); $adjustments = $table->adjustments; $highlight = get_post_meta( $table->ID, 'sp_highlight', true ); - self::table( $columns, $usecolumns, $data, $placeholders, $adjustments, $highlight ); + self::table( $table->ID, $columns, $usecolumns, $data, $placeholders, $adjustments, $highlight ); } /** @@ -39,10 +39,19 @@ class SP_Meta_Box_Table_Data { /** * Admin edit table */ - public static function table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null ) { + public static function table( $id, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null ) { if ( is_array( $usecolumns ) ) $usecolumns = array_filter( $usecolumns ); + + $mode = sp_get_post_mode( $id ); + + if ( 'player' === $mode ) { + $show_team_logo = get_option( 'sportspress_list_show_photos', 'no' ) == 'yes' ? true : false; + $icon_class = 'sp-icon-tshirt'; + } else { $show_team_logo = get_option( 'sportspress_table_show_logos', 'no' ) == 'yes' ? true : false; + $icon_class = 'sp-icon-shield'; + } ?>