mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-24 04:41:01 +00:00
Auto commit for release 'develop' on 2024-08-05
This commit is contained in:
@@ -41,16 +41,16 @@ use LaravelJsonApi\NonEloquent\Capabilities\QueryAll;
|
||||
|
||||
class AccountQuery extends QueryAll implements HasPagination
|
||||
{
|
||||
use AccountFilter;
|
||||
use CollectsCustomParameters;
|
||||
use ExpandsQuery;
|
||||
use FiltersPagination;
|
||||
use SortsCollection;
|
||||
use SortsQueryResults;
|
||||
use UsergroupAware;
|
||||
use ValidateSortParameters;
|
||||
use CollectsCustomParameters;
|
||||
use AccountFilter;
|
||||
use SortsQueryResults;
|
||||
|
||||
//use PaginatesEnumerables;
|
||||
// use PaginatesEnumerables;
|
||||
|
||||
#[\Override]
|
||||
/**
|
||||
@@ -62,49 +62,46 @@ class AccountQuery extends QueryAll implements HasPagination
|
||||
{
|
||||
Log::debug(__METHOD__);
|
||||
// collect sort options
|
||||
$sort = $this->queryParameters->sortFields();
|
||||
$sort = $this->queryParameters->sortFields();
|
||||
|
||||
// collect pagination based on the page
|
||||
$pagination = $this->filtersPagination($this->queryParameters->page());
|
||||
$pagination = $this->filtersPagination($this->queryParameters->page());
|
||||
|
||||
// check if we need all accounts, regardless of pagination
|
||||
// This is necessary when the user wants to sort on specific params.
|
||||
$needsAll = $this->needsFullDataset(Account::class, $sort);
|
||||
$needsAll = $this->needsFullDataset(Account::class, $sort);
|
||||
|
||||
// params that were not recognised, may be my own custom stuff.
|
||||
$otherParams = $this->getOtherParams($this->queryParameters->unrecognisedParameters());
|
||||
|
||||
// start the query
|
||||
$query = $this->userGroup->accounts();
|
||||
$query = $this->userGroup->accounts();
|
||||
|
||||
// add sort and filter parameters to the query.
|
||||
$query = $this->addSortParams(Account::class, $query, $sort);
|
||||
$query = $this->addFilterParams(Account::class, $query, $this->queryParameters->filter());
|
||||
|
||||
$query = $this->addSortParams(Account::class, $query, $sort);
|
||||
$query = $this->addFilterParams(Account::class, $query, $this->queryParameters->filter());
|
||||
|
||||
// collect the result.
|
||||
$collection = $query->get(['accounts.*']);
|
||||
$collection = $query->get(['accounts.*']);
|
||||
// sort the data after the query, and return it right away.
|
||||
$collection = $this->sortCollection(Account::class, $collection, $sort);
|
||||
$collection = $this->sortCollection(Account::class, $collection, $sort);
|
||||
|
||||
// if the entire collection needs to be enriched and sorted, do so now:
|
||||
$totalCount = $collection->count();
|
||||
$totalCount = $collection->count();
|
||||
Log::debug(sprintf('Total is %d', $totalCount));
|
||||
if ($needsAll) {
|
||||
Log::debug('Needs the entire collection');
|
||||
// enrich the entire collection
|
||||
$enrichment = new AccountEnrichment();
|
||||
$enrichment = new AccountEnrichment();
|
||||
$enrichment->setStart($otherParams['start'] ?? null);
|
||||
$enrichment->setEnd($otherParams['end'] ?? null);
|
||||
$collection = $enrichment->enrich($collection);
|
||||
$collection = $enrichment->enrich($collection);
|
||||
|
||||
// TODO sort the set based on post-query sort options:
|
||||
$collection = $this->postQuerySort(Account::class, $collection, $sort);
|
||||
$collection = $this->postQuerySort(Account::class, $collection, $sort);
|
||||
|
||||
// take the current page from the enriched set.
|
||||
$currentPage = $collection->skip(($pagination['number'] - 1) * $pagination['size'])->take($pagination['size']);
|
||||
|
||||
|
||||
}
|
||||
if (!$needsAll) {
|
||||
Log::debug('Needs only partial collection');
|
||||
@@ -112,38 +109,33 @@ class AccountQuery extends QueryAll implements HasPagination
|
||||
$currentPage = $collection->skip(($pagination['number'] - 1) * $pagination['size'])->take($pagination['size']);
|
||||
|
||||
// enrich only the current page.
|
||||
$enrichment = new AccountEnrichment();
|
||||
$enrichment = new AccountEnrichment();
|
||||
$enrichment->setStart($otherParams['start'] ?? null);
|
||||
$enrichment->setEnd($otherParams['end'] ?? null);
|
||||
$currentPage = $enrichment->enrich($currentPage);
|
||||
}
|
||||
// get current page?
|
||||
Log::debug(sprintf('Skip %d, take %d', ($pagination['number'] - 1) * $pagination['size'], $pagination['size']));
|
||||
//$currentPage = $collection->skip(($pagination['number'] - 1) * $pagination['size'])->take($pagination['size']);
|
||||
// $currentPage = $collection->skip(($pagination['number'] - 1) * $pagination['size'])->take($pagination['size']);
|
||||
Log::debug(sprintf('New collection size: %d', $currentPage->count()));
|
||||
|
||||
|
||||
// TODO add filters after the query, if there are filters that cannot be applied to the database
|
||||
// TODO same for sort things.
|
||||
|
||||
return new LengthAwarePaginator($currentPage, $totalCount, $pagination['size'], $pagination['number']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
#[\Override] public function paginate(array $page): Page
|
||||
#[\Override]
|
||||
public function paginate(array $page): Page
|
||||
{
|
||||
die('here weare');
|
||||
exit('here weare');
|
||||
// TODO: Implement paginate() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
#[\Override] public function getOrPaginate(?array $page): iterable
|
||||
#[\Override]
|
||||
public function getOrPaginate(?array $page): iterable
|
||||
{
|
||||
die('here weare');
|
||||
exit('here weare');
|
||||
// TODO: Implement getOrPaginate() method.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user