From 1d96fd0cb91af0e4a71963615106e2ad5b1fad45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Tue, 25 Apr 2023 19:27:29 +0200 Subject: [PATCH] RVRNEXT-5 add model and repository for currency exchange rate --- .../Model/CurrencyExchangeRate.php | 71 +++++++++++++++++++ .../CurrencyExchangeRateRepository.php | 24 +++++++ 2 files changed, 95 insertions(+) create mode 100644 src/PersistentData/Model/CurrencyExchangeRate.php create mode 100644 src/Repository/CurrencyExchangeRateRepository.php diff --git a/src/PersistentData/Model/CurrencyExchangeRate.php b/src/PersistentData/Model/CurrencyExchangeRate.php new file mode 100644 index 0000000..0b2e403 --- /dev/null +++ b/src/PersistentData/Model/CurrencyExchangeRate.php @@ -0,0 +1,71 @@ + Currency::class]; + + private ?Currency $currency = null; + + private ?int $currencyId = null; + + private float $exchangeRate = 0.0; + + private DateTime $validFrom; + + public function setCurrency(Currency $currency): void + { + $this->currency = $currency; + } + + public function setCurrencyId(int $currencyId): void + { + $this->currencyId = $currencyId; + } + + public function setExchangeRate(float $exchangeRate): void + { + $this->exchangeRate = $exchangeRate; + } + + public function setValidFromDate(DateTime $validFrom): void + { + $this->validFrom = $validFrom; + } + + public function setValidFrom(string $validFrom): void + { + $this->validFrom = new DateTime($validFrom); + } + + public function getCurrency(): ?Currency + { + return $this->currency; + } + + public function getCurrencyId(): ?int + { + return $this->currencyId; + } + + public function getExchangeRate(): float + { + return $this->exchangeRate; + } + + public function getValidFromDate(): DateTime + { + return $this->validFrom; + } + + public function getValidFrom(): string + { + return $this->validFrom->format('Y-m-d H:i:s'); + } +} diff --git a/src/Repository/CurrencyExchangeRateRepository.php b/src/Repository/CurrencyExchangeRateRepository.php new file mode 100644 index 0000000..d382c36 --- /dev/null +++ b/src/Repository/CurrencyExchangeRateRepository.php @@ -0,0 +1,24 @@ +selectFromDbById($id, CurrencyExchangeRate::class); + } + + public function getAllByCurrency(Currency $currency): Generator + { + $select = new Select(Container::$dbConnection); + $select->where('currency_id', '=', $currency->getId()); + $select->orderBy('valid_from'); + + yield from Container::$persistentDataManager->selectMultipleFromDb($select, CurrencyExchangeRate::class); + } +}