Move post type specific functions into classes

This commit is contained in:
Brian Miyaji
2014-04-26 17:52:43 +10:00
parent b6342b97e3
commit 284b0f1a5f
36 changed files with 2234 additions and 3062 deletions

View File

@@ -68,7 +68,7 @@ class SP_Admin_Menus {
*/
public function menu_highlight() {
global $typenow, $submenu;
if ( sp_is_config_type( $typenow ) )
if ( is_sp_config_type( $typenow ) )
$this->highlight_admin_menu();
elseif ( $typenow == 'sp_calendar' )
$this->highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' );

View File

@@ -54,7 +54,7 @@ class SP_Admin_Post_Types {
public function post_updated_messages( $messages ) {
global $typenow, $post;
if ( sp_is_config_type( $typenow ) ):
if ( is_sp_config_type( $typenow ) ):
$obj = get_post_type_object( $typenow );
for ( $i = 0; $i <= 10; $i++ ):

View File

@@ -19,8 +19,10 @@ class SP_Meta_Box_Calendar_Data {
* Output the metabox
*/
public static function output( $post ) {
list( $data, $usecolumns ) = sp_get_calendar_data( $post->ID, true );
sp_edit_calendar_table( $data, $usecolumns );
$calendar = new SP_Calendar( $post );
$data = $calendar->data();
$usecolumns = $calendar->columns;
self::table( $data, $usecolumns );
}
/**
@@ -29,4 +31,132 @@ class SP_Meta_Box_Calendar_Data {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
}
/**
* Admin edit table
*/
public static function table( $data = array(), $usecolumns = null ) {
if ( is_array( $usecolumns ) )
$usecolumns = array_filter( $usecolumns );
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-calendar-table">
<thead>
<tr>
<th class="column-date">
<?php _e( 'Date', 'sportspress' ); ?>
</th>
<th class="column-event">
<label for="sp_columns_event">
<input type="checkbox" name="sp_columns[]" value="event" id="sp_columns_event" <?php checked( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ); ?>>
<?php _e( 'Event', 'sportspress' ); ?>
</label>
</th>
<th class="column-teams">
<label for="sp_columns_teams">
<input type="checkbox" name="sp_columns[]" value="teams" id="sp_columns_teams" <?php checked( ! is_array( $usecolumns ) || in_array( 'teams', $usecolumns ) ); ?>>
<?php _e( 'Teams', 'sportspress' ); ?>
</label>
</th>
<th class="column-time">
<label for="sp_columns_time">
<input type="checkbox" name="sp_columns[]" value="time" id="sp_columns_time" <?php checked( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ); ?>>
<?php _e( 'Time', 'sportspress' ); ?>
</label>
</th>
<th class="column-venue">
<label for="sp_columns_venue">
<input type="checkbox" name="sp_columns[]" value="venue" id="sp_columns_venue" <?php checked( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ); ?>>
<?php _e( 'Venue', 'sportspress' ); ?>
</label>
</th>
<th class="column-article">
<label for="sp_columns_article">
<input type="checkbox" name="sp_columns[]" value="article" id="sp_columns_article" <?php checked( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ); ?>>
<?php _e( 'Article', 'sportspress' ); ?>
</label>
</th>
</tr>
</thead>
<tbody>
<?php
if ( is_array( $data ) && sizeof( $data ) > 0 ):
$main_result = get_option( 'sportspress_primary_result', null );
$i = 0;
foreach ( $data as $event ):
$teams = get_post_meta( $event->ID, 'sp_team' );
$results = get_post_meta( $event->ID, 'sp_results', true );
$video = get_post_meta( $event->ID, 'sp_video', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td><?php echo get_post_time( get_option( 'date_format' ), false, $event ); ?></td>
<td><?php echo $event->post_title; ?></td>
<td>
<?php
foreach ( $teams as $team ):
$name = get_the_title( $team );
if ( $name ):
$team_results = sp_array_value( $results, $team, null );
if ( $main_result ):
$team_result = sp_array_value( $team_results, $main_result, null );
else:
if ( is_array( $team_results ) ):
end( $team_results );
$team_result = prev( $team_results );
else:
$team_result = null;
endif;
endif;
if ( $team_result != null ):
unset( $team_results['outcome'] );
$team_results = implode( ' | ', $team_results );
echo '<a class="result tips" title="' . $team_results . '" href="' . get_edit_post_link( $event->ID ) . '">' . $team_result . '</a> ';
endif;
echo $name . '<br>';
endif;
endforeach;
?>
</td>
<td><?php echo get_post_time( get_option( 'time_format' ), false, $event ); ?></td>
<td><?php the_terms( $event->ID, 'sp_venue' ); ?></td>
<td>
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
<?php if ( $video ): ?>
<div class="dashicons dashicons-video-alt"></div>
<?php elseif ( has_post_thumbnail( $event->ID ) ): ?>
<div class="dashicons dashicons-camera"></div>
<?php endif; ?>
<?php
if ( $event->post_content == null ):
_e( 'None', 'sportspress' );
elseif ( $event->post_status == 'publish' ):
_e( 'Recap', 'sportspress' );
else:
_e( 'Preview', 'sportspress' );
endif;
?>
</a>
</td>
</tr>
<?php
$i++;
endforeach;
else:
?>
<tr class="sp-row alternate">
<td colspan="6">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
</div>
<?php
}
}

View File

@@ -5,15 +5,18 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
/**
* SP_Meta_Box_Column_Details
*/
class SP_Meta_Box_Column_Details {
class SP_Meta_Box_Column_Details extends SP_Meta_Box_Config {
/**
* Output the metabox
@@ -37,7 +40,7 @@ class SP_Meta_Box_Column_Details {
<p class="sp-equation-selector">
<?php
foreach ( $equation as $piece ):
sp_equation_selector( $post->ID, $piece, array( 'team_event', 'outcome', 'result' ) );
self::select( $post->ID, $piece, array( 'team_event', 'outcome', 'result' ) );
endforeach;
?>
</p>
@@ -75,7 +78,7 @@ class SP_Meta_Box_Column_Details {
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_delete_duplicate_post( $_POST );
self::delete_duplicate( $_POST );
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
update_post_meta( $post_id, 'sp_priority', sp_array_value( $_POST, 'sp_priority', '0' ) );

View File

@@ -0,0 +1,156 @@
<?php
/**
* Config type meta box functions
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Config
*/
class SP_Meta_Box_Config {
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
self::delete_duplicate( $_POST );
}
public static function select( $postid, $selected = null, $groups = array() ) {
if ( ! isset( $postid ) )
return;
// Initialize options array
$options = array();
// Add groups to options
foreach ( $groups as $group ):
switch ( $group ):
case 'player_event':
$options[ __( 'Events', 'sportspress' ) ] = array( '$eventsattended' => __( 'Attended', 'sportspress' ), '$eventsplayed' => __( 'Played', 'sportspress' ) );
break;
case 'team_event':
$options[ __( 'Events', 'sportspress' ) ] = array( '$eventsplayed' => __( 'Played', 'sportspress' ) );
break;
case 'result':
$options[ __( 'Results', 'sportspress' ) ] = self::optgroup( $postid, 'sp_result', array( 'for' => '&rarr;', 'against' => '&larr;' ), null, false );
break;
case 'outcome':
$options[ __( 'Outcomes', 'sportspress' ) ] = self::optgroup( $postid, 'sp_outcome', array() );
$options[ __( 'Outcomes', 'sportspress' ) ]['$streak'] = __( 'Streak', 'sportspress' );
$options[ __( 'Outcomes', 'sportspress' ) ]['$last5'] = __( 'Last 5', 'sportspress' );
$options[ __( 'Outcomes', 'sportspress' ) ]['$last10'] = __( 'Last 10', 'sportspress' );
break;
case 'performance':
$options[ __( 'Performance', 'sportspress' ) ] = self::optgroup( $postid, 'sp_performance' );
break;
case 'metric':
$options[ __( 'Metric', 'sportspress' ) ] = self::optgroup( $postid, 'sp_metric' );
break;
endswitch;
endforeach;
// Create array of operators
$operators = array( '+' => '&plus;', '-' => '&minus;', '*' => '&times;', '/' => '&divide;', '(' => '(', ')' => ')' );
// Add operators to options
$options[ __( 'Operators', 'sportspress' ) ] = $operators;
// Create array of constants
$max = 10;
$constants = array();
for ( $i = 1; $i <= $max; $i ++ ):
$constants[$i] = $i;
endfor;
// Add 100 to constants
$constants[100] = 100;
// Add constants to options
$options[ __( 'Constants', 'sportspress' ) ] = (array) $constants;
?>
<select name="sp_equation[]">
<option value=""><?php _e( '&mdash; Select &mdash;', 'sportspress' ); ?></option>
<?php
foreach ( $options as $label => $option ):
printf( '<optgroup label="%s">', $label );
foreach ( $option as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $selected, false ), $value );
endforeach;
echo '</optgroup>';
endforeach;
?>
</select>
<?php
}
public static function optgroup( $postid, $type = null, $variations = null, $defaults = null, $totals = true ) {
$arr = array();
// Get posts
$args = array(
'post_type' => $type,
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'exclude' => $postid
);
$vars = get_posts( $args );
// Add extra vars to the array
if ( isset( $defaults ) && is_array( $defaults ) ):
foreach ( $defaults as $key => $value ):
$arr[ $key ] = $value;
endforeach;
endif;
// Add vars to the array
if ( isset( $variations ) && is_array( $variations ) ):
foreach ( $vars as $var ):
if ( $totals ) $arr[ '$' . $var->post_name ] = $var->post_title;
foreach ( $variations as $key => $value ):
$arr[ '$' . $var->post_name . $key ] = $var->post_title . ' ' . $value;
endforeach;
endforeach;
else:
foreach ( $vars as $var ):
$arr[ '$' . $var->post_name ] = $var->post_title;
endforeach;
endif;
return (array) $arr;
}
public static function delete_duplicate( &$post ) {
global $wpdb;
$key = isset( $post['sp_key'] ) ? $post['sp_key'] : null;
if ( ! $key ) $key = $post['post_title'];
$id = sp_array_value( $post, 'post_ID', 'var' );
$title = sp_get_eos_safe_slug( $key, $id );
$check_sql = "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $title, $post['post_type'], $id ) );
if ( $post_name_check ):
wp_delete_post( $post_name_check, true );
$post['post_status'] = 'draft';
endif;
return $post_name_check;
}
}

View File

@@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -35,7 +35,7 @@ class SP_Meta_Box_Event_Performance {
?>
<div>
<p><strong><?php echo get_the_title( $team_id ); ?></strong></p>
<?php sp_edit_event_players_table( $columns, $data, $team_id ); ?>
<?php self::table( $columns, $data, $team_id ); ?>
</div>
<?php
@@ -48,4 +48,115 @@ class SP_Meta_Box_Event_Performance {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) );
}
/**
* Admin edit table
*/
public static function table( $columns = array(), $data = array(), $team_id ) {
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-performance-table">
<thead>
<tr>
<th>#</th>
<th><?php _e( 'Player', 'sportspress' ); ?></th>
<?php foreach ( $columns as $label ): ?>
<th><?php echo $label; ?></th>
<?php endforeach; ?>
<th><?php _e( 'Status', 'sportspress' ); ?></th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ( $data as $player_id => $player_performance ):
if ( !$player_id ) continue;
$number = get_post_meta( $player_id, 'sp_number', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>" data-player="<?php echo $player_id; ?>">
<td><?php echo ( $number ? $number : '&nbsp;' ); ?></td>
<td><?php echo get_the_title( $player_id ); ?></td>
<?php foreach( $columns as $column => $label ):
$value = sp_array_value( $player_performance, $column, '' );
?>
<td>
<input class="sp-player-<?php echo $column; ?>-input" type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" />
</td>
<?php endforeach; ?>
<td class="sp-status-selector">
<?php echo self::status_select( $team_id, $player_id, sp_array_value( $player_performance, 'status', null ) ); ?>
<?php echo self::sub_select( $team_id, $player_id, sp_array_value( $player_performance, 'sub', null ), $data ); ?>
</td>
</tr>
<?php
$i++;
endforeach;
?>
<tr class="sp-row sp-total<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>&nbsp;</td>
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
<?php foreach( $columns as $column => $label ):
$player_id = 0;
$player_performance = sp_array_value( $data, 0, array() );
$value = sp_array_value( $player_performance, $column, '' );
?>
<td><input type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" /></td>
<?php endforeach; ?>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</div>
<?php
}
/**
* Status selector
*/
public static function status_select( $team_id, $player_id, $value = null ) {
if ( ! $team_id || ! $player_id )
return '&mdash;';
$options = array(
'lineup' => __( 'Starting Lineup', 'sportspress' ),
'sub' => __( 'Substitute', 'sportspress' ),
);
$output = '<select name="sp_players[' . $team_id . '][' . $player_id . '][status]">';
foreach( $options as $key => $name ):
$output .= '<option value="' . $key . '"' . ( $key == $value ? ' selected' : '' ) . '>' . $name . '</option>';
endforeach;
$output .= '</select>';
return $output;
}
/**
* Substitute selector
*/
public static function sub_select( $team_id, $player_id, $value, $data = array() ) {
if ( ! $team_id || ! $player_id )
return '&mdash;';
$output = '<select name="sp_players[' . $team_id . '][' . $player_id . '][sub]" style="display: none;">';
$output .= '<option value="0">' . __( 'None', 'sportspress' ) . '</option>';
// Add players as selectable options
foreach( $data as $id => $performance ):
if ( ! $id || $id == $player_id ) continue;
$number = get_post_meta( $id, 'sp_number', true );
$output .= '<option value="' . $id . '"' . ( $id == $value ? ' selected' : '' ) . '>' . ( $number ? $number . '. ' : '' ) . get_the_title( $id ) . '</option>';
endforeach;
$output .= '</select>';
return $output;
}
}

View File

@@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -31,7 +31,7 @@ class SP_Meta_Box_Event_Results {
?>
<div>
<?php sp_edit_event_results_table( $columns, $data ); ?>
<?php self::table( $columns, $data ); ?>
</div>
<?php
}
@@ -43,4 +43,66 @@ class SP_Meta_Box_Event_Results {
$results = (array)sp_array_value( $_POST, 'sp_results', array() );
update_post_meta( $post_id, 'sp_results', $results );
}
/**
* Admin edit table
*/
public static function table( $columns = array(), $data = array() ) {
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table">
<thead>
<tr>
<th class="column-team"><?php _e( 'Team', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): ?>
<th class="outcome-<?php echo $key; ?>"><?php echo $label; ?></th>
<?php endforeach; ?>
<th class="column-outcome"><?php _e( 'Outcome', 'sportspress' ); ?></th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ( $data as $team_id => $team_results ):
if ( !$team_id ) continue;
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo get_the_title( $team_id ); ?>
</td>
<?php foreach( $columns as $column => $label ):
$value = sp_array_value( $team_results, $column, '' );
?>
<td><input type="text" name="sp_results[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" /></td>
<?php endforeach; ?>
<td>
<?php
$values = sp_array_value( $team_results, 'outcome', '' );
if ( ! is_array( $values ) )
$values = array( $values );
$args = array(
'post_type' => 'sp_outcome',
'name' => 'sp_results[' . $team_id . '][outcome][]',
'option_none_value' => '',
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $values,
'class' => 'sp-outcome',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?>
</td>
</tr>
<?php
$i++;
endforeach;
?>
</tbody>
</table>
</div>
<?php
}
}

View File

@@ -10,10 +10,13 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
/**
* SP_Meta_Box_Metric_Details
*/
class SP_Meta_Box_Metric_Details {
class SP_Meta_Box_Metric_Details extends SP_Meta_Box_Config {
/**
* Output the metabox
@@ -29,11 +32,4 @@ class SP_Meta_Box_Metric_Details {
</p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_delete_duplicate_post( $_POST );
}
}

View File

@@ -10,10 +10,13 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
/**
* SP_Meta_Box_Outcome_Details
*/
class SP_Meta_Box_Outcome_Details {
class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
/**
* Output the metabox
@@ -28,11 +31,4 @@ class SP_Meta_Box_Outcome_Details {
</p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_delete_duplicate_post( $_POST );
}
}

View File

@@ -10,17 +10,19 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
/**
* SP_Meta_Box_Performance_Details
*/
class SP_Meta_Box_Performance_Details {
class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
/**
* Output the metabox
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$calculate = get_post_meta( $post->ID, 'sp_calculate', true );
?>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
@@ -29,11 +31,4 @@ class SP_Meta_Box_Performance_Details {
</p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_delete_duplicate_post( $_POST );
}
}

View File

@@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -32,9 +32,11 @@ class SP_Meta_Box_Player_Performance {
<?php
endif;
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = sp_get_player_performance_data( $post->ID, $league->term_id, true );
$player = new SP_Player( $post );
sp_edit_player_performance_table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_teams' ) );
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_teams' ) );
endforeach; else:
@@ -51,4 +53,85 @@ class SP_Meta_Box_Player_Performance {
if ( current_user_can( 'edit_sp_teams' ) )
update_post_meta( $post_id, 'sp_performance', sp_array_value( $_POST, 'sp_performance', array() ) );
}
/**
* Admin edit table
*/
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) {
if ( ! $id )
$id = get_the_ID();
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table">
<thead>
<tr>
<th><?php _e( 'Season', 'sportspress' ); ?></th>
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<?php foreach ( $columns as $label ): ?>
<th><?php echo $label; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ( $data as $div_id => $div_stats ):
if ( !$div_id || $div_id == 'performance' ) continue;
$div = get_term( $div_id, 'sp_season' );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo $div->name; ?>
</td>
<td>
<?php
$value = sp_array_value( $leagues, $div_id, '-1' );
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']',
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $value,
'values' => 'ID',
'include' => $teams,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sp_league',
'terms' => $league_id,
'field' => 'id',
),
array(
'taxonomy' => 'sp_season',
'terms' => $div_id,
'field' => 'id',
),
),
);
if ( ! sp_dropdown_pages( $args ) ):
_e( 'No results found.', 'sportspress' );
endif;
?>
</td>
<?php foreach( $columns as $column => $label ):
?>
<td><?php
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, null );
$placeholder = sp_array_value( sp_array_value( $placeholders, $div_id, array() ), $column, 0 );
echo '<input type="text" name="sp_performance[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . $value . '" placeholder="' . $placeholder . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' />';
?></td>
<?php endforeach; ?>
</tr>
<?php
$i++;
endforeach;
?>
</tbody>
</table>
</div>
<?php
}
}

View File

@@ -32,9 +32,10 @@ class SP_Meta_Box_Player_Statistics {
<?php
endif;
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = sp_get_player_statistics_data( $post->ID, $league->term_id, true );
$player = new SP_Player( $post );
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
sp_edit_player_statistics_table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_teams' ) );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_teams' ) );
endforeach; else:
@@ -51,4 +52,82 @@ class SP_Meta_Box_Player_Statistics {
if ( current_user_can( 'edit_sp_teams' ) )
update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) );
}
/**
* Admin edit table
*/
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) {
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table">
<thead>
<tr>
<th><?php _e( 'Season', 'sportspress' ); ?></th>
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<?php foreach ( $columns as $label ): ?>
<th><?php echo $label; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ( $data as $div_id => $div_stats ):
if ( !$div_id || $div_id == 'statistics' ) continue;
$div = get_term( $div_id, 'sp_season' );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo $div->name; ?>
</td>
<td>
<?php
$value = sp_array_value( $leagues, $div_id, '-1' );
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']',
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $value,
'values' => 'ID',
'include' => $teams,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sp_league',
'terms' => $league_id,
'field' => 'id',
),
array(
'taxonomy' => 'sp_season',
'terms' => $div_id,
'field' => 'id',
),
),
);
if ( ! sp_dropdown_pages( $args ) ):
_e( 'No results found.', 'sportspress' );
endif;
?>
</td>
<?php foreach( $columns as $column => $label ):
?>
<td><?php
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, null );
$placeholder = sp_array_value( sp_array_value( $placeholders, $div_id, array() ), $column, 0 );
echo '<input type="text" name="sp_statistics[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . $value . '" placeholder="' . $placeholder . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' />';
?></td>
<?php endforeach; ?>
</tr>
<?php
$i++;
endforeach;
?>
</tbody>
</table>
</div>
<?php
}
}

View File

@@ -5,15 +5,18 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
/**
* SP_Meta_Box_Result_Details
*/
class SP_Meta_Box_Result_Details {
class SP_Meta_Box_Result_Details extends SP_Meta_Box_Config {
/**
* Output the metabox
@@ -28,11 +31,4 @@ class SP_Meta_Box_Result_Details {
</p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_delete_duplicate_post( $_POST );
}
}

View File

@@ -10,10 +10,13 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
/**
* SP_Meta_Box_Statistic_Details
*/
class SP_Meta_Box_Statistic_Details {
class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
/**
* Output the metabox
@@ -35,7 +38,7 @@ class SP_Meta_Box_Statistic_Details {
<p class="sp-equation-selector">
<?php
foreach ( $equation as $piece ):
sp_equation_selector( $post->ID, $piece, array( 'player_event', 'outcome', 'performance', 'metric' ) );
self::select( $post->ID, $piece, array( 'player_event', 'outcome', 'performance', 'metric' ) );
endforeach;
?>
</p>
@@ -50,8 +53,9 @@ class SP_Meta_Box_Statistic_Details {
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_delete_duplicate_post( $_POST );
self::delete_duplicate( $_POST );
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
}
}

View File

@@ -19,7 +19,7 @@ class SP_Meta_Box_Table_Data {
* Output the metabox
*/
public static function output( $post ) {
$table = new SP_Table( $post );
$table = new SP_League_Table( $post );
list( $columns, $usecolumns, $data, $placeholders, $merged ) = $table->data( true );
$adjustments = $table->adjustments;
self::table( $columns, $usecolumns, $data, $placeholders, $adjustments );

View File

@@ -34,9 +34,11 @@ class SP_Meta_Box_Team_Columns {
<?php
endif;
list( $columns, $data, $placeholders, $merged, $leagues_seasons ) = sp_get_team_columns_data( $post->ID, $league_id, true );
$team = new SP_Team( $post );
sp_edit_team_columns_table( $league_id, $columns, $data, $placeholders, $merged, $leagues_seasons, ! current_user_can( 'edit_sp_tables' ) );
list( $columns, $data, $placeholders, $merged, $leagues_seasons ) = $team->data( $league_id, true );
self::table( $league_id, $columns, $data, $placeholders, $merged, $leagues_seasons, ! current_user_can( 'edit_sp_tables' ) );
endforeach; else:
@@ -53,4 +55,54 @@ class SP_Meta_Box_Team_Columns {
if ( current_user_can( 'edit_sp_tables' ) )
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
}
/**
* Admin edit table
*/
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">
<thead>
<tr>
<th class="check-column"><input class="sp-select-all" type="checkbox"></th>
<th><?php _e( 'Season', 'sportspress' ); ?></th>
<?php foreach ( $columns as $label ): ?>
<th><?php echo $label; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ( $data as $div_id => $div_stats ):
if ( !$div_id ) continue;
$div = get_term( $div_id, 'sp_season' );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<input type="checkbox" name="sp_leagues[<?php echo $league_id; ?>][<?php echo $div_id; ?>]" id="sp_leagues_<?php echo $league_id; ?>_<?php echo $div_id; ?>" value="1" <?php checked( sp_array_value( $seasons, $div_id, 0 ), 1 ); ?>>
</td>
<td>
<label for="sp_leagues_<?php echo $league_id; ?>_<?php echo $div_id; ?>"><?php echo $div->name; ?></label>
</td>
<?php foreach( $columns as $column => $label ):
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, 0 );
?>
<td><?php
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, null );
$placeholder = sp_array_value( sp_array_value( $placeholders, $div_id, array() ), $column, 0 );
echo '<input type="text" name="sp_columns[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . $value . '" placeholder="' . $placeholder . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' />';
?></td>
<?php endforeach; ?>
</tr>
<?php
$i++;
endforeach;
?>
</tbody>
</table>
</div>
<?php
}
}