Add ability to link teams and limit list

Limit player list to current team players
This commit is contained in:
Brian Miyaji
2014-05-31 12:56:32 +10:00
parent 384e4cffa9
commit f02d49f6b4
5 changed files with 37 additions and 7 deletions

View File

@@ -51,6 +51,10 @@ class SP_Meta_Box_List_Data {
<tr> <tr>
<th>#</th> <th>#</th>
<th><?php _e( 'Player', 'sportspress' ); ?></th> <th><?php _e( 'Player', 'sportspress' ); ?></th>
<th><label for="sp_columns_team">
<input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $usecolumns ) || in_array( 'team', $usecolumns ) ); ?>>
<?php _e( 'Team', 'sportspress' ); ?>
</label></th>
<?php foreach ( $columns as $key => $label ): ?> <?php foreach ( $columns as $key => $label ): ?>
<th><label for="sp_columns_<?php echo $key; ?>"> <th><label for="sp_columns_<?php echo $key; ?>">
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>> <input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
@@ -65,6 +69,7 @@ class SP_Meta_Box_List_Data {
$i = 0; $i = 0;
foreach ( $data as $player_id => $player_stats ): foreach ( $data as $player_id => $player_stats ):
if ( !$player_id ) continue; if ( !$player_id ) continue;
$team = get_post_meta( $player_id, 'sp_team', true );
$div = get_term( $player_id, 'sp_season' ); $div = get_term( $player_id, 'sp_season' );
$number = get_post_meta( $player_id, 'sp_number', true ); $number = get_post_meta( $player_id, 'sp_number', true );
@@ -85,6 +90,7 @@ class SP_Meta_Box_List_Data {
<a class="button button-primary sp-save"><?php _e( 'Save', 'sportspress' ); ?></a> <a class="button button-primary sp-save"><?php _e( 'Save', 'sportspress' ); ?></a>
</span> </span>
</td> </td>
<td><?php echo get_the_title( $team ); ?></td>
<?php foreach( $columns as $column => $label ): <?php foreach( $columns as $column => $label ):
$value = sp_array_value( $player_stats, $column, '' ); $value = sp_array_value( $player_stats, $column, '' );
$placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 ); $placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 );

View File

@@ -102,7 +102,7 @@ class SP_Meta_Box_List_Details {
</p> </p>
<p><strong><?php _e( 'Players', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Players', 'sportspress' ); ?></strong></p>
<?php <?php
sp_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team' ); sp_post_checklist( $post->ID, 'sp_player', 'block', 'sp_current_team' );
sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) ); sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) );
?> ?>
</div> </div>

View File

@@ -5,7 +5,7 @@
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 0.8 * @version 1.0
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -60,6 +60,14 @@ class SP_Settings_Players extends SP_Settings_Page {
'type' => 'checkbox', 'type' => 'checkbox',
), ),
array(
'title' => __( 'Teams', 'sportspress' ),
'desc' => __( 'Link teams', 'sportspress' ),
'id' => 'sportspress_list_link_teams',
'default' => 'no',
'type' => 'checkbox',
),
array( array(
'title' => __( 'Pagination', 'sportspress' ), 'title' => __( 'Pagination', 'sportspress' ),
'desc' => __( 'Paginate', 'sportspress' ), 'desc' => __( 'Paginate', 'sportspress' ),

View File

@@ -239,8 +239,6 @@ class SP_Player_List extends SP_Custom_Post {
$totals[ $player_id ]['last10'] = $last10; $totals[ $player_id ]['last10'] = $last10;
endforeach; endforeach;
$columns = array();
if ( ! empty( $column_groups ) ): if ( ! empty( $column_groups ) ):
$args = array( $args = array(
@@ -351,8 +349,12 @@ class SP_Player_List extends SP_Custom_Post {
unset( $columns[ $key ] ); unset( $columns[ $key ] );
endif; endif;
endforeach; endforeach;
$labels = array_merge( array( 'name' => SP()->text->string('Player') ), $columns );
$merged[0] = $labels; $labels = array( 'name' => SP()->text->string('Player') );
if ( in_array( 'team', $this->columns ) )
$labels['team'] = __( 'Team', 'sportspress' );
$merged[0] = array_merge( $labels, $columns );
return $merged; return $merged;
endif; endif;
} }

View File

@@ -18,6 +18,7 @@ $defaults = array(
'order' => 'ASC', 'order' => 'ASC',
'show_all_players_link' => false, 'show_all_players_link' => false,
'link_posts' => get_option( 'sportspress_list_link_players', 'yes' ) == 'yes' ? true : false, 'link_posts' => get_option( 'sportspress_list_link_players', 'yes' ) == 'yes' ? true : false,
'link_teams' => get_option( 'sportspress_list_link_teams', 'no' ) == 'yes' ? true : false,
'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false, 'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false, 'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false,
'paginated' => get_option( 'sportspress_list_paginated', 'yes' ) == 'yes' ? true : false, 'paginated' => get_option( 'sportspress_list_paginated', 'yes' ) == 'yes' ? true : false,
@@ -121,9 +122,22 @@ foreach ( $groups as $group ):
endif; endif;
$output .= '<td class="data-name">' . $name . '</td>'; $output .= '<td class="data-name">' . $name . '</td>';
if ( array_key_exists( 'team', $labels ) ):
$teams = get_post_meta( $player_id, 'sp_current_team' );
$team_names = array();
foreach ( $teams as $team ):
$team_name = get_the_title( $team );
if ( $link_teams ):
$team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
endif;
$team_names[] = $team_name;
endforeach;
$output .= '<td class="data-team">' . implode( ', ', $team_names ) . '</td>';
endif;
foreach( $labels as $key => $value ): foreach( $labels as $key => $value ):
if ( $key == 'name' ) if ( in_array( $key, array( 'name', 'team' ) ) )
continue; continue;
if ( ! is_array( $columns ) || in_array( $key, $columns ) ) if ( ! is_array( $columns ) || in_array( $key, $columns ) )
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '&mdash;' ) . '</td>'; $output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '&mdash;' ) . '</td>';