From 154d704f3476ee254aa8b86538f21121430a20ca Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 5 Jun 2019 13:25:14 +0200 Subject: [PATCH] NEW FEATURE: Added possibility to get played games --- src/Constants.php | 3 ++- src/Player.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Constants.php b/src/Constants.php index 4fa0c64..ab8be63 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -9,9 +9,10 @@ use JeroenED\Libpairtwo\Enums\Result; class Constants { const Won = [ Result::won, Result::wonforfait, Result::wonbye, Result::wonadjourned ]; - const Draw = [ Result::draw, Result::drawadjourned]; + const Draw = [ Result::draw, Result::drawadjourned ]; const Lost = [ Result::absent, Result::bye, Result::lost, Result::adjourned ]; const NotPlayed = [ Result::bye, Result::wonbye, Result::absent ]; + const Played = [ Result::won, Result::wonforfait, Result::wonbye, Result::wonadjourned, Result::draw, Result::drawadjourned, Result::absent, Result::bye, Result::lost, Result::adjourned ]; const Black = [ Color::black ]; const White = [ Color::white ]; } diff --git a/src/Player.php b/src/Player.php index 2828e99..12155cb 100644 --- a/src/Player.php +++ b/src/Player.php @@ -151,4 +151,19 @@ class Player extends PlayerModel } return round($total / $opponents); } + + + /** + * @return int + */ + public function getPlayedGames(): int + { + $total = 0; + foreach ($this->getPairings() as $pairing) { + if (array_search($pairing->getResult(), Constants::Played) !== false) { + $total++; + } + } + return $total; + } }