First Commit for bypassing default ordering of league tables
This commit is contained in:
@@ -29,6 +29,8 @@ class SP_Meta_Box_Table_Details {
|
|||||||
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
|
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
|
||||||
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
|
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
|
||||||
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
|
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
|
||||||
|
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
|
||||||
|
$order = get_post_meta( $post->ID, 'sp_order', true );
|
||||||
?>
|
?>
|
||||||
<div>
|
<div>
|
||||||
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
|
||||||
@@ -90,6 +92,31 @@ class SP_Meta_Box_Table_Details {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
<p><strong><?php _e( 'Sort by', 'sportspress' ); ?></strong></p>
|
||||||
|
<p>
|
||||||
|
<?php
|
||||||
|
$args = array(
|
||||||
|
'prepend_options' => array(
|
||||||
|
'default' => __( 'Default', 'sportspress' ),
|
||||||
|
'name' => __( 'Name', 'sportspress' ),
|
||||||
|
),
|
||||||
|
'post_type' => array( 'sp_column' ),
|
||||||
|
'name' => 'sp_orderby',
|
||||||
|
'selected' => $orderby,
|
||||||
|
'values' => 'slug',
|
||||||
|
);
|
||||||
|
sp_dropdown_pages( $args );
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
<?php if ( $orderby != 'default' ) { ?>
|
||||||
|
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
|
||||||
|
<p>
|
||||||
|
<select name="sp_order">
|
||||||
|
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
|
||||||
|
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
<?php } ?>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,5 +135,7 @@ class SP_Meta_Box_Table_Details {
|
|||||||
update_post_meta( $post_id, 'sp_current_season', in_array( 'auto', sp_array_value( $tax_input, 'sp_season' ) ) );
|
update_post_meta( $post_id, 'sp_current_season', in_array( 'auto', sp_array_value( $tax_input, 'sp_season' ) ) );
|
||||||
update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) );
|
update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||||
|
update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', array() ) );
|
||||||
|
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,10 @@ class SP_League_Table extends SP_Secondary_Post {
|
|||||||
|
|
||||||
/** @var array Teams to check for tiebreakers. */
|
/** @var array Teams to check for tiebreakers. */
|
||||||
public $tiebreakers = array();
|
public $tiebreakers = array();
|
||||||
|
|
||||||
|
//** @var strings
|
||||||
|
public $orderby;
|
||||||
|
public $orderbyorder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns formatted data
|
* Returns formatted data
|
||||||
@@ -38,6 +42,8 @@ class SP_League_Table extends SP_Secondary_Post {
|
|||||||
$usecolumns = get_post_meta( $this->ID, 'sp_columns', true );
|
$usecolumns = get_post_meta( $this->ID, 'sp_columns', true );
|
||||||
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
|
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
|
||||||
$select = get_post_meta( $this->ID, 'sp_select', true );
|
$select = get_post_meta( $this->ID, 'sp_select', true );
|
||||||
|
$this->orderby = get_post_meta( $this->ID, 'sp_orderby', true );
|
||||||
|
$this->orderbyorder = get_post_meta( $this->ID, 'sp_order', true );
|
||||||
$link_events = get_option( 'sportspress_link_events', 'yes' ) === 'yes' ? true : false;
|
$link_events = get_option( 'sportspress_link_events', 'yes' ) === 'yes' ? true : false;
|
||||||
$form_limit = (int) get_option( 'sportspress_form_limit', 5 );
|
$form_limit = (int) get_option( 'sportspress_form_limit', 5 );
|
||||||
|
|
||||||
@@ -47,7 +53,10 @@ class SP_League_Table extends SP_Secondary_Post {
|
|||||||
$this->date = 0;
|
$this->date = 0;
|
||||||
|
|
||||||
// Apply defaults
|
// Apply defaults
|
||||||
|
if ( empty( $this->orderby ) ) $this->orderby = 'default';
|
||||||
|
if ( empty( $this->orderbyorder ) ) $this->orderbyorder = 'ASC';
|
||||||
if ( empty( $select ) ) $select = 'auto';
|
if ( empty( $select ) ) $select = 'auto';
|
||||||
|
|
||||||
|
|
||||||
if ( 'range' == $this->date ) {
|
if ( 'range' == $this->date ) {
|
||||||
|
|
||||||
@@ -752,7 +761,12 @@ class SP_League_Table extends SP_Secondary_Post {
|
|||||||
$merged[ $team_id ]['pos'] = $this->calculate_pos( $team_columns, $team_id, false );
|
$merged[ $team_id ]['pos'] = $this->calculate_pos( $team_columns, $team_id, false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var_dump($merged);
|
||||||
|
// Rearrange the table if Default ordering is not selected
|
||||||
|
if ( $this->orderby != 'default' ) {
|
||||||
|
uasort( $merged, array( $this, 'simple_order' ) );
|
||||||
|
}
|
||||||
|
|
||||||
// Rearrange data array to reflect values
|
// Rearrange data array to reflect values
|
||||||
$data = array();
|
$data = array();
|
||||||
foreach( $merged as $key => $value ):
|
foreach( $merged as $key => $value ):
|
||||||
@@ -804,6 +818,30 @@ class SP_League_Table extends SP_Secondary_Post {
|
|||||||
// Default sort by alphabetical
|
// Default sort by alphabetical
|
||||||
return strcmp( sp_array_value( $a, 'name', '' ), sp_array_value( $b, 'name', '' ) );
|
return strcmp( sp_array_value( $a, 'name', '' ), sp_array_value( $b, 'name', '' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort the table by ordering.
|
||||||
|
*
|
||||||
|
* @param array $a
|
||||||
|
* @param array $b
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function simple_order( $a, $b ) {
|
||||||
|
|
||||||
|
if ( $this->orderbyorder == 'DESC' ) {
|
||||||
|
if ( $this->orderby == 'name' ){
|
||||||
|
return strcmp( sp_array_value( $b, 'name', '' ), sp_array_value( $a, 'name', '' ) );
|
||||||
|
}else{
|
||||||
|
return $b[ $this->orderby ] - $a[ $this->orderby ];
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if ( $this->orderby == 'name' ){
|
||||||
|
return strcmp( sp_array_value( $a, 'name', '' ), sp_array_value( $b, 'name', '' ) );
|
||||||
|
}else{
|
||||||
|
return $a[ $this->orderby ] - $b[ $this->orderby ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find accurate position of teams.
|
* Find accurate position of teams.
|
||||||
|
|||||||
Reference in New Issue
Block a user