Skip to content

Commit

Permalink
feat: add modify for estate files
Browse files Browse the repository at this point in the history
  • Loading branch information
Katalam committed Jun 3, 2024
1 parent 2c4d0b2 commit 7322591
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
## main
- Added a exception when the file is not found in a estate file query

## v0.7.3
- Added an exception when the file is not found in a estate file query
- Added a modify method for estate files

## v0.7.2
- Fixed a typo where the delete method of estate files returns an error
Expand Down
14 changes: 13 additions & 1 deletion src/Query/EstateFileBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,19 @@ public function each(callable $callback): void
*/
public function modify(int $id): bool
{
throw new OnOfficeException('Not implemented');
$parameters = array_replace($this->modifies, [
'fileId' => $id,
'parentid' => $this->estateId,
'relationtype' => 'estate',
]);

$response = $this->onOfficeService->requestApi(
OnOfficeAction::Modify,
OnOfficeResourceType::FileRelation,
parameters: $parameters,
);

return $response->json('response.results.0.data.records.0.elements.success') === 'success';
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Query/UploadBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,32 @@ public function save(string $fileContent): string
}

/**
* Returns the linked file data.
*
* @throws OnOfficeException
*/
public function link(string $tmpUploadId, array $data = []): self
public function link(string $tmpUploadId, array $data = []): array
{
$data = array_replace($data, [
'tmpUploadId' => $tmpUploadId,
]);

$this->onOfficeService->requestApi(
$response = $this->onOfficeService->requestApi(
OnOfficeAction::Do,
OnOfficeResourceType::UploadFile,
parameters: $data,
);

return $this;
return $response->json('response.results.0.data.records.0');
}

/**
* File content as base64-encoded binary data.
* Returns the temporary upload id.
* Returns the linked file data.
*
* @throws OnOfficeException
*/
public function saveAndLink(string $fileContent, array $data = []): self
public function saveAndLink(string $fileContent, array $data = []): array
{
$tmpUploadId = $this->save($fileContent);

Expand Down

0 comments on commit 7322591

Please sign in to comment.