Prevent duplicate teams in tiebreakers array
This commit is contained in:
@@ -683,7 +683,7 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
foreach ( $this->tiebreakers as $pos => $teams ) {
|
foreach ( $this->tiebreakers as $pos => $teams ) {
|
||||||
if ( sizeof( $teams ) === 1 ) {
|
if ( sizeof( $teams ) === 1 ) {
|
||||||
$order[] = reset( $teams );
|
$order[] = reset( $teams );
|
||||||
} elseif ( sizeof( $teams ) >= 2 ) {
|
} else {
|
||||||
$standings = $this->data( false, $teams );
|
$standings = $this->data( false, $teams );
|
||||||
$teams = array_keys( $standings );
|
$teams = array_keys( $standings );
|
||||||
foreach( $teams as $team ) {
|
foreach( $teams as $team ) {
|
||||||
@@ -702,7 +702,7 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
$this->pos = 0;
|
$this->pos = 0;
|
||||||
$this->counter = 0;
|
$this->counter = 0;
|
||||||
foreach ( $merged as $team_id => $team_columns ) {
|
foreach ( $merged as $team_id => $team_columns ) {
|
||||||
$merged[ $team_id ]['pos'] = $this->calculate_pos( $team_columns, $team_id );
|
$merged[ $team_id ]['pos'] = $this->calculate_pos( $team_columns, $team_id, false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,19 +765,23 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function calculate_pos( $columns, $id = 0 ) {
|
public function calculate_pos( $columns, $id = 0, $add_tiebreakers = true ) {
|
||||||
$this->counter++;
|
$this->counter++;
|
||||||
|
|
||||||
$pos = $this->increment( $columns );
|
$pos = $this->increment( $columns );
|
||||||
|
|
||||||
// Initialize tiebreaker position
|
if ( $add_tiebreakers ) {
|
||||||
if ( ! array_key_exists( $this->pos, $this->tiebreakers ) ) {
|
// Initialize tiebreaker position
|
||||||
$this->tiebreakers[ $this->pos ] = array();
|
if ( ! array_key_exists( $this->pos, $this->tiebreakers ) ) {
|
||||||
|
$this->tiebreakers[ $this->pos ] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to tiebreakers
|
||||||
|
if ( ! in_array( $id, $this->tiebreakers[ $this->pos ] ) ) {
|
||||||
|
$this->tiebreakers[ $this->pos ][] = $id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to tiebreakers
|
|
||||||
$this->tiebreakers[ $this->pos ][] = $id;
|
|
||||||
|
|
||||||
return $pos;
|
return $pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user