diff --git a/src/Player.php b/src/Player.php index bab5452..84309a6 100644 --- a/src/Player.php +++ b/src/Player.php @@ -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]; } diff --git a/src/Tournament.php b/src/Tournament.php index ebacb50..5e3d76b 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -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) {