fix: Field and FieldType implementation

Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
This commit is contained in:
Elizabeth Danzberger 2024-07-12 14:27:24 -04:00 committed by Julius Härtl
parent 4efdb9b438
commit 49cc5beccc
No known key found for this signature in database
GPG key ID: 4C614C6ED2CDE6DF
2 changed files with 32 additions and 8 deletions

View file

@ -5,14 +5,38 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Richdocuments\Template;
namespace OCP\Files\Template;
class Field {
private FieldType $type;
class Field implements \JsonSerializable {
private int $index;
private string $content;
private FieldType $type;
private ?int $id;
private ?string $tag;
public function __construct(FieldType $type) {
$this->type = $type;
public function __construct($index, $content, $type, $id = null, $tag = null) {
$this->index = $index;
$this->id = $id;
$this->tag = $tag;
// TODO: Sanitize content
$this->content = $content;
if ($type instanceof FieldType) {
$this->type = $type;
} else {
// TODO: Throw a proper enum with descriptive message
$this->type = FieldType::tryFrom($type) ?? throw new \Exception();
}
}
public function jsonSerialize(): array {
return [
"index" => $this->index,
"content" => $this->content,
"type" => $this->type->value,
"id" => $this->id,
"tag" => $this->tag,
];
}
}

View file

@ -5,8 +5,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Richdocuments\Template;
namespace OCP\Files\Template;
enum FieldType {
case PlainText;
enum FieldType: string {
case PlainText = "plain-text";
}