]> BookStack Code Mirror - bookstack/blob - app/Exports/ZipExports/Models/ZipExportTag.php
99abb811c0657037d23cb04183e52b425373a9bd
[bookstack] / app / Exports / ZipExports / Models / ZipExportTag.php
1 <?php
2
3 namespace BookStack\Exports\ZipExports\Models;
4
5 use BookStack\Activity\Models\Tag;
6 use BookStack\Exports\ZipExports\ZipValidationHelper;
7
8 class ZipExportTag extends ZipExportModel
9 {
10     public string $name;
11     public ?string $value = null;
12     public ?int $order = null;
13
14     public static function fromModel(Tag $model): self
15     {
16         $instance = new self();
17         $instance->name = $model->name;
18         $instance->value = $model->value;
19         $instance->order = $model->order;
20
21         return $instance;
22     }
23
24     public static function fromModelArray(array $tagArray): array
25     {
26         return array_values(array_map(self::fromModel(...), $tagArray));
27     }
28
29     public static function validate(ZipValidationHelper $context, array $data): array
30     {
31         $rules = [
32             'name'  => ['required', 'string', 'min:1'],
33             'value' => ['nullable', 'string'],
34             'order' => ['nullable', 'integer'],
35         ];
36
37         return $context->validateData($data, $rules);
38     }
39 }