From 4f8e524c71c8679190d7279865dd301af5d6f25e Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 13 May 2019 20:03:21 +0200 Subject: [PATCH] Added getAbsent and getBye functions to Round --- src/Round.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Round.php b/src/Round.php index 14e8845..b5c1f12 100644 --- a/src/Round.php +++ b/src/Round.php @@ -8,6 +8,7 @@ namespace JeroenED\Libpairtwo; +use JeroenED\Libpairtwo\Enums\Result; use JeroenED\Libpairtwo\Models\Round as RoundModel; use JeroenED\Libpairtwo\Game; use JeroenED\Libpairtwo\Pairing; @@ -37,4 +38,40 @@ class Round extends RoundModel $newarray[] = $pairing; $this->setPairings($newarray); } + + + /** + * Returns an array of pairings where the player is bye + * + * @return Pairing[] + */ + public function getBye(): array + { + $allPairings = $this->getPairings(); + $byePairings = []; + foreach ($allPairings as $pairing) { + if ($pairing->getResult() == Result::bye) { + $byePairings[] = $pairing; + } + } + return $byePairings; + } + + + /** + * Returns an array of pairings where the player is absent + * + * @return Pairing[] + */ + public function getAbsent(): array + { + $allPairings = $this->getPairings(); + $absentPairings = []; + foreach ($allPairings as $pairing) { + if ($pairing->getResult() == Result::absent) { + $absentPairings[] = $pairing; + } + } + return $absentPairings; + } }