mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-15 07:33:36 +08:00
c4ec50d437
Some checks failed
analyse-php / build (push) Has been cancelled
lint-php / build (push) Has been cancelled
test-migrations / build (8.1) (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-migrations / build (8.3) (push) Has been cancelled
test-php / build (8.1) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled
53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Exports\ZipExports\Models;
|
|
|
|
use BookStack\Exports\ZipExports\ZipExportFiles;
|
|
use BookStack\Exports\ZipExports\ZipValidationHelper;
|
|
use BookStack\Uploads\Attachment;
|
|
|
|
class ZipExportAttachment extends ZipExportModel
|
|
{
|
|
public ?int $id = null;
|
|
public string $name;
|
|
public ?int $order = null;
|
|
public ?string $link = null;
|
|
public ?string $file = null;
|
|
|
|
public static function fromModel(Attachment $model, ZipExportFiles $files): self
|
|
{
|
|
$instance = new self();
|
|
$instance->id = $model->id;
|
|
$instance->name = $model->name;
|
|
$instance->order = $model->order;
|
|
|
|
if ($model->external) {
|
|
$instance->link = $model->path;
|
|
} else {
|
|
$instance->file = $files->referenceForAttachment($model);
|
|
}
|
|
|
|
return $instance;
|
|
}
|
|
|
|
public static function fromModelArray(array $attachmentArray, ZipExportFiles $files): array
|
|
{
|
|
return array_values(array_map(function (Attachment $attachment) use ($files) {
|
|
return self::fromModel($attachment, $files);
|
|
}, $attachmentArray));
|
|
}
|
|
|
|
public static function validate(ZipValidationHelper $context, array $data): array
|
|
{
|
|
$rules = [
|
|
'id' => ['nullable', 'int'],
|
|
'name' => ['required', 'string', 'min:1'],
|
|
'order' => ['nullable', 'integer'],
|
|
'link' => ['required_without:file', 'nullable', 'string'],
|
|
'file' => ['required_without:link', 'nullable', 'string', $context->fileReferenceRule()],
|
|
];
|
|
|
|
return $context->validateData($data, $rules);
|
|
}
|
|
}
|