diff --git a/src/Query/AddressBuilder.php b/src/Query/AddressBuilder.php index 49c8c7a..90df519 100644 --- a/src/Query/AddressBuilder.php +++ b/src/Query/AddressBuilder.php @@ -92,4 +92,33 @@ public function find(int $id): array return $response->json('response.results.0.data.records.0'); } + + public function each(callable $callback): void + { + $columns = $this->columns; + $filter = $this->getFilters(); + $listLimit = $this->limit; + $listOffset = $this->offset; + $orderBy = $this->getOrderBy(); + + $sortBy = data_get(array_keys($orderBy), 0); + $sortOrder = data_get($orderBy, 0); + + $this->onOfficeService->requestAllChunked(/** + * @throws OnOfficeException + */ function (int $pageSize, int $offset) use ($sortOrder, $sortBy, $filter, $columns) { + return $this->onOfficeService->requestApi( + OnOfficeAction::Read, + OnOfficeResourceType::Address, + parameters: [ + OnOfficeService::DATA => $columns, + OnOfficeService::FILTER => $filter, + OnOfficeService::LISTLIMIT => $pageSize, + OnOfficeService::LISTOFFSET => $offset, + OnOfficeService::SORTBY => $sortBy, + OnOfficeService::SORTORDER => $sortOrder, + ] + ); + }, $callback, pageSize: $listLimit, offset: $listOffset); + } } diff --git a/src/Query/Builder.php b/src/Query/Builder.php index a6efd46..aa48326 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -123,4 +123,6 @@ abstract public function get(): Collection; abstract public function first(): array; abstract public function find(int $id): array; + + abstract public function each(callable $callback): void; } diff --git a/src/Query/EstateBuilder.php b/src/Query/EstateBuilder.php index 2321513..8aef9b9 100644 --- a/src/Query/EstateBuilder.php +++ b/src/Query/EstateBuilder.php @@ -35,7 +35,6 @@ public function get(): Collection OnOfficeService::LISTLIMIT => $pageSize, OnOfficeService::LISTOFFSET => $offset, OnOfficeService::SORTBY => $orderBy, - ] ); }, pageSize: $listLimit, offset: $listOffset); @@ -85,4 +84,29 @@ public function find(int $id): array return $response->json('response.results.0.data.records.0'); } + + public function each(callable $callback): void + { + $columns = $this->columns; + $filter = $this->getFilters(); + $listLimit = $this->limit; + $listOffset = $this->offset; + $orderBy = $this->getOrderBy(); + + $this->onOfficeService->requestAllChunked(/** + * @throws OnOfficeException + */ function (int $pageSize, int $offset) use ($filter, $orderBy, $columns) { + return $this->onOfficeService->requestApi( + OnOfficeAction::Read, + OnOfficeResourceType::Estate, + parameters: [ + OnOfficeService::DATA => $columns, + OnOfficeService::FILTER => $filter, + OnOfficeService::LISTLIMIT => $pageSize, + OnOfficeService::LISTOFFSET => $offset, + OnOfficeService::SORTBY => $orderBy, + ] + ); + }, $callback, pageSize: $listLimit, offset: $listOffset); + } } diff --git a/tests/Query/BuilderTest.php b/tests/Query/BuilderTest.php index 8d8329d..e0f8798 100644 --- a/tests/Query/BuilderTest.php +++ b/tests/Query/BuilderTest.php @@ -19,6 +19,10 @@ public function find(int $id): array { return []; } + + public function each(callable $callback): void + { + } } describe('select', function () { diff --git a/tests/Services/OnOfficeServiceTest.php b/tests/Services/OnOfficeServiceTest.php index 1ff635a..34da144 100644 --- a/tests/Services/OnOfficeServiceTest.php +++ b/tests/Services/OnOfficeServiceTest.php @@ -95,7 +95,8 @@ OnOfficeAction::Get, OnOfficeResourceType::Estate, ); - }, function () {}); + }, function () { + }); })->with([300, 301, 400, 401, 500, 501]); it('will call the callback', function () {