Add abbreviation to event outcomes

This commit is contained in:
Brian Miyaji
2014-06-25 12:49:43 +10:00
parent 743d60c6ec
commit e0852ae9aa
8 changed files with 66 additions and 18 deletions

View File

@@ -77,6 +77,7 @@ class SP_Admin_Sports {
$post = self::get_post_array( $outcome, $post_type );
if ( empty( $post ) ) continue;
$id = self::insert_preset_post( $post, $index );
update_post_meta( $id, 'sp_abbreviation', sp_array_value( $outcome, 'abbreviation', null ) );
}
// Results

View File

@@ -42,6 +42,7 @@ class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_outcome_admin_columns', $columns );
@@ -57,6 +58,10 @@ class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
global $post;
echo $post->post_name;
break;
case 'sp_abbreviation':
global $post;
echo sp_get_post_abbreviation( $post->ID );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . $post->post_excerpt . '</span>';

View File

@@ -23,12 +23,24 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
?>
<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; ?>">
</p>
<p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_abbreviation" type="text" id="sp_abbreviation" value="<?php echo $abbreviation; ?>" placeholder="<?php echo substr( $post->post_title, 0, 1 ); ?>">
</p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_abbreviation', sp_array_value( $_POST, 'sp_abbreviation', array() ) );
}
}

View File

@@ -106,6 +106,7 @@ class SP_Settings_Config extends SP_Settings_Page {
<tr>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Variable', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Abbreviation', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Description', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
@@ -114,6 +115,7 @@ class SP_Settings_Config extends SP_Settings_Page {
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo $row->post_name; ?></td>
<td><?php echo sp_get_post_abbreviation( $row->ID ); ?></td>
<td><p class="description"><?php echo $row->post_excerpt; ?></p></td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>

View File

@@ -5,7 +5,7 @@
* The SportsPress league table class handles individual league table data.
*
* @class SP_League_Table
* @version 1.1
* @version 1.1.2
* @package SportsPress/Classes
* @category Class
* @author ThemeBoy
@@ -182,13 +182,18 @@ class SP_League_Table extends SP_Custom_Post{
'name' => $streak['name'],
'post_type' => 'sp_outcome',
'post_status' => 'publish',
'posts_per_page' => 1
'posts_per_page' => 1,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$outcomes = get_posts( $args );
if ( $outcomes ):
$outcome = reset( $outcomes );
$totals[ $team_id ]['streak'] = $outcome->post_title . $streak['count'];
$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'];
else:
$totals[ $team_id ]['streak'] = null;
endif;
@@ -262,6 +267,7 @@ class SP_League_Table extends SP_Custom_Post{
// Solve
$placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision );
if ( ! in_array( $stat->equation, array( '$streak', '$last5', '$last10' ) ) ):
// Adjustments
$adjustment = sp_array_value( $adjustments, $team_id, array() );
@@ -270,6 +276,7 @@ class SP_League_Table extends SP_Custom_Post{
$placeholder = number_format( $placeholder, $stat->precision );
endif;
endif;
endif;
$placeholders[ $team_id ][ $stat->post_name ] = $placeholder;
endif;

View File

@@ -197,13 +197,18 @@ class SP_Team extends SP_Custom_Post {
'name' => $streak['name'],
'post_type' => 'sp_outcome',
'post_status' => 'publish',
'posts_per_page' => 1
'posts_per_page' => 1,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$outcomes = get_posts( $args );
if ( $outcomes ):
$outcome = reset( $outcomes );
$totals['streak'] = $outcome->post_title . $streak['count'];
$abbreviation = get_post_meta( $outcome->ID, 'sp_abbreviation', true );
if ( ! $abbreviation )
$abbreviation = substr( $outcome->post_title, 0, 1 );
$totals['streak'] = $abbreviation . $streak['count'];
endif;
// Add last counters to totals

View File

@@ -283,7 +283,7 @@ if ( !function_exists( 'sp_array_combine' ) ) {
if ( !function_exists( 'sp_numbers_to_words' ) ) {
function sp_numbers_to_words( $str ) {
$output = str_replace( array( '1st', '2nd', '3rd', '5th', '8th', '9th', '10', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ), array( 'first', 'second', 'third', 'fifth', 'eight', 'ninth', 'ten', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ), $str );
$output = str_replace( array( '%', '1st', '2nd', '3rd', '5th', '8th', '9th', '10', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ), array( 'percent', 'first', 'second', 'third', 'fifth', 'eight', 'ninth', 'ten', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ), $str );
return $output;
}
}
@@ -311,6 +311,17 @@ if ( !function_exists( 'sp_get_url' ) ) {
}
}
if ( !function_exists( 'sp_get_post_abbreviation' ) ) {
function sp_get_post_abbreviation( $post_id ) {
$abbreviation = get_post_meta ( $post_id, 'sp_abbreviation', true );
if ( $abbreviation ):
return $abbreviation;
else:
return substr( get_the_title( $post_id ), 0, 1 );
endif;
}
}
if ( !function_exists( 'sp_get_post_precision' ) ) {
function sp_get_post_precision( $post_id ) {
$precision = get_post_meta ( $post_id, 'sp_precision', true );
@@ -975,14 +986,19 @@ if ( !function_exists( 'sp_solve' ) ) {
if ( ! array_key_exists( preg_replace( "/[^a-z]/", '', $value ), $vars ) )
return 0;
endif;
$pos = strpos( $equation, '/' );
if ( $pos ):
if ( $eos->solveIF( substr( $equation, $pos + 2 ), $vars ) == 0 )
return 0;
endif;
endforeach;
// Remove space between equation parts
$equation = str_replace( ' ', '', $equation );
// Check if denominator is zero
$pos = strpos( $equation, '/' );
if ( $pos ):
if ( $eos->solveIF( substr( $equation, $pos + 1 ), $vars ) == 0 )
return 0;
endif;
// Return solution
return number_format( $eos->solveIF( str_replace( ' ', '', $equation ), $vars ), $precision );
}

View File

@@ -3,7 +3,7 @@
"outcomes": [
"Win",
"Loss",
"Overtime Loss"
{ "name" : "Overtime loss", "abbreviation" : "OT" }
],
"results": [
{ "name" : "1st", "description" : "1st period goals" },