From 033fa2949c3985cfc36069f781b03a2bee18c227 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 18 Jun 2014 13:28:43 +1000 Subject: [PATCH] Add column selector to player profiles --- .../post-types/class-sp-admin-meta-boxes.php | 15 ++++--- .../class-sp-meta-box-player-columns.php | 43 +++++++++++++++++++ .../class-sp-meta-box-player-statistics.php | 17 +++----- includes/class-sp-player.php | 22 ++++++++-- includes/sp-core-functions.php | 36 ++++++++++++++++ 5 files changed, 113 insertions(+), 20 deletions(-) create mode 100644 includes/admin/post-types/meta-boxes/class-sp-meta-box-player-columns.php 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 458aa8d0..ea53be26 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -6,8 +6,8 @@ * * @author ThemeBoy * @category Admin - * @package SportsPress/Admin/Meta Boxes - * @version 1.0 + * @package SportsPress/Admin/Meta_Boxes + * @version 1.1 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -68,9 +68,10 @@ class SP_Admin_Meta_Boxes { add_action( 'sportspress_process_sp_table_meta', 'SP_Meta_Box_Table_Data::save', 20, 2 ); // Save Player Meta Boxes - add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Details::save', 10, 2 ); - add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Metrics::save', 20, 2 ); - add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Statistics::save', 30, 2 ); + add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Columns::save', 10, 2 ); + add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Details::save', 20, 2 ); + add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Metrics::save', 30, 2 ); + add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Statistics::save', 40, 2 ); // Save List Meta Boxes add_action( 'sportspress_process_sp_list_meta', 'SP_Meta_Box_List_Format::save', 10, 2 ); @@ -86,7 +87,6 @@ class SP_Admin_Meta_Boxes { * Add SP Meta boxes */ public function add_meta_boxes() { - // Results add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Result_Details::output', 'sp_result', 'normal', 'high' ); @@ -136,6 +136,7 @@ class SP_Admin_Meta_Boxes { add_meta_box( 'sp_editordiv', __( 'Description', 'sportspress' ), 'SP_Meta_Box_Table_Editor::output', 'sp_table', 'normal', 'high' ); // Players + add_meta_box( 'sp_columnsdiv', __( 'Columns', 'sportspress' ), 'SP_Meta_Box_Player_Columns::output', 'sp_player', 'side', 'default' ); add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Player_Details::output', 'sp_player', 'side', 'default' ); add_meta_box( 'sp_metricsdiv', __( 'Metrics', 'sportspress' ), 'SP_Meta_Box_Player_Metrics::output', 'sp_player', 'side', 'default' ); add_meta_box( 'sp_statisticsdiv', __( 'Statistics', 'sportspress' ), 'SP_Meta_Box_Player_Statistics::output', 'sp_player', 'normal', 'high' ); @@ -214,7 +215,7 @@ class SP_Admin_Meta_Boxes { if ( is_int( wp_is_post_autosave( $post ) ) ) return; if ( empty( $_POST['sportspress_meta_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_meta_nonce'], 'sportspress_save_data' ) ) return; if ( ! current_user_can( 'edit_post', $post_id )) return; - if ( ! in_array( $post->post_type, array( 'sp_result', 'sp_outcome', 'sp_performance', 'sp_statistic', 'sp_column', 'sp_metric', 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' ) ) ) return; + if ( ! is_sp_post_type( $post->post_type ) && ! is_sp_config_type( $post->post_type ) ) return; do_action( 'sportspress_process_' . $post->post_type . '_meta', $post_id, $post ); } diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-columns.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-columns.php new file mode 100644 index 00000000..fbde3104 --- /dev/null +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-columns.php @@ -0,0 +1,43 @@ + +
+ + ID, 'sp_columns', true ); + sp_column_checklist( $post->ID, 'sp_performance', 'block', $selected ); + sp_column_checklist( $post->ID, 'sp_statistic', 'none', $selected ); + ?> +
+ ID, 'sp_league' ); $league_num = sizeof( $leagues ); - $usecolumns = get_post_meta( $post->ID, 'sp_columns', true ); - // Loop through statistics for each league if ( $leagues ): foreach ( $leagues as $league ): @@ -35,7 +33,7 @@ class SP_Meta_Box_Player_Statistics { $player = new SP_Player( $post ); list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true ); - self::table( $post->ID, $league->term_id, $columns, $usecolumns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_player_statistics' ) ); + self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_player_statistics' ) ); endforeach; else: @@ -48,7 +46,6 @@ class SP_Meta_Box_Player_Statistics { * Save meta box data */ public static function save( $post_id, $post ) { - update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) ); update_post_meta( $post_id, 'sp_leagues', sp_array_value( $_POST, 'sp_leagues', array() ) ); if ( current_user_can( 'edit_sp_player_statistics' ) ) update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) ); @@ -57,20 +54,20 @@ class SP_Meta_Box_Player_Statistics { /** * Admin edit table */ - public static function table( $id = null, $league_id, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) { + public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) { $teams = array_filter( get_post_meta( $id, 'sp_team', false ) ); - if ( is_array( $usecolumns ) ) - $usecolumns = array_filter( $usecolumns ); ?>
- + $label ): ?> diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index 61e6e57b..2058da2a 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -307,8 +307,22 @@ class SP_Player extends SP_Custom_Post { $columns = array_merge( $performance_labels, $stats ); if ( $admin ): - return array( $columns, $data, $placeholders, $merged, $leagues ); + foreach( $usecolumns as $key ): + if ( $key == 'team' ): + $labels[ $key ] = __( 'Team', 'sportspress' ); + elseif ( array_key_exists( $key, $columns ) ): + $labels[ $key ] = $columns[ $key ]; + endif; + endforeach; + return array( $labels, $data, $placeholders, $merged, $leagues ); else: + if ( ! is_array( $this->columns ) ) + $this->columns = array(); + foreach ( $columns as $key => $label ): + if ( ! in_array( $key, $this->columns ) ): + unset( $columns[ $key ] ); + endif; + endforeach; if ( ! is_array( $usecolumns ) ) $usecolumns = array(); foreach ( $columns as $key => $label ): @@ -316,8 +330,10 @@ class SP_Player extends SP_Custom_Post { unset( $columns[ $key ] ); endif; endforeach; - $labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ), 'team' => __( 'Team', 'sportspress' ) ), $columns ); - $merged[0] = $labels; + $labels = array( 'name' => __( 'Season', 'sportspress' ) ); + if ( in_array( 'team', $this->columns ) ) + $labels['team'] = __( 'Team', 'sportspress' ); + $merged[0] = array_merge( $labels, $columns ); return $merged; endif; } diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index b921f125..40fff1bd 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -662,6 +662,42 @@ if ( !function_exists( 'sp_post_checklist' ) ) { } } +if ( !function_exists( 'sp_column_checklist' ) ) { + function sp_column_checklist( $post_id = null, $meta = 'post', $display = 'block', $selected = array(), $default_checked = false ) { + if ( ! isset( $post_id ) ) + global $post_id; + ?> +
+ +
    +
  • + $meta, 'number' => 0 ) ); + if ( empty( $posts ) ): + $query = array( 'post_type' => $meta, 'numberposts' => -1, 'post_per_page' => -1, 'order' => 'ASC', 'orderby' => 'menu_order' ); + $posts = get_posts( $query ); + endif; + if ( sizeof( $posts ) ): + foreach ( $posts as $post ): + ?> +
  • + +
  • + +
  • + +
+
+