Skip to content

Commit

Permalink
Feature Fields (#115)
Browse files Browse the repository at this point in the history
Feature Fields 1/2
  • Loading branch information
StanBarrows authored Nov 21, 2023
1 parent e7709f5 commit 15d20b9
Show file tree
Hide file tree
Showing 22 changed files with 608 additions and 138 deletions.
73 changes: 70 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ then optimize the processes that power the core of your business.

## 🛠 Requirements

### > = v4.0 (alpha)

- PHP: `^8.2``
- Laravel: `^11.*`
- DocuWare Cloud Access

### > = v3.0

- PHP: `^8.2``
Expand Down Expand Up @@ -188,11 +194,13 @@ $content = $connector->send(new GetDocumentCountRequest($fileCabinetId, $dialogI
/**
* Upload new document with index values.
*/
use CodebarAg\DocuWare\DTO\DocumentIndex;
use CodebarAg\DocuWare\DTO\DocumentIndex\PrepareDTO;

$indexes = collect([
DocumentIndex::make('DOCUMENT_TEXT', 'Indexed Text'),
DocumentIndex::make('DOCUMENT_NUMBER', 42),
PrepareDTO::make('FIELD_TEXT', 'Indexed Text'),
PrepareDTO::make('FIELD_NUMERIC', 1),
PrepareDTO::make('FIELD_DECIMAL', 1.00),
PrepareDTO::make('FIELD_DATE', now()),
]);

$document = $connector->send(new PostDocumentRequest(
Expand Down Expand Up @@ -388,6 +396,65 @@ $url = DocuWare::url()

Please see [Tests](tests/Feature/DocuWare.php) for more details.

## 🏋️ Document Index Fields DTO showcase

```php
CodebarAg\DocuWare\DTO\DocumentIndex\IndexTextDTO {
+name: "FIELD_TEXT" // string
+value: "Value" // string
}
```

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

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

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

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

```php
use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTableDTO {
+name: "FIELD_TABLE" // string
+value: collect([
0 => [
[
'NAME' => 'TABLE_ID',
'VALUE' => '1',
],
[
'NAME' => 'TABLE_DATE',
'VALUE' => Carbon::class
],
[
'NAME' => 'TABLE_DECIMALE',
'VALUE' => 1.00,
],
]
]) // Collection|array
}
```

## 🏋️ DTO showcase

```php
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"license": "MIT",
"authors": [
{
"name": "Sebastian Fix",
"email": "sebastian.fix@codebar.ch",
"name": "Sebastian Bürgin",
"email": "sebastian.fix@buergin.ch",
"homepage": "https://www.codebar.ch",
"role": "Sofware-Engineer"
},
Expand Down
126 changes: 0 additions & 126 deletions src/DTO/DocumentIndex.php

This file was deleted.

37 changes: 37 additions & 0 deletions src/DTO/DocumentIndex/IndexDateDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace CodebarAg\DocuWare\DTO\DocumentIndex;

use Illuminate\Support\Carbon;

class IndexDateDTO
{
public function __construct(
public string $name,
public Carbon $value,
) {

}

public static function make(string $name, Carbon $value): self
{
return new self($name, $value);
}

public static function makeWithFallback($name, object $value): mixed
{
return match (true) {
$value instanceof Carbon => self::make($name, $value),
default => null,
};
}

public function values(): array
{
return [
'FieldName' => $this->name,
'Item' => $this->value->toDateString(),
'ItemElementName' => 'String',
];
}
}
37 changes: 37 additions & 0 deletions src/DTO/DocumentIndex/IndexDateTimeDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace CodebarAg\DocuWare\DTO\DocumentIndex;

use Illuminate\Support\Carbon;

class IndexDateTimeDTO
{
public function __construct(
public string $name,
public Carbon $value,
) {

}

public static function make(string $name, Carbon $value): self
{
return new self($name, $value);
}

public static function makeWithFallback($name, object $value): mixed
{
return match (true) {
$value instanceof Carbon => self::make($name, $value),
default => null,
};
}

public function values(): array
{
return [
'FieldName' => $this->name,
'Item' => $this->value->toDateTimeString(),
'ItemElementName' => 'String',
];
}
}
27 changes: 27 additions & 0 deletions src/DTO/DocumentIndex/IndexDecimalDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace CodebarAg\DocuWare\DTO\DocumentIndex;

class IndexDecimalDTO
{
public function __construct(
public string $name,
public int|float $value,
) {

}

public static function make(string $name, int|float $value): self
{
return new self($name, $value);
}

public function values(): array
{
return [
'FieldName' => $this->name,
'Item' => (float) $this->value,
'ItemElementName' => 'Decimal',
];
}
}
29 changes: 29 additions & 0 deletions src/DTO/DocumentIndex/IndexNumericDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace CodebarAg\DocuWare\DTO\DocumentIndex;

class IndexNumericDTO
{
public string $type;

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

}

public static function make(string $name, int $value): self
{
return new self($name, $value);
}

public function values(): array
{
return [
'FieldName' => $this->name,
'Item' => $this->value,
'ItemElementName' => 'Int',
];
}
}
Loading

0 comments on commit 15d20b9

Please sign in to comment.