Enable linking player lists to teams
This commit is contained in:
@@ -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' );
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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' ) : '—'; ?></td>
|
||||
<td><?php echo get_the_terms ( $list->ID, 'sp_season' ) ? the_terms( $list->ID, 'sp_season' ) : '—'; ?></td>
|
||||
<td><?php echo sp_array_value( SP()->formats->list, $format, '—' ); ?></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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user