45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php namespace RVR\Repository;
|
|
|
|
use Container;
|
|
use Generator;
|
|
use RVR\PersistentData\Model\Community;
|
|
use RVR\PersistentData\Model\Transaction;
|
|
use SokoWeb\Database\Query\Select;
|
|
|
|
class TransactionRepository
|
|
{
|
|
public function getById(int $id): ?Transaction
|
|
{
|
|
return Container::$persistentDataManager->selectFromDbById($id, Transaction::class);
|
|
}
|
|
|
|
public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator
|
|
{
|
|
$select = $this->selectAllByCommunity($community);
|
|
|
|
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
|
|
}
|
|
|
|
public function countAllByCommunity(Community $community): int
|
|
{
|
|
return $this->selectAllByCommunity($community)->count();
|
|
}
|
|
|
|
public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
|
{
|
|
$select = new Select(Container::$dbConnection);
|
|
$select->where('community_id', '=', $community->getId());
|
|
$select->orderBy('time', 'DESC');
|
|
$select->limit($limit, $start);
|
|
|
|
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
|
|
}
|
|
|
|
private function selectAllByCommunity(Community $community)
|
|
{
|
|
$select = new Select(Container::$dbConnection, Transaction::getTable());
|
|
$select->where('community_id', '=', $community->getId());
|
|
return $select;
|
|
}
|
|
}
|