Merge branch 'bugfix/fix-mutual-result' into develop

This commit is contained in:
Jeroen De Meerleer 2019-12-25 13:43:39 +01:00
commit ff1848b0cb
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 48 additions and 0 deletions

View File

@ -322,6 +322,43 @@ class Player
return $total;
}
/**
* Returns if player has played against all players of the array
*
* @param Player[] $players
* @return bool
*/
public function hasPlayedAllPlayersOfArray(array $players): bool
{
$ownkey = array_search($this, $players);
if ($ownkey !== false) {
unset($players[$ownkey]);
}
$total = 0;
foreach ($players as $player) {
if (array_search($player, $this->Opponents) !== false) {
$total++;
}
}
return $total == count($players);
}
/**
* Returns all opponents of $this
*
* @return Player[]
*/
private function opponents() {
$return = array();
foreach ($this->Pairings as $pairing) {
if (!empty($pairing->Opponent)) {
$return[] = $pairing->Opponent;
}
}
return $return;
}
/**
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
*
@ -334,6 +371,8 @@ class Player
return $this->playedGames();
} elseif ($key == 'NoOfWins') {
return $this->noOfWins();
} elseif ($key == 'Opponents') {
return $this->opponents();
} elseif (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key];
}

View File

@ -700,6 +700,15 @@ class Tournament
}
}
}
if($interestingplayers) {
$allintplayers = $interestingplayers;
$allintplayers[] = $player;
foreach($allintplayers as $player) {
if (!$player->hasPlayedAllPlayersOfArray($allintplayers)) {
return 0;
}
}
}
$points = 0;
$totalmatches = 0;
foreach ($player->Pairings as $pairing) {