aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorElizabeth Danzberger <lizzy7128@tutanota.de>2024-07-12 14:27:24 -0400
committerJulius Härtl <jus@bitgrid.net>2024-07-25 11:11:39 +0200
commit49cc5beccc4486f69350112ff94ebaebe3b6a63c (patch)
treea182fe432ce6d28b01cc62f5698eec07f1207e6d /lib/public
parent4efdb9b438e51a7f8dbbab63bc60ce0122ca3c98 (diff)
downloadnextcloud-server-49cc5beccc4486f69350112ff94ebaebe3b6a63c.tar.gz
nextcloud-server-49cc5beccc4486f69350112ff94ebaebe3b6a63c.zip
fix: `Field` and `FieldType` implementation
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/Files/Template/Field.php34
-rw-r--r--lib/public/Files/Template/FieldType.php6
2 files changed, 32 insertions, 8 deletions
diff --git a/lib/public/Files/Template/Field.php b/lib/public/Files/Template/Field.php
index 143ea95c0ef..9437563cce8 100644
--- a/lib/public/Files/Template/Field.php
+++ b/lib/public/Files/Template/Field.php
@@ -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($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 __construct(FieldType $type) {
- $this->type = $type;
+ public function jsonSerialize(): array {
+ return [
+ "index" => $this->index,
+ "content" => $this->content,
+ "type" => $this->type->value,
+ "id" => $this->id,
+ "tag" => $this->tag,
+ ];
}
}
diff --git a/lib/public/Files/Template/FieldType.php b/lib/public/Files/Template/FieldType.php
index e5e0c176d99..cb9eccae14c 100644
--- a/lib/public/Files/Template/FieldType.php
+++ b/lib/public/Files/Template/FieldType.php
@@ -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";
}