From c3d86d3de8f338c5465a775f262e39b46577207b Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Fri, 20 Jun 2014 11:42:19 +1000 Subject: [PATCH] Enable linking player lists to teams --- .../post-types/class-sp-admin-meta-boxes.php | 10 +- .../class-sp-meta-box-team-columns.php | 4 +- .../class-sp-meta-box-team-lists.php | 121 ++++++++++++++++++ includes/class-sp-post-types.php | 2 +- includes/class-sp-team.php | 39 +++++- includes/sp-template-functions.php | 21 +++ includes/sp-template-hooks.php | 17 +++ templates/player-gallery.php | 5 +- templates/player-list.php | 5 +- templates/team-columns.php | 4 +- templates/team-lists.php | 32 +++++ 11 files changed, 245 insertions(+), 15 deletions(-) create mode 100644 includes/admin/post-types/meta-boxes/class-sp-meta-box-team-lists.php create mode 100644 templates/team-lists.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 44e67b1e..bae3ec5e 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -60,8 +60,9 @@ class SP_Admin_Meta_Boxes { add_action( 'sportspress_process_sp_calendar_meta', 'SP_Meta_Box_Calendar_Data::save', 30, 2 ); // Save Team Meta Boxes - add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Columns::save', 10, 2 ); - add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Details::save', 20, 2 ); + add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Details::save', 10, 2 ); + add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Columns::save', 20, 2 ); + add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Lists::save', 30, 2 ); // Save Table Meta Boxes add_action( 'sportspress_process_sp_table_meta', 'SP_Meta_Box_Table_Details::save', 10, 2 ); @@ -125,9 +126,10 @@ class SP_Admin_Meta_Boxes { add_meta_box( 'sp_editordiv', __( 'Description', 'sportspress' ), 'SP_Meta_Box_Calendar_Editor::output', 'sp_calendar', 'normal', 'high' ); // Teams - add_meta_box( 'sp_columnssdiv', __( 'Table Columns', 'sportspress' ), 'SP_Meta_Box_Team_Columns::output', 'sp_team', 'normal', 'high' ); - add_meta_box( 'sp_editordiv', __( 'Profile', 'sportspress' ), 'SP_Meta_Box_Team_Editor::output', 'sp_team', 'normal', 'high' ); add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Team_Details::output', 'sp_team', 'side', 'default' ); + add_meta_box( 'sp_columnssdiv', __( 'Table Columns', 'sportspress' ), 'SP_Meta_Box_Team_Columns::output', 'sp_team', 'normal', 'high' ); + add_meta_box( 'sp_listsdiv', __( 'Player Lists', 'sportspress' ), 'SP_Meta_Box_Team_Lists::output', 'sp_team', 'normal', 'high' ); + add_meta_box( 'sp_editordiv', __( 'Profile', 'sportspress' ), 'SP_Meta_Box_Team_Editor::output', 'sp_team', 'normal', 'high' ); // Tables add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_Table_Shortcode::output', 'sp_table', 'side', 'default' ); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-columns.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-columns.php index 2237328f..9db455be 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-columns.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-columns.php @@ -36,7 +36,7 @@ class SP_Meta_Box_Team_Columns { $team = new SP_Team( $post ); - list( $columns, $data, $placeholders, $merged, $leagues_seasons ) = $team->data( $league_id, true ); + list( $columns, $data, $placeholders, $merged, $leagues_seasons ) = $team->columns( $league_id, true ); self::table( $league_id, $columns, $data, $placeholders, $merged, $leagues_seasons, ! current_user_can( 'edit_sp_team_columns' ) ); @@ -62,7 +62,7 @@ class SP_Meta_Box_Team_Columns { public static function table( $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $seasons = array(), $readonly = true ) { ?>
- +
diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-lists.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-lists.php new file mode 100644 index 00000000..dba3f7be --- /dev/null +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-lists.php @@ -0,0 +1,121 @@ +lists( true ); + self::table( $data, $checked ); + + else: + + printf( __( 'No results found.', 'sportspress' ) ); + + endif; + } + + /** + * Save meta box data + */ + public static function save( $post_id, $post ) { + sp_update_post_meta_recursive( $post_id, 'sp_list', sp_array_value( $_POST, 'sp_list', array() ) ); + } + + /** + * Admin edit table + */ + public static function table( $data = array(), $checked = array() ) { + ?> +
+
+ + + + + + + + + + + + 0 ): + $i = 0; + foreach ( $data as $list ): + $players = array_filter( get_post_meta( $list->ID, 'sp_player' ) ); + $format = get_post_meta( $list->ID, 'sp_format', true ); + ?> + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ ID, $checked ) ); ?>> + + + post_title; ?> + + ID, 'sp_league' ) ? the_terms( $list->ID, 'sp_league' ) : '—'; ?>ID, 'sp_season' ) ? the_terms( $list->ID, 'sp_season' ) : '—'; ?>formats->list, $format, '—' ); ?>
+ +
+ +
+
+ false, 'hierarchical' => false, 'rewrite' => array( 'slug' => get_option( 'sportspress_list_slug', 'list' ) ), - 'supports' => array( 'title', 'author', 'thumbnail' ), + 'supports' => array( 'title', 'page-attributes', 'author', 'thumbnail' ), 'has_archive' => false, 'show_in_nav_menus' => true, 'show_in_menu' => 'edit.php?post_type=sp_player', diff --git a/includes/class-sp-team.php b/includes/class-sp-team.php index 7a665047..d59cc59f 100644 --- a/includes/class-sp-team.php +++ b/includes/class-sp-team.php @@ -5,7 +5,7 @@ * The SportsPress team class handles individual team data. * * @class SP_Team - * @version 0.8.4 + * @version 1.1 * @package SportsPress/Classes * @category Class * @author ThemeBoy @@ -41,7 +41,7 @@ class SP_Team extends SP_Custom_Post { * @param bool $admin * @return array */ - public function data( $league_id, $admin = false ) { + public function columns( $league_id, $admin = false ) { $seasons = (array)get_the_terms( $this->ID, 'sp_season' ); $columns = (array)get_post_meta( $this->ID, 'sp_columns', true ); $leagues_seasons = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() ); @@ -257,4 +257,39 @@ class SP_Team extends SP_Custom_Post { return $merged; endif; } + + /** + * Returns player lists + * + * @access public + * @return array + */ + public function lists( $admin = false ) { + if ( ! $this->ID ) return null; + + $args = array( + 'post_type' => 'sp_list', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'meta_key' => 'sp_team', + 'meta_value' => $this->ID, + ); + $lists = get_posts( $args ); + + $checked = (array) get_post_meta( $this->ID, 'sp_list' ); + + if ( $admin ): + return array( $lists, $checked ); + else: + foreach ( $lists as $key => $list ): + if ( ! in_array( $list->ID, $checked ) ): + unset( $lists[ $key ] ); + endif; + endforeach; + return $lists; + endif; + + } } diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index 98ea58b7..cb8247ba 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -186,6 +186,19 @@ if ( ! function_exists( 'sportspress_output_team_columns' ) ) { sp_get_template( 'team-columns.php' ); } } +if ( ! function_exists( 'sportspress_output_team_lists' ) ) { + + /** + * Output the team lists. + * + * @access public + * @subpackage Team/Lists + * @return void + */ + function sportspress_output_team_lists() { + sp_get_template( 'team-lists.php' ); + } +} /** Single League Table ********************************************************/ @@ -285,3 +298,11 @@ function sportspress_output_venue_map( $query ) { $meta = get_option( "taxonomy_$t_id" ); sp_get_template( 'venue-map.php', array( 'meta' => $meta ) ); } + +/** Misc ********************************************************/ + +function sportspress_output_br_tag() { + ?> +
+ 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', + 'grouptag' => 'h4', 'columns' => 3, 'size' => 'thumbnail', 'show_all_players_link' => false, @@ -110,7 +111,7 @@ foreach ( $groups as $group ): if ( ! empty( $group->name ) ): echo ''; - echo ''; + echo '<' . $grouptag . ' class="player-group-name player-gallery-group-name">' . $group->name . ''; endif; foreach( $data as $player_id => $performance ): if ( empty( $group->term_id ) || has_term( $group->term_id, 'sp_position', $player_id ) ): diff --git a/templates/player-list.php b/templates/player-list.php index 5bac3202..7da81b9b 100644 --- a/templates/player-list.php +++ b/templates/player-list.php @@ -4,7 +4,7 @@ * * @author ThemeBoy * @package SportsPress/Templates - * @version 0.8 + * @version 1.1 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -12,6 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly $defaults = array( 'id' => get_the_ID(), 'number' => -1, + 'grouptag' => 'h4', 'columns' => null, 'grouping' => null, 'orderby' => 'default', @@ -76,7 +77,7 @@ $output = ''; foreach ( $groups as $group ): if ( ! empty( $group->name ) ): $output .= ''; - $output .= '

' . $group->name . '

'; + $output .= '<' . $grouptag . ' class="sp-table-caption player-group-name player-list-group-name">' . $group->name . ''; endif; $output .= '
' . diff --git a/templates/team-columns.php b/templates/team-columns.php index 53afbe36..73dbb949 100644 --- a/templates/team-columns.php +++ b/templates/team-columns.php @@ -4,7 +4,7 @@ * * @author ThemeBoy * @package SportsPress/Templates - * @version 0.8 + * @version 1.1 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -23,7 +23,7 @@ $output = ''; foreach ( $leagues as $league ): $team = new SP_Team( $id ); - $data = $team->data( $league->term_id ); + $data = $team->columns( $league->term_id ); if ( sizeof( $data ) <= 1 ) continue; diff --git a/templates/team-lists.php b/templates/team-lists.php new file mode 100644 index 00000000..369aca5a --- /dev/null +++ b/templates/team-lists.php @@ -0,0 +1,32 @@ +lists(); + +foreach ( $lists as $list ): + $id = $list->ID; + + if ( $id && sizeof( $lists ) > 1 ): + ?> +

post_title; ?>

+ formats->list ) ) + sp_get_template( 'player-' . $format . '.php', array( 'id' => $id ) ); + else + sp_get_template( 'player-list.php', array( 'id' => $id ) ); +endforeach;