|
4 | 4 |
|
5 | 5 | namespace CodebarAg\MFiles\DTO; |
6 | 6 |
|
| 7 | +use Carbon\CarbonImmutable; |
7 | 8 | use Illuminate\Support\Arr; |
8 | 9 | use Illuminate\Support\Collection; |
9 | 10 |
|
10 | 11 | final class ObjectProperties |
11 | 12 | { |
12 | 13 | public function __construct( |
| 14 | + public readonly int $classId, |
| 15 | + public readonly int $objectId, |
| 16 | + public readonly int $objectTypeId, |
| 17 | + public readonly int $objectVersionId, |
| 18 | + public readonly CarbonImmutable $lastModifiedAt, |
13 | 19 | public readonly Collection $properties, |
14 | | - public readonly ?int $objectId = null, |
15 | | - public readonly ?string $objectType = null, |
16 | | - public readonly ?int $objectTypeId = null, |
| 20 | + public readonly Collection $files, |
17 | 21 | ) {} |
18 | 22 |
|
19 | 23 | public static function fromArray(array $data): self |
20 | 24 | { |
| 25 | + $lastModifiedAt = Arr::get($data, 'ObjVer.Modified'); |
| 26 | + $properties = Arr::get($data, 'Properties', []); |
| 27 | + $files = Arr::get($data, 'Files', []); |
| 28 | + |
21 | 29 | return new self( |
22 | | - properties: collect(Arr::get($data, 'Properties', [])) |
23 | | - ->map(fn (array $property) => Property::fromArray($property)), |
24 | | - objectId: Arr::get($data, 'ObjectID'), |
25 | | - objectType: Arr::get($data, 'ObjectType'), |
26 | | - objectTypeId: Arr::get($data, 'ObjectTypeID'), |
| 30 | + classId: Arr::get($data, 'Class'), |
| 31 | + objectId: Arr::get($data, 'ObjVer.ID'), |
| 32 | + objectTypeId: Arr::get($data, 'ObjVer.Type'), |
| 33 | + objectVersionId: Arr::get($data, 'ObjVer.Version'), |
| 34 | + lastModifiedAt: CarbonImmutable::parse($lastModifiedAt), |
| 35 | + properties: collect($properties)->map(fn (array $property) => GetProperty::fromArray($property)), |
| 36 | + files: collect($files)->map(fn (array $file) => File::fromArray($file)), |
27 | 37 | ); |
28 | 38 | } |
29 | 39 |
|
30 | 40 | public function toArray(): array |
31 | 41 | { |
32 | 42 | return [ |
33 | | - 'properties' => $this->properties->map(fn (Property $property) => $property->toArray())->toArray(), |
| 43 | + 'classId' => $this->classId, |
34 | 44 | 'objectId' => $this->objectId, |
35 | | - 'objectType' => $this->objectType, |
36 | 45 | 'objectTypeId' => $this->objectTypeId, |
| 46 | + 'objectVersionId' => $this->objectVersionId, |
| 47 | + 'lastModifiedAt' => $this->lastModifiedAt->toIso8601String(), |
| 48 | + 'properties' => $this->properties->toArray(), |
| 49 | + 'files' => $this->files->toArray(), |
37 | 50 | ]; |
38 | 51 | } |
39 | 52 | } |
0 commit comments