Add offense and defense option to player performance

This commit is contained in:
Brian Miyaji
2016-02-17 01:58:46 +11:00
parent ab30b88785
commit 3dfb3f9f92
8 changed files with 305 additions and 221 deletions

View File

@@ -166,6 +166,7 @@ class SP_Admin_Sports {
}
update_post_meta( $id, 'sp_icon', sp_array_value( $performance, 'icon', null ) );
update_post_meta( $id, 'sp_color', sp_array_value( $performance, 'color', null ) );
update_post_meta( $id, 'sp_section', sp_array_value( $performance, 'section', -1 ) );
$i ++;
}

View File

@@ -62,19 +62,58 @@ class SP_Meta_Box_Event_Teams {
}
?>
</p>
<?php $tabs = apply_filters( 'sportspress_event_team_tabs', array( 'sp_player', 'sp_staff' ) ); ?>
<?php
$tabs = array();
$sections = get_option( 'sportspress_event_performance_sections', -1 );
if ( 0 == $sections ) {
$tabs['sp_offense'] = array(
'label' => __( 'Offense', 'sportspress' ),
'post_type' => 'sp_player',
);
$tabs['sp_defense'] = array(
'label' => __( 'Defense', 'sportspress' ),
'post_type' => 'sp_player',
);
} elseif ( 1 == $sections ) {
$tabs['sp_defense'] = array(
'label' => __( 'Defense', 'sportspress' ),
'post_type' => 'sp_player',
);
$tabs['sp_offense'] = array(
'label' => __( 'Offense', 'sportspress' ),
'post_type' => 'sp_player',
);
} else {
$tabs['sp_player'] = array(
'label' => __( 'Players', 'sportspress' ),
'post_type' => 'sp_player',
);
}
$tabs['sp_staff'] = array(
'label' => __( 'Staff', 'sportspress' ),
'post_type' => 'sp_staff',
);
?>
<?php if ( $tabs ) { ?>
<ul id="sp_team-tabs" class="wp-tab-bar sp-tab-bar">
<?php foreach ( $tabs as $index => $post_type ) { $object = get_post_type_object( $post_type ); ?>
<li class="wp-tab<?php if ( 0 == $index ) { ?>-active<?php } ?>"><a href="#<?php echo $post_type; ?>-all"><?php echo $object->labels->name; ?></a></li>
<?php } ?>
<?php
$j = 0;
foreach ( $tabs as $slug => $tab ) {
?>
<li class="wp-tab<?php if ( 0 == $j ) { ?>-active<?php } ?>"><a href="#<?php echo $slug; ?>-all"><?php echo $tab['label']; ?></a></li>
<?php
$j++;
}
?>
</ul>
<?php
foreach ( $tabs as $index => $post_type ) {
do_action( 'sportspress_event_teams_meta_box_checklist', $post->ID, $post_type, ( 0 == $index ? 'block' : 'none' ), $team, $i );
$j = 0;
foreach ( $tabs as $slug => $tab ) {
do_action( 'sportspress_event_teams_meta_box_checklist', $post->ID, $tab['post_type'], ( 0 == $j ? 'block' : 'none' ), $team, $i, $slug );
if ( apply_filters( 'sportspress_event_teams_meta_box_default_checklist', true ) ) {
sp_post_checklist( $post->ID, $post_type, ( 0 == $index ? 'block' : 'none' ), array( 'sp_league', 'sp_season', 'sp_current_team' ), $i );
sp_post_checklist( $post->ID, $tab['post_type'], ( 0 == $j ? 'block' : 'none' ), array( 'sp_league', 'sp_season', 'sp_current_team' ), $i, $slug );
}
$j++;
}
?>
<?php } ?>
@@ -107,11 +146,16 @@ class SP_Meta_Box_Event_Teams {
*/
public static function save( $post_id, $post ) {
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
$tabs = apply_filters( 'sportspress_event_team_tabs', array( 'sp_player', 'sp_staff' ) );
if ( $tabs ) {
foreach ( $tabs as $post_type ) {
sp_update_post_meta_recursive( $post_id, $post_type, sp_array_value( $_POST, $post_type, array() ) );
}
$tabs = array();
$sections = get_option( 'sportspress_event_performance_sections', -1 );
if ( -1 == $sections ) {
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
} else {
$players = array_merge( sp_array_value( $_POST, 'sp_offense', array() ), sp_array_value( $_POST, 'sp_defense', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_offense', sp_array_value( $_POST, 'sp_offense', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_defense', sp_array_value( $_POST, 'sp_defense', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_player', $players );
}
sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) );
}
}

View File

@@ -29,12 +29,51 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
} else {
$readonly = false;
}
$section = get_post_meta( $post->ID, 'sp_section', true );
if ( '' === $section ) {
$section = -1;
}
$format = get_post_meta( $post->ID, 'sp_format', true );
if ( '' === $format ) {
$format = 'number';
}
?>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>"<?php if ( $readonly ) { ?> readonly="readonly"<?php } ?>>
</p>
<p><strong><?php _e( 'Category', 'sportspress' ); ?></strong></p>
<p class="sp-section-selector">
<select name="sp_section">
<?php
$options = apply_filters( 'sportspress_performance_sections', array( -1 => __( 'All', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $section ), $value );
endforeach;
?>
</select>
</p>
<p><strong><?php _e( 'Format', 'sportspress' ); ?></strong></p>
<p class="sp-format-selector">
<select name="sp_format">
<?php
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format ), $value );
endforeach;
?>
</select>
</p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
self::delete_duplicate( $_POST );
update_post_meta( $post_id, 'sp_section', (int) sp_array_value( $_POST, 'sp_section', -1 ) );
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'number' ) );
}
}

View File

@@ -371,19 +371,15 @@ class SP_Settings_Events extends SP_Settings_Page {
),
array(
'desc' => __( 'Split players by team', 'sportspress' ),
'id' => 'sportspress_event_split_players_by_team',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Split players by position', 'sportspress' ),
'id' => 'sportspress_event_split_players_by_position',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'title' => __( 'Performance', 'sportspress' ),
'id' => 'sportspress_event_performance_sections',
'default' => -1,
'type' => 'radio',
'options' => array(
-1 => __( 'Combined', 'sportspress' ),
0 => __( 'Offense', 'sportspress' ) . ' &rarr; ' . __( 'Defense', 'sportspress' ),
1 => __( 'Defense', 'sportspress' ) . ' &rarr; ' . __( 'Offense', 'sportspress' ),
),
),
array(

View File

@@ -449,6 +449,41 @@ if ( !function_exists( 'sp_get_post_order' ) ) {
}
}
if ( !function_exists( 'sp_get_post_section' ) ) {
function sp_get_post_section( $post_id ) {
$section = get_post_meta ( $post_id, 'sp_section', true );
if ( isset( $section ) ):
$options = apply_filters( 'sportspress_performance_sections', array( -1 => __( 'All', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
return sp_array_value( $options, $section, __( 'All', 'sportspress' ) );
else:
return __( 'All', 'sportspress' );
endif;
}
}
if ( !function_exists( 'sp_get_post_format' ) ) {
function sp_get_post_format( $post_id ) {
$format = get_post_meta ( $post_id, 'sp_format', true );
if ( isset( $format ) ):
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'time' => __( 'Time', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ) ) );
return sp_array_value( $options, $format, __( 'Number', 'sportspress' ) );
else:
return __( 'Number', 'sportspress' );
endif;
}
}
if ( !function_exists( 'sp_get_format_placeholder' ) ) {
function sp_get_format_placeholder( $key = 'number' ) {
$placeholders = apply_filters( 'sportspress_format_placeholders', array(
'number' => 0,
'time' => '0:00',
'text' => '',
) );
return sp_array_value( $placeholders, $key, 0 );
}
}
if ( !function_exists( 'sp_dropdown_statuses' ) ) {
function sp_dropdown_statuses( $args = array() ) {
$defaults = array(
@@ -786,12 +821,14 @@ if ( !function_exists( 'sp_posts' ) ) {
}
if ( !function_exists( 'sp_post_checklist' ) ) {
function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filters = null, $index = null ) {
function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filters = null, $index = null, $slug = null ) {
if ( ! isset( $post_id ) )
global $post_id;
if ( ! isset( $slug ) )
$slug = $meta;
?>
<div id="<?php echo $meta; ?>-all" class="posttypediv wp-tab-panel sp-tab-panel sp-tab-filter-panel sp-select-all-range" style="display: <?php echo $display; ?>;">
<input type="hidden" value="0" name="<?php echo $meta; ?><?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]" />
<div id="<?php echo $slug; ?>-all" class="posttypediv wp-tab-panel sp-tab-panel sp-tab-filter-panel sp-select-all-range" style="display: <?php echo $display; ?>;">
<input type="hidden" value="0" name="<?php echo $slug; ?><?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]" />
<ul class="categorychecklist form-no-clear">
<li class="sp-select-all-container"><label class="selectit"><input type="checkbox" class="sp-select-all"> <strong><?php _e( 'Select All', 'sportspress' ); ?></strong></label></li>
<?php
@@ -844,7 +881,7 @@ if ( !function_exists( 'sp_post_checklist' ) ) {
?>">
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
<label class="selectit">
<input type="checkbox" value="<?php echo $post->ID; ?>" name="<?php echo $meta; ?><?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
<input type="checkbox" value="<?php echo $post->ID; ?>" name="<?php echo $slug; ?><?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
<?php echo sp_get_player_name_with_number( $post->ID ); ?>
</label>
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>
@@ -854,10 +891,10 @@ if ( !function_exists( 'sp_post_checklist' ) ) {
?>
<li class="sp-not-found-container">
<?php _e( 'No results found.', 'sportspress' ); ?>
<?php if ( sizeof( $posts ) ): ?><a class="sp-show-all" href="#show-all-<?php echo $meta; ?>s"><?php _e( 'Show all', 'sportspress' ); ?></a><?php endif; ?>
<?php if ( sizeof( $posts ) ): ?><a class="sp-show-all" href="#show-all-<?php echo $slug; ?>s"><?php _e( 'Show all', 'sportspress' ); ?></a><?php endif; ?>
</li>
<?php if ( sizeof( $posts ) ): ?>
<li class="sp-show-all-container"><a class="sp-show-all" href="#show-all-<?php echo $meta; ?>s"><?php _e( 'Show all', 'sportspress' ); ?></a></li>
<li class="sp-show-all-container"><a class="sp-show-all" href="#show-all-<?php echo $slug; ?>s"><?php _e( 'Show all', 'sportspress' ); ?></a></li>
<?php endif; ?>
</ul>
</div>
@@ -882,6 +919,10 @@ if ( !function_exists( 'sp_column_checklist' ) ) {
endif;
if ( sizeof( $posts ) ):
foreach ( $posts as $post ):
if ( 'sp_performance' == $meta ) {
$format = get_post_meta( $post->ID, 'sp_format', true );
if ( 'text' === $format ) continue;
}
?>
<li class="sp-post">
<label class="selectit">