From 12065b052512be90f3a08b441e3d31ea0a769e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 23 Apr 2023 17:38:04 +0200 Subject: [PATCH] RVRNEXT-5 add model and repository for currencies --- src/PersistentData/Model/Currency.php | 60 +++++++++++++++++++++++++++ src/Repository/CurrencyRepository.php | 32 ++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/PersistentData/Model/Currency.php create mode 100644 src/Repository/CurrencyRepository.php diff --git a/src/PersistentData/Model/Currency.php b/src/PersistentData/Model/Currency.php new file mode 100644 index 0000000..06cbbfd --- /dev/null +++ b/src/PersistentData/Model/Currency.php @@ -0,0 +1,60 @@ + Community::class]; + + private ?Community $community = null; + + private ?int $communityId = null; + + private string $code = ''; + + private int $roundDigits = 0; + + public function setCommunity(Community $community): void + { + $this->community = $community; + } + + public function setCommunityId(int $communityId): void + { + $this->communityId = $communityId; + } + + public function setCode(string $code): void + { + $this->code = $code; + } + + public function setRoundDigits(int $roundDigits): void + { + $this->roundDigits = $roundDigits; + } + + public function getCommunity(): ?Community + { + return $this->community; + } + + public function getCommunityId(): ?int + { + return $this->communityId; + } + + public function getCode(): string + { + return $this->code; + } + + public function getRoundDigits(): int + { + return $this->roundDigits; + } +} diff --git a/src/Repository/CurrencyRepository.php b/src/Repository/CurrencyRepository.php new file mode 100644 index 0000000..b34b089 --- /dev/null +++ b/src/Repository/CurrencyRepository.php @@ -0,0 +1,32 @@ +selectFromDbById($id, Currency::class); + } + + public function getAllByCommunity(Community $community, bool $useRelations = false): Generator + { + $select = new Select(Container::$dbConnection); + $select->where('community_id', '=', $community->getId()); + + yield from Container::$persistentDataManager->selectMultipleFromDb($select, Currency::class, $useRelations); + } + + public function getByCommunityAndCurrencyCode(Community $community, string $code): ?Currency + { + $select = new Select(Container::$dbConnection); + $select->where('community_id', '=', $community->getId()); + $select->where('code', '=', $code); + + return Container::$persistentDataManager->selectFromDb($select, Currency::class); + } +}