Add abbreviation to event outcomes
This commit is contained in:
@@ -77,6 +77,7 @@ class SP_Admin_Sports {
|
|||||||
$post = self::get_post_array( $outcome, $post_type );
|
$post = self::get_post_array( $outcome, $post_type );
|
||||||
if ( empty( $post ) ) continue;
|
if ( empty( $post ) ) continue;
|
||||||
$id = self::insert_preset_post( $post, $index );
|
$id = self::insert_preset_post( $post, $index );
|
||||||
|
update_post_meta( $id, 'sp_abbreviation', sp_array_value( $outcome, 'abbreviation', null ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Results
|
// Results
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
|
|||||||
'cb' => '<input type="checkbox" />',
|
'cb' => '<input type="checkbox" />',
|
||||||
'title' => __( 'Label', 'sportspress' ),
|
'title' => __( 'Label', 'sportspress' ),
|
||||||
'sp_key' => __( 'Variable', 'sportspress' ),
|
'sp_key' => __( 'Variable', 'sportspress' ),
|
||||||
|
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
|
||||||
'sp_description' => __( 'Description', 'sportspress' ),
|
'sp_description' => __( 'Description', 'sportspress' ),
|
||||||
);
|
);
|
||||||
return apply_filters( 'sportspress_outcome_admin_columns', $columns );
|
return apply_filters( 'sportspress_outcome_admin_columns', $columns );
|
||||||
@@ -57,6 +58,10 @@ class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
|
|||||||
global $post;
|
global $post;
|
||||||
echo $post->post_name;
|
echo $post->post_name;
|
||||||
break;
|
break;
|
||||||
|
case 'sp_abbreviation':
|
||||||
|
global $post;
|
||||||
|
echo sp_get_post_abbreviation( $post->ID );
|
||||||
|
break;
|
||||||
case 'sp_description':
|
case 'sp_description':
|
||||||
global $post;
|
global $post;
|
||||||
echo '<span class="description">' . $post->post_excerpt . '</span>';
|
echo '<span class="description">' . $post->post_excerpt . '</span>';
|
||||||
|
|||||||
@@ -23,12 +23,24 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
|
|||||||
*/
|
*/
|
||||||
public static function output( $post ) {
|
public static function output( $post ) {
|
||||||
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
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><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
|
||||||
<p>
|
<p>
|
||||||
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
|
<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; ?>">
|
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
|
||||||
</p>
|
</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
|
<?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() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -106,6 +106,7 @@ class SP_Settings_Config extends SP_Settings_Page {
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||||
<th scope="col"><?php _e( 'Variable', '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"><?php _e( 'Description', 'sportspress' ); ?></th>
|
||||||
<th scope="col" class="edit"></th>
|
<th scope="col" class="edit"></th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -114,6 +115,7 @@ class SP_Settings_Config extends SP_Settings_Page {
|
|||||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||||
<td><?php echo $row->post_name; ?></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><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>
|
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* The SportsPress league table class handles individual league table data.
|
* The SportsPress league table class handles individual league table data.
|
||||||
*
|
*
|
||||||
* @class SP_League_Table
|
* @class SP_League_Table
|
||||||
* @version 1.1
|
* @version 1.1.2
|
||||||
* @package SportsPress/Classes
|
* @package SportsPress/Classes
|
||||||
* @category Class
|
* @category Class
|
||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
@@ -182,13 +182,18 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
'name' => $streak['name'],
|
'name' => $streak['name'],
|
||||||
'post_type' => 'sp_outcome',
|
'post_type' => 'sp_outcome',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'posts_per_page' => 1
|
'posts_per_page' => 1,
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'order' => 'ASC',
|
||||||
);
|
);
|
||||||
$outcomes = get_posts( $args );
|
$outcomes = get_posts( $args );
|
||||||
|
|
||||||
if ( $outcomes ):
|
if ( $outcomes ):
|
||||||
$outcome = reset( $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:
|
else:
|
||||||
$totals[ $team_id ]['streak'] = null;
|
$totals[ $team_id ]['streak'] = null;
|
||||||
endif;
|
endif;
|
||||||
@@ -262,12 +267,14 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
// Solve
|
// Solve
|
||||||
$placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision );
|
$placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision );
|
||||||
|
|
||||||
// Adjustments
|
if ( ! in_array( $stat->equation, array( '$streak', '$last5', '$last10' ) ) ):
|
||||||
$adjustment = sp_array_value( $adjustments, $team_id, array() );
|
// Adjustments
|
||||||
|
$adjustment = sp_array_value( $adjustments, $team_id, array() );
|
||||||
|
|
||||||
if ( $adjustment != 0 ):
|
if ( $adjustment != 0 ):
|
||||||
$placeholder += sp_array_value( $adjustment, $stat->post_name, 0 );
|
$placeholder += sp_array_value( $adjustment, $stat->post_name, 0 );
|
||||||
$placeholder = number_format( $placeholder, $stat->precision );
|
$placeholder = number_format( $placeholder, $stat->precision );
|
||||||
|
endif;
|
||||||
endif;
|
endif;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
|||||||
@@ -197,13 +197,18 @@ class SP_Team extends SP_Custom_Post {
|
|||||||
'name' => $streak['name'],
|
'name' => $streak['name'],
|
||||||
'post_type' => 'sp_outcome',
|
'post_type' => 'sp_outcome',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'posts_per_page' => 1
|
'posts_per_page' => 1,
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'order' => 'ASC',
|
||||||
);
|
);
|
||||||
$outcomes = get_posts( $args );
|
$outcomes = get_posts( $args );
|
||||||
|
|
||||||
if ( $outcomes ):
|
if ( $outcomes ):
|
||||||
$outcome = reset( $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;
|
endif;
|
||||||
|
|
||||||
// Add last counters to totals
|
// Add last counters to totals
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ if ( !function_exists( 'sp_array_combine' ) ) {
|
|||||||
|
|
||||||
if ( !function_exists( 'sp_numbers_to_words' ) ) {
|
if ( !function_exists( 'sp_numbers_to_words' ) ) {
|
||||||
function sp_numbers_to_words( $str ) {
|
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;
|
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' ) ) {
|
if ( !function_exists( 'sp_get_post_precision' ) ) {
|
||||||
function sp_get_post_precision( $post_id ) {
|
function sp_get_post_precision( $post_id ) {
|
||||||
$precision = get_post_meta ( $post_id, 'sp_precision', true );
|
$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 ) )
|
if ( ! array_key_exists( preg_replace( "/[^a-z]/", '', $value ), $vars ) )
|
||||||
return 0;
|
return 0;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
$pos = strpos( $equation, '/' );
|
|
||||||
if ( $pos ):
|
|
||||||
if ( $eos->solveIF( substr( $equation, $pos + 2 ), $vars ) == 0 )
|
|
||||||
return 0;
|
|
||||||
endif;
|
|
||||||
endforeach;
|
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 );
|
return number_format( $eos->solveIF( str_replace( ' ', '', $equation ), $vars ), $precision );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"outcomes": [
|
"outcomes": [
|
||||||
"Win",
|
"Win",
|
||||||
"Loss",
|
"Loss",
|
||||||
"Overtime Loss"
|
{ "name" : "Overtime loss", "abbreviation" : "OT" }
|
||||||
],
|
],
|
||||||
"results": [
|
"results": [
|
||||||
{ "name" : "1st", "description" : "1st period goals" },
|
{ "name" : "1st", "description" : "1st period goals" },
|
||||||
|
|||||||
Reference in New Issue
Block a user