|
4 | 4 |
|
5 | 5 | namespace ItkDev\F2ApiClient\Model; |
6 | 6 |
|
7 | | -final class CaseFile extends AbstractItem |
| 7 | +final class CaseFile extends F2Item |
8 | 8 | { |
9 | | - /** |
10 | | - * @see resources/f2-rest-docs/f2-rest-docs-v13s.html#56 |
11 | | - */ |
12 | | - public function __construct( |
13 | | - // Id |
14 | | - // int |
15 | | - // Internal identifier. |
16 | | - public readonly int $id, |
| 9 | + // @see resources/f2-rest-docs/f2-rest-docs-v13s.html#56 |
17 | 10 |
|
18 | | - // CaseNumber |
19 | | - // string |
20 | | - // Official case number (for instance "2012 - 342"). |
21 | | - public readonly string $caseNumber, |
| 11 | + public string $caseNumber; |
22 | 12 |
|
23 | | - // Title |
24 | | - // string |
25 | | - // Case title. |
26 | | - public readonly string $title, |
| 13 | + public string $title; |
| 14 | + public \DateTimeImmutable $createdDate; |
| 15 | + public \DateTimeImmutable $modifiedDate; |
| 16 | + public PartyItem $modifiedBy; |
| 17 | + public PartyItem $responsible; |
27 | 18 |
|
28 | | - // CreatedDate |
29 | | - // DateTime |
30 | | - // Date and time the case was created. |
31 | | - public readonly \DateTimeImmutable $createdDate, |
| 19 | + // Link |
| 20 | + // List of Link (read-only) |
| 21 | + // One or more links to other related resources. |
| 22 | + // Matters |
| 23 | + // List of Matter |
| 24 | + // List of all accessible matters on the case. |
| 25 | + /** @var Matter[] */ |
| 26 | + public array $matters; |
32 | 27 |
|
33 | | - // ModifiedDate |
34 | | - // DateTime |
35 | | - // Date and time the case was last modified. |
36 | | - public readonly \DateTimeImmutable $modifiedDate, |
| 28 | + public function setFromSimpleXMLElement(\SimpleXMLElement $sxe): static |
| 29 | + { |
| 30 | + parent::setFromSimpleXMLElement($sxe); |
37 | 31 |
|
38 | | - // ModifiedBy |
39 | | - // PartyItem |
40 | | - // Last user who modified the case. |
41 | | - public readonly PartyItem $modifiedBy, |
| 32 | + $this->id = (int) $sxe->Id; |
| 33 | + $this->caseNumber = (string) $sxe->CaseNumber; |
| 34 | + $this->title = (string) $sxe->Title; |
| 35 | + $this->createdDate = new \DateTimeImmutable((string) $sxe->CreatedDate); |
| 36 | + $this->modifiedDate = new \DateTimeImmutable((string) $sxe->ModifiedDate); |
| 37 | + $this->modifiedBy = PartyItem::fromSimpleXMLElement($sxe->ModifiedBy); |
| 38 | + $this->responsible = PartyItem::fromSimpleXMLElement($sxe->Responsible); |
42 | 39 |
|
43 | | - // Responsible |
44 | | - // PartyItem |
45 | | - // The party who is responsible for the case. |
46 | | - public readonly PartyItem $responsible, |
47 | | - // Link |
48 | | - // List of Link (read-only) |
49 | | - // One or more links to other related resources. |
50 | | - // Matters |
51 | | - // List of Matter |
52 | | - // List of all accessible matters on the case. |
53 | | - // /** @var Matter[] */ |
54 | | - // public readonly array $matters, |
55 | | - ) |
56 | | - { |
57 | | - } |
| 40 | + $this->matters = static::listOf(Matter::class, $sxe->Matters); |
58 | 41 |
|
59 | | - public static function fromSimpleXMLElement(\SimpleXMLElement $sxe) |
60 | | - { |
61 | | - return new self( |
62 | | - id: (int) $sxe->Id, |
63 | | - caseNumber: (string) $sxe->CaseNumber, |
64 | | - title: (string) $sxe->Title, |
65 | | - createdDate: new \DateTimeImmutable((string) $sxe->CreatedDate), |
66 | | - modifiedDate: new \DateTimeImmutable((string) $sxe->ModifiedDate), |
67 | | - modifiedBy: PartyItem::fromSimpleXMLElement($sxe->ModifiedBy), |
68 | | - responsible: PartyItem::fromSimpleXMLElement($sxe->Responsible), |
69 | | - // matters: static::listOf(Matter::class, $sxe->Matters), |
70 | | - ); |
| 42 | + return $this; |
71 | 43 | } |
72 | 44 |
|
73 | | - public function __toString() |
| 45 | + #[\Override] |
| 46 | + public function __toString(): string |
74 | 47 | { |
75 | 48 | return sprintf('Case %s: %s', $this->caseNumber, $this->title); |
76 | 49 | } |
77 | 50 |
|
| 51 | + #[\Override] |
78 | 52 | public function jsonSerialize(): array |
79 | 53 | { |
80 | 54 | return [ |
81 | | - 'id' => $this->id, |
82 | 55 | 'caseNumber' => $this->caseNumber, |
83 | 56 | 'title' => $this->title, |
84 | 57 | 'createdDate' => $this->createdDate, |
85 | 58 | 'modifiedDate' => $this->modifiedDate, |
86 | 59 | 'modifiedBy' => $this->modifiedBy->jsonSerialize(), |
87 | 60 | 'responsible' => $this->responsible->jsonSerialize(), |
88 | | - // 'matters' => array_map(static fn (Matter $matter) => $matter->jsonSerialize(), $this->matters), |
89 | | - ]; |
| 61 | + 'matters' => array_map(static fn(Matter $matter) => $matter->jsonSerialize(), $this->matters), |
| 62 | + ] + parent::jsonSerialize(); |
90 | 63 | } |
91 | 64 | } |
0 commit comments