Add chronological streak format to league table column equation generator
This commit is contained in:
@@ -417,6 +417,24 @@
|
||||
font-size: 36px;
|
||||
}
|
||||
|
||||
/* Event Form */
|
||||
.sp-form-events {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.sp-form-event-link {
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
width: 1.5em;
|
||||
margin: 0 0 0.25em;
|
||||
color: #fff;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.sp-form-event-link:hover {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* Countdowns */
|
||||
.sp-template-countdown .event-name {
|
||||
clear: both;
|
||||
|
||||
26
assets/js/admin/colorpicker.js
Normal file
26
assets/js/admin/colorpicker.js
Normal file
@@ -0,0 +1,26 @@
|
||||
jQuery(document).ready(function($){
|
||||
|
||||
// Color picker
|
||||
$('.colorpick').iris( {
|
||||
change: function(event, ui){
|
||||
$(this).css( { backgroundColor: ui.color.toString() } );
|
||||
},
|
||||
hide: true,
|
||||
border: true
|
||||
} ).each( function() {
|
||||
$(this).css( { backgroundColor: $(this).val() } );
|
||||
})
|
||||
.click(function(){
|
||||
$('.iris-picker').hide();
|
||||
$(this).closest('.sp-color-box, td').find('.iris-picker').show();
|
||||
});
|
||||
|
||||
$('body').click(function() {
|
||||
$('.iris-picker').hide();
|
||||
});
|
||||
|
||||
$('.sp-color-box, .colorpick').click(function(event){
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -94,6 +94,8 @@ class SP_Admin_Assets {
|
||||
|
||||
wp_register_script( 'sportspress-admin-equationbuilder', SP()->plugin_url() . '/assets/js/admin/equationbuilder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable' ), SP_VERSION, true );
|
||||
|
||||
wp_register_script( 'sportspress-admin-colorpicker', SP()->plugin_url() . '/assets/js/admin/colorpicker.js', array( 'jquery', 'wp-color-picker', 'iris' ), SP_VERSION, true );
|
||||
|
||||
wp_register_script( 'sportspress-admin-widgets', SP()->plugin_url() . '/assets/js/admin/widgets.js', array( 'jquery' ), SP_VERSION, true );
|
||||
|
||||
wp_register_script( 'sportspress-admin-quickeditor', SP()->plugin_url() . '/assets/js/admin/quickeditor.js', array( 'jquery' ), SP_VERSION, true );
|
||||
@@ -137,6 +139,11 @@ class SP_Admin_Assets {
|
||||
wp_enqueue_script( 'sportspress-admin-locationpicker' );
|
||||
}
|
||||
|
||||
// Edit color
|
||||
if ( in_array( $screen->id, array( 'sp_outcome' ) ) ) {
|
||||
wp_enqueue_script( 'sportspress-admin-colorpicker' );
|
||||
}
|
||||
|
||||
// Edit equation
|
||||
if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) {
|
||||
wp_enqueue_script( 'sportspress-admin-equationbuilder' );
|
||||
|
||||
@@ -43,7 +43,7 @@ class SP_Meta_Box_Equation {
|
||||
$options[ 'Outcomes' ] = self::optgroup( 'sp_outcome' );
|
||||
break;
|
||||
case 'preset':
|
||||
$options[ 'Presets' ] = array( '$gamesback' => __( 'Games Back', 'sportspress' ), '$homerecord' => __( 'Home Record', 'sportspress' ), '$awayrecord' => __( 'Away Record', 'sportspress' ), '$streak' => __( 'Streak', 'sportspress' ), '$last5' => __( 'Last 5', 'sportspress' ), '$last10' => __( 'Last 10', 'sportspress' ) );
|
||||
$options[ 'Presets' ] = array( '$gamesback' => __( 'Games Back', 'sportspress' ), '$homerecord' => __( 'Home Record', 'sportspress' ), '$awayrecord' => __( 'Away Record', 'sportspress' ), '$streak' => __( 'Streak', 'sportspress' ), '$form' => __( 'Form', 'sportspress' ), '$last5' => __( 'Last 5', 'sportspress' ), '$last10' => __( 'Last 10', 'sportspress' ) );
|
||||
break;
|
||||
case 'subset':
|
||||
$options[ 'Subsets' ] = array( '_home' => '@' . __( 'Home', 'sportspress' ), '_away' => '@' . __( 'Away', 'sportspress' ), '_venue' => '@' . __( 'Venue', 'sportspress' ) );
|
||||
|
||||
@@ -30,10 +30,13 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
|
||||
$readonly = false;
|
||||
}
|
||||
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
|
||||
$color = get_post_meta( $post->ID, 'sp_color', true );
|
||||
$condition = get_post_meta( $post->ID, 'sp_condition', true );
|
||||
$main_result = get_option( 'sportspress_primary_result', null );
|
||||
$result = get_page_by_path( $main_result, ARRAY_A, 'sp_result' );
|
||||
$label = sp_array_value( $result, 'post_title', __( 'Primary', 'sportspress' ) );
|
||||
|
||||
if ( '' === $color ) $color = '#888888';
|
||||
?>
|
||||
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
@@ -44,6 +47,13 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
|
||||
<p>
|
||||
<input name="sp_abbreviation" type="text" id="sp_abbreviation" value="<?php echo $abbreviation; ?>" placeholder="<?php echo substr( $post->post_title, 0, 1 ); ?>">
|
||||
</p>
|
||||
<p><strong><?php _e( 'Color', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<div class="sp-color-box">
|
||||
<input name="sp_color" id="sp_color" type="text" value="<?php echo $color; ?>" class="colorpick">
|
||||
<div id="sp_color" class="colorpickdiv"></div>
|
||||
</div>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Condition', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<select name="sp_condition">
|
||||
@@ -72,6 +82,7 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_abbreviation', sp_array_value( $_POST, 'sp_abbreviation', array() ) );
|
||||
update_post_meta( $post_id, 'sp_color', sp_array_value( $_POST, 'sp_color', array() ) );
|
||||
update_post_meta( $post_id, 'sp_condition', sp_array_value( $_POST, 'sp_condition', array() ) );
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,8 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
|
||||
$select = get_post_meta( $this->ID, 'sp_select', true );
|
||||
$abbreviate_teams = get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false;
|
||||
$link_events = get_option( 'sportspress_link_events', 'yes' ) === 'yes' ? true : false;
|
||||
$form_limit = (int) get_option( 'sportspress_form_limit', 5 );
|
||||
|
||||
// Get labels from result variables
|
||||
$result_labels = (array)sp_get_var_labels( 'sp_result' );
|
||||
@@ -101,6 +103,9 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
// Initialize streaks counter
|
||||
$streaks = array();
|
||||
|
||||
// Initialize form counter
|
||||
$forms = array();
|
||||
|
||||
// Initialize last counters
|
||||
$last5s = array();
|
||||
$last10s = array();
|
||||
@@ -116,6 +121,9 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
// Initialize team streaks counter
|
||||
$streaks[ $team_id ] = array( 'name' => '', 'count' => 0, 'fire' => 1 );
|
||||
|
||||
// Initialize team form counter
|
||||
$forms[ $team_id ] = array();
|
||||
|
||||
// Initialize team last counters
|
||||
$last5s[ $team_id ] = array();
|
||||
$last10s[ $team_id ] = array();
|
||||
@@ -280,6 +288,12 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
$streaks[ $team_id ]['fire'] = 0;
|
||||
endif;
|
||||
|
||||
// Add to form counter
|
||||
$forms[ $team_id ][] = array(
|
||||
'id' => $event->ID,
|
||||
'outcome' => $outcome,
|
||||
);
|
||||
|
||||
// Add to last 5 counter if sum is less than 5
|
||||
if ( array_key_exists( $team_id, $last5s ) && array_key_exists( $outcome, $last5s[ $team_id ] ) && array_sum( $last5s[ $team_id ] ) < 5 ):
|
||||
$last5s[ $team_id ][ $outcome ] ++;
|
||||
@@ -352,26 +366,50 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
$e++;
|
||||
|
||||
endforeach;
|
||||
|
||||
// Get outcomes
|
||||
$outcomes = array();
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => -1,
|
||||
);
|
||||
$posts = get_posts( $args );
|
||||
|
||||
if ( $posts ):
|
||||
foreach ( $posts as $post ):
|
||||
// Get ID
|
||||
$id = $post->ID;
|
||||
|
||||
// Get title
|
||||
$title = $post->post_title;
|
||||
|
||||
// Get abbreviation
|
||||
$abbreviation = get_post_meta( $id, 'sp_abbreviation', true );
|
||||
if ( ! $abbreviation ):
|
||||
$abbreviation = substr( $title, 0, 1 );
|
||||
endif;
|
||||
|
||||
// Get color
|
||||
$color = get_post_meta( $id, 'sp_color', true );
|
||||
if ( '' === $color ) $color = '#888888';
|
||||
|
||||
$outcomes[ $post->post_name ] = array(
|
||||
'id' => $id,
|
||||
'title' => $title,
|
||||
'abbreviation' => $abbreviation,
|
||||
'color' => $color,
|
||||
);
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
foreach ( $streaks as $team_id => $streak ):
|
||||
// Compile streaks counter and add to totals
|
||||
if ( $streak['name'] ):
|
||||
$args = array(
|
||||
'name' => $streak['name'],
|
||||
'post_type' => 'sp_outcome',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
$outcomes = get_posts( $args );
|
||||
|
||||
if ( $outcomes ):
|
||||
$outcome = reset( $outcomes );
|
||||
$abbreviation = get_post_meta( $outcome->ID, 'sp_abbreviation', true );
|
||||
if ( ! $abbreviation )
|
||||
$abbreviation = substr( $outcome->post_title, 0, 1 );
|
||||
$totals[ $team_id ]['streak'] = $abbreviation . $streak['count'];
|
||||
$outcome = sp_array_value( $outcomes, $streak['name'], false );
|
||||
if ( $outcome ):
|
||||
$totals[ $team_id ]['streak'] = $outcome['abbreviation'] . $streak['count'];
|
||||
else:
|
||||
$totals[ $team_id ]['streak'] = null;
|
||||
endif;
|
||||
@@ -380,6 +418,42 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
foreach ( $forms as $team_id => $form ):
|
||||
// Apply form limit
|
||||
if ( $form_limit && sizeof( $form ) > $form_limit ):
|
||||
$form = array_slice( $form, 0, $form_limit );
|
||||
endif;
|
||||
|
||||
// Initialize team form array
|
||||
$team_form = array();
|
||||
|
||||
// Loop through event form
|
||||
foreach ( $form as $form_event ):
|
||||
if ( $form_event['id'] ):
|
||||
$outcome = sp_array_value( $outcomes, $form_event['outcome'], false );
|
||||
if ( $outcome ):
|
||||
$abbreviation = $outcome['abbreviation'];
|
||||
$color = $outcome['color'];
|
||||
if ( $link_events ):
|
||||
$abbreviation = '<a class="sp-form-event-link" href="' . get_post_permalink( $form_event['id'], false, true ) . '" style="background-color:' . $color . '">' . $abbreviation . '</a>';
|
||||
else:
|
||||
$abbreviation = '<span class="sp-form-event-link" style="background-color:' . $color . '">' . $abbreviation . '</span>';
|
||||
endif;
|
||||
|
||||
// Add to team form
|
||||
$team_form[] = $abbreviation;
|
||||
endif;
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
// Append to totals
|
||||
if ( sizeof( $team_form ) ):
|
||||
$totals[ $team_id ]['form'] = '<div class="sp-form-events">' . implode( ' ', $team_form ) . '</div>';
|
||||
else:
|
||||
$totals[ $team_id ]['form'] = null;
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
foreach ( $last5s as $team_id => $last5 ):
|
||||
// Add last 5 to totals
|
||||
$totals[ $team_id ]['last5'] = $last5;
|
||||
@@ -461,7 +535,7 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
if ( '$gamesback' == $stat->equation )
|
||||
$gb_column = $stat->post_name;
|
||||
|
||||
if ( ! in_array( $stat->equation, array( '$gamesback', '$streak', '$last5', '$last10', '$homerecord', '$awayrecord' ) ) ):
|
||||
if ( ! in_array( $stat->equation, array( '$gamesback', '$streak', '$form', '$last5', '$last10', '$homerecord', '$awayrecord' ) ) ):
|
||||
// Adjustments
|
||||
$adjustment = sp_array_value( $adjustments, $team_id, array() );
|
||||
|
||||
|
||||
@@ -1161,6 +1161,11 @@ if ( !function_exists( 'sp_solve' ) ) {
|
||||
// Return direct value
|
||||
return sp_array_value( $vars, 'streak', $default );
|
||||
|
||||
elseif ( strpos( $equation, '$form' ) !== false ):
|
||||
|
||||
// Return direct value
|
||||
return sp_array_value( $vars, 'form', $default );
|
||||
|
||||
elseif ( strpos( $equation, '$last5' ) !== false ):
|
||||
|
||||
// Return imploded string
|
||||
|
||||
@@ -255,6 +255,19 @@ class SportsPress_League_Tables {
|
||||
'step' => 1
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Form', 'sportspress' ),
|
||||
'id' => 'sportspress_form_limit',
|
||||
'class' => 'small-text',
|
||||
'default' => '5',
|
||||
'desc' => __( 'events', 'sportspress' ),
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 1,
|
||||
'step' => 1
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Pos', 'sportspress' ),
|
||||
|
||||
Reference in New Issue
Block a user