Enable linking player lists to teams

This commit is contained in:
Brian Miyaji
2014-06-20 11:42:19 +10:00
parent d49f1c6c13
commit c3d86d3de8
11 changed files with 245 additions and 15 deletions

View File

@@ -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' );

View File

@@ -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 ) {
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-select-all-range">
<table class="widefat sp-data-table sp-team-column-table sp-select-all-range">
<thead>
<tr>
<th class="check-column"><input class="sp-select-all" type="checkbox"></th>

View File

@@ -0,0 +1,121 @@
<?php
/**
* Team Player Lists
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Team_Lists
*/
class SP_Meta_Box_Team_Lists {
/**
* Output the metabox
*/
public static function output( $post ) {
global $pagenow;
if ( $pagenow != 'post-new.php' ):
$team = new SP_Team( $post );
list( $data, $checked ) = $team->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() ) {
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-team-list-table sp-select-all-range">
<thead>
<tr>
<th class="check-column"><input class="sp-select-all" type="checkbox"></th>
<th class="column-list">
<?php _e( 'List', 'sportspress' ); ?>
</th>
<th class="column-players">
<?php _e( 'Players', 'sportspress' ); ?>
</th>
<th class="column-league">
<?php _e( 'League', 'sportspress' ); ?>
</th>
<th class="column-season">
<?php _e( 'Season', 'sportspress' ); ?>
</th>
<th class="column-layout">
<?php _e( 'Layout', 'sportspress' ); ?>
</th>
</tr>
</thead>
<tbody>
<?php
if ( is_array( $data ) ):
if ( sizeof( $data ) > 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 );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<input type="checkbox" name="sp_list[]" id="sp_list_<?php echo $list->ID; ?>" value="<?php echo $list->ID; ?>" <?php checked( in_array( $list->ID, $checked ) ); ?>>
</td>
<td>
<a href="<?php echo get_edit_post_link( $list->ID ); ?>">
<?php echo $list->post_title; ?>
</a>
</td>
<td><?php echo sizeof( $players ); ?></td>
<td><?php echo get_the_terms ( $list->ID, 'sp_league' ) ? the_terms( $list->ID, 'sp_league' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms ( $list->ID, 'sp_season' ) ? the_terms( $list->ID, 'sp_season' ) : '&mdash;'; ?></td>
<td><?php echo sp_array_value( SP()->formats->list, $format, '&mdash;' ); ?></td>
</tr>
<?php
$i++;
endforeach;
else:
?>
<tr class="sp-row alternate">
<td colspan="4">
<?php _e( 'No results found.', 'sportspress' ); ?>
</td>
</tr>
<?php
endif;
else:
?>
<tr class="sp-row alternate">
<td colspan="4">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
</div>
<?php
}
}

View File

@@ -509,7 +509,7 @@ class SP_Post_types {
'exclude_from_search' => 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',

View File

@@ -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;
}
}

View File

@@ -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() {
?>
<br>
<?php
}

View File

@@ -37,6 +37,8 @@ add_action( 'sportspress_single_event_content', 'sportspress_output_event_detail
add_action( 'sportspress_single_event_content', 'sportspress_output_event_venue', 40 );
add_action( 'sportspress_single_event_content', 'sportspress_output_event_performance', 50 );
add_action( 'sportspress_after_single_event', 'sportspress_output_br_tag', 100 );
/**
* Single Calendar Content
*
@@ -44,13 +46,20 @@ add_action( 'sportspress_single_event_content', 'sportspress_output_event_perfor
*/
add_action( 'sportspress_single_calendar_content', 'sportspress_output_calendar', 10 );
add_action( 'sportspress_after_single_calendar', 'sportspress_output_br_tag', 100 );
/**
* Single Team Content
*
* @see sportspress_output_team_link()
* @see sportspress_output_team_columns()
* @see sportspress_output_team_lists()
*/
add_action( 'sportspress_single_team_content', 'sportspress_output_team_link', 10 );
add_action( 'sportspress_single_team_content', 'sportspress_output_team_columns', 20 );
add_action( 'sportspress_single_team_content', 'sportspress_output_team_lists', 30 );
add_action( 'sportspress_after_single_team', 'sportspress_output_br_tag', 100 );
/**
* Single Table Content
@@ -59,6 +68,8 @@ add_action( 'sportspress_single_team_content', 'sportspress_output_team_columns'
*/
add_action( 'sportspress_single_table_content', 'sportspress_output_league_table', 10 );
add_action( 'sportspress_after_single_table', 'sportspress_output_br_tag', 100 );
/**
* Single Player Content
*
@@ -68,6 +79,8 @@ add_action( 'sportspress_single_table_content', 'sportspress_output_league_table
add_action( 'sportspress_single_player_content', 'sportspress_output_player_details', 10 );
add_action( 'sportspress_single_player_content', 'sportspress_output_player_statistics', 20 );
add_action( 'sportspress_after_single_player', 'sportspress_output_br_tag', 100 );
/**
* Single List Content
*
@@ -75,6 +88,8 @@ add_action( 'sportspress_single_player_content', 'sportspress_output_player_stat
*/
add_action( 'sportspress_single_list_content', 'sportspress_output_player_list', 10 );
add_action( 'sportspress_after_single_list', 'sportspress_output_br_tag', 100 );
/**
* Single Staff Content
*
@@ -82,6 +97,8 @@ add_action( 'sportspress_single_list_content', 'sportspress_output_player_list',
*/
add_action( 'sportspress_single_staff_content', 'sportspress_output_staff_details', 10 );
add_action( 'sportspress_after_single_staff', 'sportspress_output_br_tag', 100 );
/**
* Venue Archive Content
*/

View File

@@ -4,7 +4,7 @@
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 0.9.4
* @version 1.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -18,6 +18,7 @@ $defaults = array(
'itemtag' => '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 '<a name="group-' . $group->slug . '" id="group-' . $group->slug . '"></a>';
echo '<h3 class="player-group-name player-gallery-group-name">' . $group->name . '</h3>';
echo '<' . $grouptag . ' class="player-group-name player-gallery-group-name">' . $group->name . '</' . $grouptag . '>';
endif;
foreach( $data as $player_id => $performance ): if ( empty( $group->term_id ) || has_term( $group->term_id, 'sp_position', $player_id ) ):

View File

@@ -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 .= '<a name="group-' . $group->slug . '" id="group-' . $group->slug . '"></a>';
$output .= '<h3 class="sp-table-caption player-group-name player-list-group-name">' . $group->name . '</h3>';
$output .= '<' . $grouptag . ' class="sp-table-caption player-group-name player-list-group-name">' . $group->name . '</' . $grouptag . '>';
endif;
$output .= '<div class="sp-table-wrapper sp-scrollable-table-wrapper">' .

View File

@@ -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;

32
templates/team-lists.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
/**
* Team Player Lists
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 1.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! isset( $id ) )
$id = get_the_ID();
$team = new SP_Team( $id );
$lists = $team->lists();
foreach ( $lists as $list ):
$id = $list->ID;
if ( $id && sizeof( $lists ) > 1 ):
?>
<h4 class="sp-table-caption"><?php echo $list->post_title; ?></h4>
<?php
endif;
$format = get_post_meta( $id, 'sp_format', true );
if ( array_key_exists( $format, SP()->formats->list ) )
sp_get_template( 'player-' . $format . '.php', array( 'id' => $id ) );
else
sp_get_template( 'player-list.php', array( 'id' => $id ) );
endforeach;