Enable selecting columns to display in player list

This commit is contained in:
Brian Miyaji
2014-06-18 13:29:00 +10:00
parent 033fa2949c
commit 6333025646
3 changed files with 84 additions and 91 deletions

View File

@@ -4,8 +4,8 @@
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 0.8 * @version 1.1
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -19,35 +19,27 @@ class SP_Meta_Box_List_Columns {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$column_groups = (array) get_post_meta( $post->ID, 'sp_column_group' );
?> ?>
<ul id="sp-column-group-select"> <div class="sp-instance">
<li> <ul id="sp_column-tabs" class="wp-tab-bar sp-tab-bar">
<label class="selectit"> <li class="wp-tab-active"><a href="#sp_performance-all"><?php _e( 'Performance', 'sportspress' ); ?></a></li>
<input type="checkbox" name="sp_column_group[]" value="sp_performance" <?php checked( true, in_array( 'sp_performance', $column_groups ) ); ?>> <li class="wp-tab"><a href="#sp_metric-all"><?php _e( 'Metrics', 'sportspress' ); ?></a></li>
<?php _e( 'Performance', 'sportspress' ); ?> <li class="wp-tab"><a href="#sp_statistic-all"><?php _e( 'Statistics', 'sportspress' ); ?></a></li>
</label>
</li>
<li>
<label class="selectit">
<input type="checkbox" name="sp_column_group[]" value="sp_metric" <?php checked( true, in_array( 'sp_metric', $column_groups ) ); ?>>
<?php _e( 'Metrics', 'sportspress' ); ?>
</label>
</li>
<li>
<label class="selectit">
<input type="checkbox" name="sp_column_group[]" value="sp_statistic" <?php checked( true, in_array( 'sp_statistic', $column_groups ) ); ?>>
<?php _e( 'Statistics', 'sportspress' ); ?>
</label>
</li>
</ul> </ul>
<?php <?php
$selected = (array)get_post_meta( $post->ID, 'sp_columns', true );
sp_column_checklist( $post->ID, 'sp_performance', 'block', $selected );
sp_column_checklist( $post->ID, 'sp_metric', 'none', $selected );
sp_column_checklist( $post->ID, 'sp_statistic', 'none', $selected );
?>
</div>
<?php
} }
/** /**
* Save meta box data * Save meta box data
*/ */
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
sp_update_post_meta_recursive( $post_id, 'sp_column_group', sp_array_value( $_POST, 'sp_column_group', array() ) ); update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
} }
} }

View File

@@ -4,7 +4,7 @@
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 1.0.2 * @version 1.0.2
*/ */
@@ -20,16 +20,15 @@ class SP_Meta_Box_List_Data {
*/ */
public static function output( $post ) { public static function output( $post ) {
$list = new SP_Player_List( $post ); $list = new SP_Player_List( $post );
list( $columns, $usecolumns, $data, $placeholders, $merged ) = $list->data( true ); list( $columns, $data, $placeholders, $merged ) = $list->data( true );
$adjustments = $list->adjustments; $adjustments = $list->adjustments;
self::table( $columns, $usecolumns, $data, $placeholders, $adjustments ); self::table( $columns, $data, $placeholders, $adjustments );
} }
/** /**
* Save meta box data * Save meta box data
*/ */
public static function save( $post_id, $post ) { 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_adjustments', sp_array_value( $_POST, 'sp_adjustments', array() ) ); update_post_meta( $post_id, 'sp_adjustments', sp_array_value( $_POST, 'sp_adjustments', array() ) );
update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) ); update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) );
} }
@@ -37,9 +36,7 @@ class SP_Meta_Box_List_Data {
/** /**
* Admin edit table * Admin edit table
*/ */
public static function table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array() ) { public static function table( $columns = array(), $data = array(), $placeholders = array(), $adjustments = array() ) {
if ( is_array( $usecolumns ) )
$usecolumns = array_filter( $usecolumns );
?> ?>
<ul class="subsubsub sp-table-bar"> <ul class="subsubsub sp-table-bar">
<li><a href="#sp-table-values" class="current"><?php _e( 'Values', 'sportspress' ); ?></a></li> | <li><a href="#sp-table-values" class="current"><?php _e( 'Values', 'sportspress' ); ?></a></li> |
@@ -52,12 +49,12 @@ class SP_Meta_Box_List_Data {
<th>#</th> <th>#</th>
<th><?php _e( 'Player', 'sportspress' ); ?></th> <th><?php _e( 'Player', 'sportspress' ); ?></th>
<th><label for="sp_columns_team"> <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 ) ); ?>> <input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>>
<?php _e( 'Team', 'sportspress' ); ?> <?php _e( 'Team', 'sportspress' ); ?>
</label></th> </label></th>
<?php foreach ( $columns as $key => $label ): ?> <?php foreach ( $columns as $key => $label ): ?>
<?php if ( $key == 'team' ) continue; ?>
<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 ) ); ?>>
<?php echo $label; ?> <?php echo $label; ?>
</label></th> </label></th>
<?php endforeach; ?> <?php endforeach; ?>
@@ -92,6 +89,7 @@ class SP_Meta_Box_List_Data {
</td> </td>
<td><?php echo get_the_title( $team ); ?></td> <td><?php echo get_the_title( $team ); ?></td>
<?php foreach( $columns as $column => $label ): <?php foreach( $columns as $column => $label ):
if ( $column == 'team' ) continue;
$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

@@ -41,7 +41,6 @@ class SP_Player_List extends SP_Custom_Post {
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true ); $adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
$orderby = get_post_meta( $this->ID, 'sp_orderby', true ); $orderby = get_post_meta( $this->ID, 'sp_orderby', true );
$order = get_post_meta( $this->ID, 'sp_order', true ); $order = get_post_meta( $this->ID, 'sp_order', true );
$column_groups = (array)get_post_meta( $this->ID, 'sp_column_group' );
// Get labels from performance variables // Get labels from performance variables
$performance_labels = (array)sp_get_var_labels( 'sp_performance' ); $performance_labels = (array)sp_get_var_labels( 'sp_performance' );
@@ -242,10 +241,8 @@ class SP_Player_List extends SP_Custom_Post {
$totals[ $player_id ]['last10'] = $last10; $totals[ $player_id ]['last10'] = $last10;
endforeach; endforeach;
if ( ! empty( $column_groups ) ):
$args = array( $args = array(
'post_type' => $column_groups, 'post_type' => array( 'sp_performance', 'sp_metric', 'sp_statistic' ),
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
@@ -307,8 +304,6 @@ class SP_Player_List extends SP_Custom_Post {
endforeach; endforeach;
endif;
// Merge the data and placeholders arrays // Merge the data and placeholders arrays
$merged = array(); $merged = array();
@@ -348,7 +343,15 @@ class SP_Player_List extends SP_Custom_Post {
endforeach; endforeach;
if ( $admin ): if ( $admin ):
return array( $columns, $this->columns, $data, $placeholders, $merged ); $labels = array();
foreach( $this->columns 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 );
else: else:
if ( ! is_array( $this->columns ) ) if ( ! is_array( $this->columns ) )
$this->columns = array(); $this->columns = array();