]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: `Field` and `FieldType` implementation
authorElizabeth Danzberger <lizzy7128@tutanota.de>
Fri, 12 Jul 2024 18:27:24 +0000 (14:27 -0400)
committerJulius Härtl <jus@bitgrid.net>
Thu, 25 Jul 2024 09:11:39 +0000 (11:11 +0200)
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
lib/public/Files/Template/Field.php
lib/public/Files/Template/FieldType.php

index 143ea95c0ef1fcf0534a2af2d1ff817dd64697b8..9437563cce832662dc67076adad67b36f6239bc6 100644 (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($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,
+               ];
        }
 }
index e5e0c176d99f19ef068b8f11bb70f6b30f12b92e..cb9eccae14c3be23c1e3eb5f4c63a12259f4ad71 100644 (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";
 }