Skip to content

Commit

Permalink
Feature Fields (#116)
Browse files Browse the repository at this point in the history
* Update PutDocumentFieldUpdate
  • Loading branch information
StanBarrows authored Dec 7, 2023
1 parent 15d20b9 commit 5c3e097
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 95 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ $thumbnail = $connector->send(new GetDocumentDownloadThumbnailRequest($fileCabin
/**
* Update value of a indexed field.
*/
$value = $connector->send(new PutDocumentFieldsRequest($fileCabinetId, $documentId, [$fieldName => $newValue]))->dto()[$fieldName];
$value = $connector->send(new PutDocumentFieldsRequest($fileCabinetId, $documentId, [$fieldName => $newValue]))->dto();

/**
* Update multiple values of indexed fields.
Expand Down Expand Up @@ -401,35 +401,35 @@ Please see [Tests](tests/Feature/DocuWare.php) for more details.
```php
CodebarAg\DocuWare\DTO\DocumentIndex\IndexTextDTO {
+name: "FIELD_TEXT" // string
+value: "Value" // string
+value: "Value" // null|string
}
```

```php
CodebarAg\DocuWare\DTO\DocumentIndex\IndexNumericDTO {
+name: "FIELD_NUMERIC" // string
+value: 1 // int
+value: 1 // null|int
}
```

```php
CodebarAg\DocuWare\DTO\DocumentIndex\IndexDecimalDTO {
+name: "FIELD_DECIMAL" // string
+value: 1.00 // int|float
+value: 1.00 // null|int|float
}
```

```php
use CodebarAg\DocuWare\DTO\DocumentIndex\IndexDateDTO {
+name: "FIELD_DATE" // string
+value: now(), // Carbon
+value: now(), // null|Carbon
}
```

```php
use CodebarAg\DocuWare\DTO\DocumentIndex\IndexDateTimeDTO {
+name: "FIELD_DATETIME" // string
+value: now(), // Carbon
+value: now(), // null|Carbon
}
```

Expand All @@ -451,7 +451,7 @@ use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTableDTO {
'VALUE' => 1.00,
],
]
]) // Collection|array
]) // null|Collection|array
}
```

Expand Down
10 changes: 5 additions & 5 deletions src/DTO/Dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public function isSearch(): bool
}

public static function fake(
string $id = null,
string $type = null,
string $label = null,
bool $isDefault = null,
string $fileCabinetId = null,
?string $id = null,
?string $type = null,
?string $label = null,
?bool $isDefault = null,
?string $fileCabinetId = null,
): self {
return new self(
id: $id ?? (string) Str::uuid(),
Expand Down
24 changes: 12 additions & 12 deletions src/DTO/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ public function fileName(): string
}

public static function fake(
int $id = null,
int $file_size = null,
int $total_pages = null,
string $title = null,
string $extension = null,
string $content_type = null,
string $file_cabinet_id = null,
string $intellixTrust = null,
Carbon $created_at = null,
Carbon $updated_at = null,
Collection $fields = null,
Collection $suggestions = null,
?int $id = null,
?int $file_size = null,
?int $total_pages = null,
?string $title = null,
?string $extension = null,
?string $content_type = null,
?string $file_cabinet_id = null,
?string $intellixTrust = null,
?Carbon $created_at = null,
?Carbon $updated_at = null,
?Collection $fields = null,
?Collection $suggestions = null,
): self {
return new self(
id: $id ?? random_int(1, 999999),
Expand Down
8 changes: 4 additions & 4 deletions src/DTO/DocumentField.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function __construct(

public static function fake(
?bool $systemField = false,
string $name = null,
string $label = null,
?string $name = null,
?string $label = null,
?bool $isNull = true,
int|float|Carbon|string $value = null,
string $type = null,
int|float|Carbon|string|null $value = null,
?string $type = null,
): self {
$fakeType = Arr::random(['Int', 'Decimal', 'Text', 'DateTime']);

Expand Down
4 changes: 2 additions & 2 deletions src/DTO/DocumentIndex/IndexDateDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class IndexDateDTO
{
public function __construct(
public string $name,
public Carbon $value,
public null|Carbon|\Carbon\Carbon $value,
) {

}

public static function make(string $name, Carbon $value): self
public static function make(string $name, null|Carbon|\Carbon\Carbon $value): self
{
return new self($name, $value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/DTO/DocumentIndex/IndexDateTimeDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class IndexDateTimeDTO
{
public function __construct(
public string $name,
public Carbon $value,
public null|Carbon|\Carbon\Carbon $value,
) {

}

public static function make(string $name, Carbon $value): self
public static function make(string $name, null|Carbon|\Carbon\Carbon $value): self
{
return new self($name, $value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/DTO/DocumentIndex/IndexDecimalDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class IndexDecimalDTO
{
public function __construct(
public string $name,
public int|float $value,
public null|int|float $value,
) {

}

public static function make(string $name, int|float $value): self
public static function make(string $name, null|int|float $value): self
{
return new self($name, $value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/DTO/DocumentIndex/IndexNumericDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class IndexNumericDTO

public function __construct(
public string $name,
public int $value,
public ?int $value,
) {

}

public static function make(string $name, int $value): self
public static function make(string $name, ?int $value): self
{
return new self($name, $value);
}
Expand Down
6 changes: 3 additions & 3 deletions src/DTO/DocumentIndex/IndexTableDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class IndexTableDTO
{
public function __construct(
public string $name,
public Collection|array $rows,
public null|Collection|array $rows,
) {

}

public static function make(string $name, Collection|array $rows): self
public static function make(string $name, null|Collection|array $rows): self
{
return new self($name, $rows);
}
Expand All @@ -33,7 +33,7 @@ public function values(): array

protected function rowsCollection(): array
{
return collect($this->rows)->map(function ($row) {
return collect($this->rows ?? [])->map(function ($row) {

$indexes = collect($row)->map(function ($column) {

Expand Down
4 changes: 2 additions & 2 deletions src/DTO/DocumentIndex/IndexTextDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class IndexTextDTO
{
public function __construct(
public string $name,
public string $value,
public ?string $value,
) {

}

public static function make(string $name, string $value): self
public static function make(string $name, ?string $value): self
{
return new self($name, $value);
}
Expand Down
13 changes: 12 additions & 1 deletion src/DTO/DocumentIndex/PrepareDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function guess(string $name, mixed $value): mixed
};
}

public static function makeContent(Collection $indexes): array
public static function makeFields(Collection $indexes): array
{
return [
'Fields' => $indexes
Expand All @@ -28,4 +28,15 @@ public static function makeContent(Collection $indexes): array
->values(),
];
}

public static function makeField(Collection $indexes, bool $forceUpdate = false): array
{
return [
'Field' => $indexes
->map(fn (IndexTextDTO|IndexDateDTO|IndexDateTimeDTO|IndexNumericDTO|IndexDecimalDTO|IndexTableDTO $index) => $index->values())
->filter()
->values(),
'ForceUpdate' => $forceUpdate,
];
}
}
14 changes: 7 additions & 7 deletions src/DTO/DocumentPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public static function fromFailed(Exception $e): self
}

public static function fake(
int $total = null,
int $per_page = null,
int $current_page = null,
int $last_page = null,
int $from = null,
int $to = null,
Collection $documents = null,
?int $total = null,
?int $per_page = null,
?int $current_page = null,
?int $last_page = null,
?int $from = null,
?int $to = null,
?Collection $documents = null,
): self {
return new self(
total: $total ?? random_int(10, 100),
Expand Down
8 changes: 4 additions & 4 deletions src/DTO/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function isUser(): bool
}

public static function fake(
string $name = null,
string $label = null,
string $type = null,
string $scope = null,
?string $name = null,
?string $label = null,
?string $type = null,
?string $scope = null,
): self {
return new self(
name: $name ?? 'FAKE_FIELD',
Expand Down
10 changes: 5 additions & 5 deletions src/DTO/FileCabinet.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public function __construct(
}

public static function fake(
string $id = null,
string $name = null,
string $color = null,
bool $isBasket = null,
string $assignedCabinet = null,
?string $id = null,
?string $name = null,
?string $color = null,
?bool $isBasket = null,
?string $assignedCabinet = null,
): self {
return new self(
id: $id ?? (string) Str::uuid(),
Expand Down
6 changes: 3 additions & 3 deletions src/DTO/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function __construct(
}

public static function fake(
string $id = null,
string $name = null,
string $guid = null,
?string $id = null,
?string $name = null,
?string $guid = null,
array $additionalInfo = [],
array $configurationRights = [],
): self {
Expand Down
6 changes: 3 additions & 3 deletions src/DTO/OrganizationIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function __construct(
}

public static function fake(
string $id = null,
string $name = null,
string $guid = null,
?string $id = null,
?string $name = null,
?string $guid = null,
): self {
return new self(
id: $id ?? (string) Str::uuid(),
Expand Down
6 changes: 3 additions & 3 deletions src/DTO/SuggestionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function __construct(

public static function fake(
array $value = [],
string $name = null,
string $db_name = null,
string $confidence = null,
?string $name = null,
?string $db_name = null,
?string $confidence = null,
): self {
return new self(
value: $value,
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/TableRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
}

public static function fake(
Collection $fields = null,
?Collection $fields = null,
): self {
return new self(
fields: $fields ?? collect([
Expand Down
2 changes: 1 addition & 1 deletion src/Requests/Document/PostDocumentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function defaultBody(): array
$body = [];

if ($this->indexes) {
$indexContent = json_encode(PrepareDTO::makeContent($this->indexes));
$indexContent = json_encode(PrepareDTO::makeFields($this->indexes));
$body[] = new MultipartValue(name: 'document', value: $indexContent, filename: 'index.json');
}

Expand Down
Loading

0 comments on commit 5c3e097

Please sign in to comment.