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
|
|
|
|
2024-11-05 21:17:31 +08:00
|
|
|
public function metadataOnly(): void
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2024-10-30 23:26:23 +08:00
|
|
|
public static function validate(ZipValidationHelper $context, array $data): array
|
|
|
|
{
|
2024-11-19 01:42:49 +08:00
|
|
|
$acceptedImageTypes = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'];
|
2024-10-30 23:26:23 +08:00
|
|
|
$rules = [
|
2024-11-18 23:53:21 +08:00
|
|
|
'id' => ['nullable', 'int', $context->uniqueIdRule('image')],
|
2024-10-30 23:26:23 +08:00
|
|
|
'name' => ['required', 'string', 'min:1'],
|
2024-11-19 01:42:49 +08:00
|
|
|
'file' => ['required', 'string', $context->fileReferenceRule($acceptedImageTypes)],
|
2024-10-30 23:26:23 +08:00
|
|
|
'type' => ['required', 'string', Rule::in(['gallery', 'drawio'])],
|
|
|
|
];
|
|
|
|
|
|
|
|
return $context->validateData($data, $rules);
|
|
|
|
}
|
2024-11-05 21:17:31 +08:00
|
|
|
|
|
|
|
public static function fromArray(array $data): self
|
|
|
|
{
|
|
|
|
$model = new self();
|
|
|
|
|
|
|
|
$model->id = $data['id'] ?? null;
|
|
|
|
$model->name = $data['name'];
|
|
|
|
$model->file = $data['file'];
|
|
|
|
$model->type = $data['type'];
|
|
|
|
|
|
|
|
return $model;
|
|
|
|
}
|
2024-10-21 02:56:56 +08:00
|
|
|
}
|