Skip to content

Commit 0711fd5

Browse files
committed
Make sort and sort direction configurable
1 parent 20d4222 commit 0711fd5

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/DataObject/DataObjectFetcher.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class DataObjectFetcher implements DocumentFetcherInterface
2424

2525
private ?string $dataObjectClass = null;
2626

27+
private static string $fetch_sort = 'ID';
28+
29+
private static string $fetch_sort_direction = 'ASC';
30+
2731
public ?DocumentFetchCreatorRegistry $Registry = null;
2832

2933
public ?IndexConfiguration $Configuration = null;
@@ -58,6 +62,10 @@ public function fetch(?int $limit = 20, ?int $offset = 0): array
5862
$docs[] = DataObjectDocument::create($record);
5963
}
6064

65+
echo implode(',', array_map(function ($doc) {
66+
return $doc->getDataObject()->ID;
67+
}, $docs));
68+
6169
return $docs;
6270
}
6371

@@ -90,8 +98,12 @@ public function createDocument(array $data): ?DocumentInterface
9098

9199
private function createDataList(?int $limit = null, ?int $offset = 0): DataList
92100
{
93-
// sort records by id so that their order can be guaranteed across multiple fetches
94-
$list = DataList::create($this->dataObjectClass)->sort('ID');
101+
// sort records (default by ID) so that their order can be guaranteed across multiple fetches
102+
$sortBy = static::config()->get('fetch_sort') ?? 'ID';
103+
$sortDirection = static::config()->get('fetch_sort_direction') ?? 'ASC';
104+
105+
$list = DataList::create($this->dataObjectClass)
106+
->sort($sortBy, $sortDirection);
95107

96108
return $list->limit($limit, $offset);
97109
}

0 commit comments

Comments
 (0)