3 namespace BookStack\Exports\ZipExports\Models;
5 use BookStack\Exports\ZipExports\ZipExportFiles;
6 use BookStack\Exports\ZipExports\ZipValidationHelper;
7 use BookStack\Uploads\Attachment;
9 class ZipExportAttachment extends ZipExportModel
11 public ?int $id = null;
13 public ?int $order = null;
14 public ?string $link = null;
15 public ?string $file = null;
17 public static function fromModel(Attachment $model, ZipExportFiles $files): self
19 $instance = new self();
20 $instance->id = $model->id;
21 $instance->name = $model->name;
22 $instance->order = $model->order;
24 if ($model->external) {
25 $instance->link = $model->path;
27 $instance->file = $files->referenceForAttachment($model);
33 public static function fromModelArray(array $attachmentArray, ZipExportFiles $files): array
35 return array_values(array_map(function (Attachment $attachment) use ($files) {
36 return self::fromModel($attachment, $files);
37 }, $attachmentArray));
40 public static function validate(ZipValidationHelper $context, array $data): array
43 'id' => ['nullable', 'int'],
44 'name' => ['required', 'string', 'min:1'],
45 'order' => ['nullable', 'integer'],
46 'link' => ['required_without:file', 'nullable', 'string'],
47 'file' => ['required_without:link', 'nullable', 'string', $context->fileReferenceRule()],
50 return $context->validateData($data, $rules);