RVRNEXT-5 add model and repository for currencies
This commit is contained in:
parent
0fc21cc461
commit
12065b0525
60
src/PersistentData/Model/Currency.php
Normal file
60
src/PersistentData/Model/Currency.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php namespace RVR\PersistentData\Model;
|
||||
|
||||
use SokoWeb\PersistentData\Model\Model;
|
||||
|
||||
class Currency extends Model
|
||||
{
|
||||
protected static string $table = 'currencies';
|
||||
|
||||
protected static array $fields = ['community_id', 'code', 'round_digits'];
|
||||
|
||||
protected static array $relations = ['community' => 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;
|
||||
}
|
||||
}
|
32
src/Repository/CurrencyRepository.php
Normal file
32
src/Repository/CurrencyRepository.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php namespace RVR\Repository;
|
||||
|
||||
use Generator;
|
||||
use Container;
|
||||
use RVR\PersistentData\Model\Community;
|
||||
use RVR\PersistentData\Model\Currency;
|
||||
use SokoWeb\Database\Query\Select;
|
||||
|
||||
class CurrencyRepository
|
||||
{
|
||||
public function getById(int $id): ?Currency
|
||||
{
|
||||
return \Container::$persistentDataManager->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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user