Enable automatic event results
This commit is contained in:
@@ -19,9 +19,15 @@ class SP_Meta_Box_Event_Results {
|
|||||||
* Output the metabox
|
* Output the metabox
|
||||||
*/
|
*/
|
||||||
public static function output( $post ) {
|
public static function output( $post ) {
|
||||||
|
// Determine if we need checkboxes
|
||||||
|
if ( 'manual' == get_option( 'sportspress_event_result_columns', 'auto' ) )
|
||||||
|
$has_checkboxes = true;
|
||||||
|
else
|
||||||
|
$has_checkboxes = false;
|
||||||
|
|
||||||
$event = new SP_Event( $post );
|
$event = new SP_Event( $post );
|
||||||
list( $columns, $usecolumns, $data ) = $event->results( true );
|
list( $columns, $usecolumns, $data ) = $event->results( true );
|
||||||
self::table( $columns, $usecolumns, $data );
|
self::table( $columns, $usecolumns, $data, $has_checkboxes );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,7 +122,7 @@ class SP_Meta_Box_Event_Results {
|
|||||||
/**
|
/**
|
||||||
* Admin edit table
|
* Admin edit table
|
||||||
*/
|
*/
|
||||||
public static function table( $columns = array(), $usecolumns = array(), $data = array() ) {
|
public static function table( $columns = array(), $usecolumns = array(), $data = array(), $has_checkboxes = false ) {
|
||||||
?>
|
?>
|
||||||
<div class="sp-data-table-container">
|
<div class="sp-data-table-container">
|
||||||
<table class="widefat sp-data-table">
|
<table class="widefat sp-data-table">
|
||||||
@@ -127,17 +133,18 @@ class SP_Meta_Box_Event_Results {
|
|||||||
</th>
|
</th>
|
||||||
<?php foreach ( $columns as $key => $label ): ?>
|
<?php foreach ( $columns as $key => $label ): ?>
|
||||||
<th class="column-<?php echo $key; ?>">
|
<th class="column-<?php echo $key; ?>">
|
||||||
<label for="sp_result_columns_<?php echo $key; ?>">
|
<?php if ( $has_checkboxes ): ?>
|
||||||
<input type="checkbox" name="sp_result_columns[]" value="<?php echo $key; ?>" id="sp_result_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
|
<label for="sp_result_columns_<?php echo $key; ?>">
|
||||||
|
<input type="checkbox" name="sp_result_columns[]" value="<?php echo $key; ?>" id="sp_result_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
|
||||||
|
<?php echo $label; ?>
|
||||||
|
</label>
|
||||||
|
<?php else: ?>
|
||||||
<?php echo $label; ?>
|
<?php echo $label; ?>
|
||||||
</label>
|
<?php endif; ?>
|
||||||
</th>
|
</th>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<th class="column-outcome">
|
<th class="column-outcome">
|
||||||
<label for="sp_result_columns_outcome">
|
<?php _e( 'Outcome', 'sportspress' ); ?>
|
||||||
<input type="checkbox" name="sp_result_columns[]" value="outcome" id="sp_result_columns_outcome" <?php checked( ! is_array( $usecolumns ) || in_array( 'outcome', $usecolumns ) ); ?>>
|
|
||||||
<?php _e( 'Outcome', 'sportspress' ); ?>
|
|
||||||
</label>
|
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -164,6 +164,35 @@ class SP_Settings_Events extends SP_Settings_Page {
|
|||||||
array( 'type' => 'sectionend', 'id' => 'event_options' ),
|
array( 'type' => 'sectionend', 'id' => 'event_options' ),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
array( 'title' => __( 'Event Results', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'result_options' ),
|
||||||
|
),
|
||||||
|
|
||||||
|
apply_filters( 'sportspress_result_options', array(
|
||||||
|
array(
|
||||||
|
'title' => __( 'Columns', 'sportspress' ),
|
||||||
|
'id' => 'sportspress_event_result_columns',
|
||||||
|
'default' => 'auto',
|
||||||
|
'type' => 'radio',
|
||||||
|
'options' => array(
|
||||||
|
'auto' => __( 'Auto', 'sportspress' ),
|
||||||
|
'manual' => __( 'Manual', 'sportspress' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
'title' => __( 'Outcome', 'sportspress' ),
|
||||||
|
'desc' => __( 'Display outcome', 'sportspress' ),
|
||||||
|
'id' => 'sportspress_event_show_outcome',
|
||||||
|
'default' => 'no',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
),
|
||||||
|
) ),
|
||||||
|
|
||||||
|
array(
|
||||||
|
array( 'type' => 'sectionend', 'id' => 'result_options' ),
|
||||||
|
),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
array( 'title' => __( 'Player Performance', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'performance_options' ),
|
array( 'title' => __( 'Player Performance', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'performance_options' ),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -45,11 +45,27 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
// Add outcome to result columns
|
// Add outcome to result columns
|
||||||
$columns['outcome'] = __( 'Outcome', 'sportspress' );
|
$columns['outcome'] = __( 'Outcome', 'sportspress' );
|
||||||
if ( is_array( $usecolumns ) ):
|
if ( is_array( $usecolumns ) ):
|
||||||
foreach ( $columns as $key => $label ):
|
if ( 'manual' == get_option( 'sportspress_event_result_columns', 'auto' ) ):
|
||||||
if ( ! in_array( $key, $usecolumns ) ):
|
foreach ( $columns as $key => $label ):
|
||||||
unset( $columns[ $key ] );
|
if ( ! in_array( $key, $usecolumns ) ):
|
||||||
endif;
|
unset( $columns[ $key ] );
|
||||||
endforeach;
|
endif;
|
||||||
|
endforeach;
|
||||||
|
else:
|
||||||
|
$active_columns = array();
|
||||||
|
foreach ( $data as $team_results ):
|
||||||
|
foreach ( $team_results as $key => $result ):
|
||||||
|
if ( is_string( $result ) && strlen( $result ) ):
|
||||||
|
$active_columns[ $key ] = $key;
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
|
endforeach;
|
||||||
|
$columns = array_intersect_key( $columns, $active_columns );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if ( 'yes' == get_option( 'sportspress_event_show_outcome', 'no' ) ):
|
||||||
|
$columns[ 'outcome' ] = __( 'Outcome', 'sportspress' );
|
||||||
|
endif;
|
||||||
endif;
|
endif;
|
||||||
$data[0] = $columns;
|
$data[0] = $columns;
|
||||||
return $data;
|
return $data;
|
||||||
|
|||||||
Reference in New Issue
Block a user