Add abbreviation to config post types and calculate streak
This commit is contained in:
@@ -132,17 +132,28 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th><?php _e( 'Label', 'sportspress' ); ?></th>
|
<th><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||||
<th><?php _e( 'Key', 'sportspress' ); ?></th>
|
<th><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||||
|
<th><?php _e( 'Abbreviation', 'sportspress' ); ?></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||||
<tr<?php if ( $i % 2 ) echo ' class="alternate"'; ?>>
|
<tr<?php if ( $i % 2 ) 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
|
||||||
|
$abbreviation = get_post_meta ( $row->ID, 'sp_abbreviation', true );
|
||||||
|
if ( $abbreviation ):
|
||||||
|
echo $abbreviation;
|
||||||
|
else:
|
||||||
|
echo $row->post_title;
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php $i++; endforeach; ?>
|
<?php $i++; endforeach; ?>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2"><a href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Results', 'sportspress' ) ); ?></a></th>
|
<th colspan="3"><a href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Results', 'sportspress' ) ); ?></a></th>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
@@ -163,17 +174,28 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th><?php _e( 'Label', 'sportspress' ); ?></th>
|
<th><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||||
<th><?php _e( 'Key', 'sportspress' ); ?></th>
|
<th><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||||
|
<th><?php _e( 'Abbreviation', 'sportspress' ); ?></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||||
<tr<?php if ( $i % 2 ) echo ' class="alternate"'; ?>>
|
<tr<?php if ( $i % 2 ) 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
|
||||||
|
$abbreviation = get_post_meta ( $row->ID, 'sp_abbreviation', true );
|
||||||
|
if ( $abbreviation ):
|
||||||
|
echo $abbreviation;
|
||||||
|
else:
|
||||||
|
echo $row->post_title;
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php $i++; endforeach; ?>
|
<?php $i++; endforeach; ?>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2"><a href="<?php echo admin_url( 'edit.php?post_type=sp_outcome' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Outcomes', 'sportspress' ) ); ?></a></th>
|
<th colspan="3"><a href="<?php echo admin_url( 'edit.php?post_type=sp_outcome' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Outcomes', 'sportspress' ) ); ?></a></th>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
@@ -25,7 +25,8 @@ function sp_column_edit_columns() {
|
|||||||
'title' => __( 'Label', 'sportspress' ),
|
'title' => __( 'Label', 'sportspress' ),
|
||||||
'sp_equation' => __( 'Equation', 'sportspress' ),
|
'sp_equation' => __( 'Equation', 'sportspress' ),
|
||||||
'sp_order' => __( 'Sort Order', 'sportspress' ),
|
'sp_order' => __( 'Sort Order', 'sportspress' ),
|
||||||
'sp_key' => __( 'Key', 'sportspress' )
|
'sp_key' => __( 'Key', 'sportspress' ),
|
||||||
|
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' )
|
||||||
);
|
);
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -39,6 +40,7 @@ function sp_column_details_meta( $post ) {
|
|||||||
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
|
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
|
||||||
$order = get_post_meta( $post->ID, 'sp_order', true );
|
$order = get_post_meta( $post->ID, 'sp_order', true );
|
||||||
$priority = get_post_meta( $post->ID, 'sp_priority', true );
|
$priority = get_post_meta( $post->ID, 'sp_priority', true );
|
||||||
|
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
|
||||||
?>
|
?>
|
||||||
<p><strong><?php _e( 'Equation', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Equation', 'sportspress' ); ?></strong></p>
|
||||||
<p class="sp-equation-selector">
|
<p class="sp-equation-selector">
|
||||||
@@ -67,6 +69,10 @@ function sp_column_details_meta( $post ) {
|
|||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
|
<p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p>
|
||||||
|
<p>
|
||||||
|
<input name="sp_abbreviation" type="text" size="4" id="sp_abbreviation" value="<?php echo $abbreviation; ?>">
|
||||||
|
</p>
|
||||||
<?php
|
<?php
|
||||||
sp_nonce();
|
sp_nonce();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ function sp_outcome_edit_columns() {
|
|||||||
$columns = array(
|
$columns = array(
|
||||||
'cb' => '<input type="checkbox" />',
|
'cb' => '<input type="checkbox" />',
|
||||||
'title' => __( 'Label', 'sportspress' ),
|
'title' => __( 'Label', 'sportspress' ),
|
||||||
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
|
'sp_key' => __( 'Key', 'sportspress' ),
|
||||||
'sp_key' => __( 'Key', 'sportspress' )
|
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' )
|
||||||
);
|
);
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ function sp_outcome_details_meta( $post ) {
|
|||||||
?>
|
?>
|
||||||
<p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p>
|
||||||
<p>
|
<p>
|
||||||
<input name="sp_abbreviation" type="text" size="4" id="sp_abbreviation" value="<?php echo $abbreviation; ?>" placeholder="<?php echo get_the_title( $post->ID ); ?>">
|
<input name="sp_abbreviation" type="text" size="4" id="sp_abbreviation" value="<?php echo $abbreviation; ?>">
|
||||||
</p>
|
</p>
|
||||||
<?php
|
<?php
|
||||||
sp_nonce();
|
sp_nonce();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ function sp_result_cpt_init() {
|
|||||||
'show_in_menu' => false,
|
'show_in_menu' => false,
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'supports' => array( 'title', 'page-attributes' ),
|
'supports' => array( 'title', 'page-attributes' ),
|
||||||
|
'register_meta_box_cb' => 'sp_result_meta_init',
|
||||||
'capability_type' => 'sp_config'
|
'capability_type' => 'sp_config'
|
||||||
);
|
);
|
||||||
register_post_type( 'sp_result', $args );
|
register_post_type( 'sp_result', $args );
|
||||||
@@ -22,9 +23,25 @@ function sp_result_edit_columns() {
|
|||||||
$columns = array(
|
$columns = array(
|
||||||
'cb' => '<input type="checkbox" />',
|
'cb' => '<input type="checkbox" />',
|
||||||
'title' => __( 'Label', 'sportspress' ),
|
'title' => __( 'Label', 'sportspress' ),
|
||||||
'sp_key' => __( 'Key', 'sportspress' )
|
'sp_key' => __( 'Key', 'sportspress' ),
|
||||||
|
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' )
|
||||||
);
|
);
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
add_filter( 'manage_edit-sp_result_columns', 'sp_result_edit_columns' );
|
add_filter( 'manage_edit-sp_result_columns', 'sp_result_edit_columns' );
|
||||||
|
|
||||||
|
function sp_result_meta_init() {
|
||||||
|
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sp_result_details_meta', 'sp_result', 'normal', 'high' );
|
||||||
|
}
|
||||||
|
|
||||||
|
function sp_result_details_meta( $post ) {
|
||||||
|
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
|
||||||
|
?>
|
||||||
|
<p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p>
|
||||||
|
<p>
|
||||||
|
<input name="sp_abbreviation" type="text" size="4" id="sp_abbreviation" value="<?php echo $abbreviation; ?>">
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
sp_nonce();
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
@@ -24,7 +24,8 @@ function sp_statistic_edit_columns() {
|
|||||||
'cb' => '<input type="checkbox" />',
|
'cb' => '<input type="checkbox" />',
|
||||||
'title' => __( 'Label', 'sportspress' ),
|
'title' => __( 'Label', 'sportspress' ),
|
||||||
'sp_equation' => __( 'Equation', 'sportspress' ),
|
'sp_equation' => __( 'Equation', 'sportspress' ),
|
||||||
'sp_key' => __( 'Key', 'sportspress' )
|
'sp_key' => __( 'Key', 'sportspress' ),
|
||||||
|
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' )
|
||||||
);
|
);
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -36,16 +37,19 @@ function sp_statistic_meta_init() {
|
|||||||
|
|
||||||
function sp_statistic_equation_meta( $post ) {
|
function sp_statistic_equation_meta( $post ) {
|
||||||
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
|
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
|
||||||
|
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
|
||||||
?>
|
?>
|
||||||
<div>
|
<p class="sp-equation-selector">
|
||||||
<p class="sp-equation-selector">
|
<?php
|
||||||
<?php
|
foreach ( $equation as $piece ):
|
||||||
foreach ( $equation as $piece ):
|
sp_get_equation_selector( $post->ID, $piece, array( 'player_event' ) );
|
||||||
sp_get_equation_selector( $post->ID, $piece, array( 'player_event' ) );
|
endforeach;
|
||||||
endforeach;
|
?>
|
||||||
?>
|
</p>
|
||||||
</p>
|
<p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p>
|
||||||
</div>
|
<p>
|
||||||
|
<input name="sp_abbreviation" type="text" size="4" id="sp_abbreviation" value="<?php echo $abbreviation; ?>">
|
||||||
|
</p>
|
||||||
<?php
|
<?php
|
||||||
sp_nonce();
|
sp_nonce();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ function sp_team_columns_meta( $post ) {
|
|||||||
|
|
||||||
foreach ( $div_ids as $div_id ):
|
foreach ( $div_ids as $div_id ):
|
||||||
|
|
||||||
$totals = array( 'eventsplayed' => 0 );
|
$totals = array( 'eventsplayed' => 0, 'streak' => 0 );
|
||||||
|
|
||||||
foreach ( $result_labels as $key => $value ):
|
foreach ( $result_labels as $key => $value ):
|
||||||
$totals[ $key . 'for' ] = 0;
|
$totals[ $key . 'for' ] = 0;
|
||||||
@@ -89,6 +89,7 @@ function sp_team_columns_meta( $post ) {
|
|||||||
'post_type' => 'sp_event',
|
'post_type' => 'sp_event',
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
|
'order' => 'ASC',
|
||||||
'meta_query' => array(
|
'meta_query' => array(
|
||||||
array(
|
array(
|
||||||
'key' => 'sp_team',
|
'key' => 'sp_team',
|
||||||
@@ -105,6 +106,9 @@ function sp_team_columns_meta( $post ) {
|
|||||||
);
|
);
|
||||||
$events = get_posts( $args );
|
$events = get_posts( $args );
|
||||||
|
|
||||||
|
// Initialize streaks counter
|
||||||
|
$streak = array( 'name' => '', 'count' => 0 );
|
||||||
|
|
||||||
foreach( $events as $event ):
|
foreach( $events as $event ):
|
||||||
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
||||||
foreach ( $results as $team_id => $team_result ):
|
foreach ( $results as $team_id => $team_result ):
|
||||||
@@ -115,6 +119,14 @@ function sp_team_columns_meta( $post ) {
|
|||||||
$totals['eventsplayed']++;
|
$totals['eventsplayed']++;
|
||||||
$totals[ $value ]++;
|
$totals[ $value ]++;
|
||||||
endif;
|
endif;
|
||||||
|
if ( $value && $value != '-1' ):
|
||||||
|
if ( $streak['name'] == $value ):
|
||||||
|
$streak['count'] ++;
|
||||||
|
else:
|
||||||
|
$streak['name'] = $value;
|
||||||
|
$streak['count'] = 1;
|
||||||
|
endif;
|
||||||
|
endif;
|
||||||
else:
|
else:
|
||||||
if ( array_key_exists( $key . 'for', $totals ) ):
|
if ( array_key_exists( $key . 'for', $totals ) ):
|
||||||
$totals[ $key . 'for' ] += $value;
|
$totals[ $key . 'for' ] += $value;
|
||||||
@@ -131,6 +143,21 @@ function sp_team_columns_meta( $post ) {
|
|||||||
endforeach;
|
endforeach;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
|
// Compile streaks counter and add to totals
|
||||||
|
$args=array(
|
||||||
|
'name' => $streak['name'],
|
||||||
|
'post_type' => 'sp_outcome',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'posts_per_page' => 1
|
||||||
|
);
|
||||||
|
$outcomes = get_posts( $args );
|
||||||
|
|
||||||
|
if ( $outcomes ):
|
||||||
|
$outcome = $outcomes[0];
|
||||||
|
$abbreviation = get_post_meta( $outcome->ID, 'sp_abbreviation', true );
|
||||||
|
$totals['streak'] = ( $abbreviation ? $abbreviation : $outcome->post_title ) . $streak['count'];
|
||||||
|
endif;
|
||||||
|
|
||||||
// Generate array of placeholder values for each league
|
// Generate array of placeholder values for each league
|
||||||
$placeholders[ $div_id ] = array();
|
$placeholders[ $div_id ] = array();
|
||||||
foreach ( $equations as $key => $value ):
|
foreach ( $equations as $key => $value ):
|
||||||
|
|||||||
@@ -207,8 +207,8 @@ function sp_save_post( $post_id ) {
|
|||||||
|
|
||||||
case ( 'sp_result' ):
|
case ( 'sp_result' ):
|
||||||
|
|
||||||
// Update equation as string
|
// Update abbreviation as string
|
||||||
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
|
update_post_meta( $post_id, 'sp_abbreviation', sp_array_value( $_POST, 'sp_abbreviation', '' ) );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -230,6 +230,9 @@ function sp_save_post( $post_id ) {
|
|||||||
// Update sort order as string
|
// Update sort order as string
|
||||||
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC' ) );
|
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC' ) );
|
||||||
|
|
||||||
|
// Update abbreviation as string
|
||||||
|
update_post_meta( $post_id, 'sp_abbreviation', sp_array_value( $_POST, 'sp_abbreviation', '' ) );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ( 'sp_statistic' ):
|
case ( 'sp_statistic' ):
|
||||||
@@ -237,6 +240,9 @@ function sp_save_post( $post_id ) {
|
|||||||
// Update equation as string
|
// Update equation as string
|
||||||
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
|
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
|
||||||
|
|
||||||
|
// Update abbreviation as string
|
||||||
|
update_post_meta( $post_id, 'sp_abbreviation', sp_array_value( $_POST, 'sp_abbreviation', '' ) );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ( 'sp_player' ):
|
case ( 'sp_player' ):
|
||||||
|
|||||||
@@ -331,6 +331,7 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) {
|
|||||||
break;
|
break;
|
||||||
case 'outcome':
|
case 'outcome':
|
||||||
$options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) );
|
$options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) );
|
||||||
|
$options[ __( 'Outcomes', 'sportspress' ) ]['$streak'] = __( 'Streak', 'sportspress' );
|
||||||
break;
|
break;
|
||||||
case 'column':
|
case 'column':
|
||||||
$options[ __( 'Columns', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_column' );
|
$options[ __( 'Columns', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_column' );
|
||||||
@@ -767,6 +768,10 @@ if ( !function_exists( 'sportspress_render_option_field' ) ) {
|
|||||||
if ( !function_exists( 'sp_solve' ) ) {
|
if ( !function_exists( 'sp_solve' ) ) {
|
||||||
function sp_solve( $equation, $vars ) {
|
function sp_solve( $equation, $vars ) {
|
||||||
|
|
||||||
|
// Return direct value if streak
|
||||||
|
if ( str_replace( ' ', '', $equation ) == '$streak' )
|
||||||
|
return sp_array_value( $vars, 'streak', 0 );
|
||||||
|
|
||||||
// Clearance to begin calculating remains true if all equation variables are in vars
|
// Clearance to begin calculating remains true if all equation variables are in vars
|
||||||
$clearance = true;
|
$clearance = true;
|
||||||
|
|
||||||
@@ -784,7 +789,7 @@ if ( !function_exists( 'sp_solve' ) ) {
|
|||||||
$eos = new eqEOS();
|
$eos = new eqEOS();
|
||||||
|
|
||||||
// Solve using EOS
|
// Solve using EOS
|
||||||
return $eos->solveIF( str_replace( ' ', '', $equation ), $vars );
|
return round( $eos->solveIF( str_replace( ' ', '', $equation ), $vars ), 3 ); // TODO: add precision setting to each column with default set to 3
|
||||||
else:
|
else:
|
||||||
return 0;
|
return 0;
|
||||||
endif;
|
endif;
|
||||||
@@ -812,11 +817,16 @@ if ( !function_exists( 'sp_get_table' ) ) {
|
|||||||
$totals = array();
|
$totals = array();
|
||||||
$placeholders = array();
|
$placeholders = array();
|
||||||
|
|
||||||
|
// Initialize streaks counter
|
||||||
|
$streaks = array();
|
||||||
|
|
||||||
foreach ( $team_ids as $team_id ):
|
foreach ( $team_ids as $team_id ):
|
||||||
if ( ! $team_id )
|
if ( ! $team_id )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$totals[ $team_id ] = array( 'eventsplayed' => 0 );
|
$streaks[ $team_id ] = array( 'name' => '', 'count' => 0 );
|
||||||
|
|
||||||
|
$totals[ $team_id ] = array( 'eventsplayed' => 0, 'streak' => 0 );
|
||||||
|
|
||||||
foreach ( $result_labels as $key => $value ):
|
foreach ( $result_labels as $key => $value ):
|
||||||
$totals[ $team_id ][ $key . 'for' ] = 0;
|
$totals[ $team_id ][ $key . 'for' ] = 0;
|
||||||
@@ -844,6 +854,7 @@ if ( !function_exists( 'sp_get_table' ) ) {
|
|||||||
'post_type' => 'sp_event',
|
'post_type' => 'sp_event',
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
|
'order' => 'ASC',
|
||||||
'tax_query' => array(
|
'tax_query' => array(
|
||||||
array(
|
array(
|
||||||
'taxonomy' => 'sp_league',
|
'taxonomy' => 'sp_league',
|
||||||
@@ -855,21 +866,27 @@ if ( !function_exists( 'sp_get_table' ) ) {
|
|||||||
$events = get_posts( $args );
|
$events = get_posts( $args );
|
||||||
|
|
||||||
// Event loop
|
// Event loop
|
||||||
foreach( $events as $event ):
|
foreach ( $events as $event ):
|
||||||
|
|
||||||
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
||||||
|
|
||||||
foreach ( $results as $team_id => $team_result ):
|
foreach ( $results as $team_id => $team_result ):
|
||||||
|
|
||||||
// Increment events played
|
|
||||||
$totals[ $team_id ]['eventsplayed']++;
|
|
||||||
|
|
||||||
foreach ( $team_result as $key => $value ):
|
foreach ( $team_result as $key => $value ):
|
||||||
|
|
||||||
if ( $key == 'outcome' ):
|
if ( $key == 'outcome' ):
|
||||||
if ( array_key_exists( $value, $totals[ $team_id ] ) ):
|
if ( array_key_exists( $value, $totals[ $team_id ] ) ):
|
||||||
|
$totals[ $team_id ]['eventsplayed']++;
|
||||||
$totals[ $team_id ][ $value ]++;
|
$totals[ $team_id ][ $value ]++;
|
||||||
endif;
|
endif;
|
||||||
|
if ( $value && $value != '-1' ):
|
||||||
|
if ( $streaks[ $team_id ]['name'] == $value ):
|
||||||
|
$streaks[ $team_id ]['count'] ++;
|
||||||
|
else:
|
||||||
|
$streaks[ $team_id ]['name'] = $value;
|
||||||
|
$streaks[ $team_id ]['count'] = 1;
|
||||||
|
endif;
|
||||||
|
endif;
|
||||||
else:
|
else:
|
||||||
if ( array_key_exists( $key . 'for', $totals[ $team_id ] ) ):
|
if ( array_key_exists( $key . 'for', $totals[ $team_id ] ) ):
|
||||||
$totals[ $team_id ][ $key . 'for' ] += $value;
|
$totals[ $team_id ][ $key . 'for' ] += $value;
|
||||||
@@ -882,6 +899,23 @@ if ( !function_exists( 'sp_get_table' ) ) {
|
|||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
|
foreach ( $streaks as $team_id => $streak ):
|
||||||
|
// Compile streaks counter and add to totals
|
||||||
|
$args=array(
|
||||||
|
'name' => $streak['name'],
|
||||||
|
'post_type' => 'sp_outcome',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'posts_per_page' => 1
|
||||||
|
);
|
||||||
|
$outcomes = get_posts( $args );
|
||||||
|
|
||||||
|
if ( $outcomes ):
|
||||||
|
$outcome = $outcomes[0];
|
||||||
|
$abbreviation = get_post_meta( $outcome->ID, 'sp_abbreviation', true );
|
||||||
|
$totals[ $team_id ]['streak'] = ( $abbreviation ? $abbreviation : $outcome->post_title ) . $streak['count'];
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'sp_column',
|
'post_type' => 'sp_column',
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
|
|||||||
Reference in New Issue
Block a user