Skip to content

Commit

Permalink
feat: add custom parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Katalam committed Jul 4, 2024
1 parent ee218b4 commit 82a0a35
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
## main

## v.0.8.0
- Added the parameter helper to all repositories

## v0.7.7
- Fixed typo of addressids

Expand Down
3 changes: 1 addition & 2 deletions src/Query/ActivityBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class ActivityBuilder extends Builder

public string $estateOrAddress = 'estate';

public array $customParameters = [];

public function __construct(
private readonly OnOfficeService $onOfficeService,
) {}
Expand Down Expand Up @@ -91,6 +89,7 @@ public function find(int $id): array
$id,
parameters: [
OnOfficeService::DATA => $this->columns,
...$this->customParameters,
]
);

Expand Down
3 changes: 1 addition & 2 deletions src/Query/AddressBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class AddressBuilder extends Builder
{
use RecordIds;

public array $customParameters = [];

public function __construct(
private readonly OnOfficeService $onOfficeService,
) {}
Expand Down Expand Up @@ -99,6 +97,7 @@ public function find(int $id): array
$id,
parameters: [
OnOfficeService::DATA => $columns,
...$this->customParameters,
]
);

Expand Down
19 changes: 19 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ abstract class Builder
*/
public int $offset = 0;

/*
* An array of custom parameters.
*/
public array $customParameters = [];

public function select(array|string $columns = ['ID']): static
{
$this->columns = Arr::wrap($columns);
Expand Down Expand Up @@ -140,6 +145,20 @@ protected function getOrderBy(): array
})->toArray();
}

public function parameter(string $key, mixed $value): static
{
$this->customParameters[$key] = $value;

return $this;
}

public function parameters(array $parameters): static
{
$this->customParameters = array_replace_recursive($this->customParameters, $parameters);

return $this;
}

abstract public function get(): Collection;

abstract public function first(): array;
Expand Down
4 changes: 4 additions & 0 deletions src/Query/EstateBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function get(): Collection
OnOfficeService::LISTLIMIT => $pageSize,
OnOfficeService::LISTOFFSET => $offset,
OnOfficeService::SORTBY => $orderBy,
...$this->customParameters,
]
);
}, pageSize: $listLimit, offset: $listOffset);
Expand All @@ -61,6 +62,7 @@ public function first(): array
OnOfficeService::LISTLIMIT => $listLimit,
OnOfficeService::LISTOFFSET => $listOffset,
OnOfficeService::SORTBY => $orderBy,
...$this->customParameters,
]
);

Expand All @@ -80,6 +82,7 @@ public function find(int $id): array
$id,
parameters: [
OnOfficeService::DATA => $columns,
...$this->customParameters,
]
);

Expand All @@ -106,6 +109,7 @@ public function each(callable $callback): void
OnOfficeService::LISTLIMIT => $pageSize,
OnOfficeService::LISTOFFSET => $offset,
OnOfficeService::SORTBY => $orderBy,
...$this->customParameters,
]
);
}, $callback, pageSize: $listLimit, offset: $listOffset);
Expand Down
5 changes: 5 additions & 0 deletions src/Query/EstateFileBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function get(): Collection
'estateid' => $this->estateId,
OnOfficeService::LISTLIMIT => $pageSize,
OnOfficeService::LISTOFFSET => $offset,
...$this->customParameters,
],
);
}, pageSize: $this->limit, offset: $this->offset);
Expand All @@ -51,6 +52,7 @@ public function first(): array
OnOfficeResourceId::Estate,
parameters: [
'estateid' => $this->estateId,
...$this->customParameters,
],
);

Expand All @@ -69,6 +71,7 @@ public function find(int $id): array
parameters: [
'estateid' => $this->estateId,
'fileid' => $id,
...$this->customParameters,
],
);

Expand All @@ -94,6 +97,7 @@ public function each(callable $callback): void
'estateid' => $this->estateId,
OnOfficeService::LISTLIMIT => $pageSize,
OnOfficeService::LISTOFFSET => $offset,
...$this->customParameters,
],
);
}, $callback, pageSize: $this->limit, offset: $this->offset);
Expand Down Expand Up @@ -131,6 +135,7 @@ public function delete(int $id): bool
'fileId' => $id,
'parentid' => $this->estateId,
'relationtype' => 'estate',
...$this->customParameters,
],
);

Expand Down
3 changes: 3 additions & 0 deletions src/Query/FieldBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function get(): Collection
OnOfficeResourceType::Fields,
parameters: [
'modules' => $this->modules,
...$this->customParameters,
],
);
});
Expand All @@ -44,6 +45,7 @@ public function first(): array
OnOfficeResourceType::Fields,
parameters: [
'modules' => $this->modules,
...$this->customParameters,
],
);

Expand All @@ -68,6 +70,7 @@ public function each(callable $callback): void
OnOfficeResourceType::Fields,
parameters: [
'modules' => $this->modules,
...$this->customParameters,
],
);
}, $callback);
Expand Down
3 changes: 3 additions & 0 deletions src/Query/ImprintBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function get(): Collection
OnOfficeResourceType::Impressum,
parameters: [
OnOfficeService::DATA => $columns,
...$this->customParameters,
]
);
}, pageSize: $listLimit, offset: $listOffset);
Expand All @@ -53,6 +54,7 @@ public function first(): array
OnOfficeResourceType::Impressum,
parameters: [
OnOfficeService::DATA => $columns,
...$this->customParameters,
]
);

Expand All @@ -72,6 +74,7 @@ public function find(int $id): array
resourceId: $id,
parameters: [
OnOfficeService::DATA => $columns,
...$this->customParameters,
]
);

Expand Down
1 change: 1 addition & 0 deletions src/Query/MarketplaceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function unlockProvider(
parameters: [
OnOfficeService::PARAMETERCACHEID => $parameterCacheId,
OnOfficeService::EXTENDEDCLAIM => $extendedClaim,
...$this->customParameters,
]
);

Expand Down
3 changes: 3 additions & 0 deletions src/Query/RegionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function get(): Collection
return $this->onOfficeService->requestApi(
OnOfficeAction::Get,
OnOfficeResourceType::Regions,
...$this->customParameters,
);
}, pageSize: $listLimit, offset: $listOffset);
}
Expand All @@ -47,6 +48,7 @@ public function first(): array
$response = $this->onOfficeService->requestApi(
OnOfficeAction::Get,
OnOfficeResourceType::Regions,
...$this->customParameters,
);

return $response->json('response.results.0.data.records.0');
Expand All @@ -71,6 +73,7 @@ public function each(callable $callback): void
return $this->onOfficeService->requestApi(
OnOfficeAction::Get,
OnOfficeResourceType::Regions,
...$this->customParameters,
);
}, $callback, pageSize: $listLimit, offset: $listOffset);
}
Expand Down
1 change: 1 addition & 0 deletions src/Query/RelationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function get(): Collection
OnOfficeService::RELATIONTYPE => $this->relationType,
OnOfficeService::PARENTIDS => $this->parentIds,
OnOfficeService::CHILDIDS => $this->childIds,
...$this->customParameters,
],
);
}, pageSize: $this->limit, offset: $this->offset);
Expand Down
1 change: 1 addition & 0 deletions src/Query/UploadBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function save(string $fileContent): string
OnOfficeResourceType::UploadFile,
parameters: [
OnOfficeService::DATA => $fileContent,
...$this->customParameters,
]
);

Expand Down
4 changes: 4 additions & 0 deletions src/Query/UserBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function get(): Collection
OnOfficeService::LISTLIMIT => $pageSize,
OnOfficeService::LISTOFFSET => $offset,
OnOfficeService::SORTBY => $orderBy,
...$this->customParameters,
],
);
}, pageSize: $listLimit, offset: $listOffset);
Expand All @@ -61,6 +62,7 @@ public function first(): array
OnOfficeService::LISTLIMIT => $listLimit,
OnOfficeService::LISTOFFSET => $listOffset,
OnOfficeService::SORTBY => $orderBy,
...$this->customParameters,
]
);

Expand All @@ -80,6 +82,7 @@ public function find(int $id): array
$id,
parameters: [
OnOfficeService::DATA => $columns,
...$this->customParameters,
]
);

Expand All @@ -106,6 +109,7 @@ public function each(callable $callback): void
OnOfficeService::LISTLIMIT => $pageSize,
OnOfficeService::LISTOFFSET => $offset,
OnOfficeService::SORTBY => $orderBy,
...$this->customParameters,
]
);
}, $callback, pageSize: $listLimit, offset: $listOffset);
Expand Down

0 comments on commit 82a0a35

Please sign in to comment.