2024-10-21 02:56:56 +08:00
|
|
|
<?php
|
|
|
|
|
2024-10-23 17:48:26 +08:00
|
|
|
namespace BookStack\Exports\ZipExports\Models;
|
2024-10-21 02:56:56 +08:00
|
|
|
|
2024-10-23 17:48:26 +08:00
|
|
|
use BookStack\Exports\ZipExports\ZipExportFiles;
|
2024-10-30 23:26:23 +08:00
|
|
|
use BookStack\Exports\ZipExports\ZipValidationHelper;
|
2024-10-21 20:59:15 +08:00
|
|
|
use BookStack\Uploads\Image;
|
2024-10-30 23:26:23 +08:00
|
|
|
use Illuminate\Validation\Rule;
|
2024-10-21 02:56:56 +08:00
|
|
|
|
2024-10-21 19:13:41 +08:00
|
|
|
class ZipExportImage extends ZipExportModel
|
2024-10-21 02:56:56 +08:00
|
|
|
{
|
2024-10-21 20:59:15 +08:00
|
|
|
public ?int $id = null;
|
2024-10-21 02:56:56 +08:00
|
|
|
public string $name;
|
|
|
|
public string $file;
|
2024-10-21 20:59:15 +08:00
|
|
|
public string $type;
|
|
|
|
|
|
|
|
public static function fromModel(Image $model, ZipExportFiles $files): self
|
|
|
|
{
|
|
|
|
$instance = new self();
|
|
|
|
$instance->id = $model->id;
|
|
|
|
$instance->name = $model->name;
|
|
|
|
$instance->type = $model->type;
|
|
|
|
$instance->file = $files->referenceForImage($model);
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
2024-10-30 23:26:23 +08:00
|
|
|
|
|
|
|
public static function validate(ZipValidationHelper $context, array $data): array
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'id' => ['nullable', 'int'],
|
|
|
|
'name' => ['required', 'string', 'min:1'],
|
|
|
|
'file' => ['required', 'string', $context->fileReferenceRule()],
|
|
|
|
'type' => ['required', 'string', Rule::in(['gallery', 'drawio'])],
|
|
|
|
];
|
|
|
|
|
|
|
|
return $context->validateData($data, $rules);
|
|
|
|
}
|
2024-10-21 02:56:56 +08:00
|
|
|
}
|