mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-15 15:44:03 +08:00
7c39dd5cba
Some checks are pending
analyse-php / build (push) Waiting to run
lint-php / build (push) Waiting to run
test-migrations / build (8.1) (push) Waiting to run
test-migrations / build (8.2) (push) Waiting to run
test-migrations / build (8.3) (push) Waiting to run
test-php / build (8.1) (push) Waiting to run
test-php / build (8.2) (push) Waiting to run
test-php / build (8.3) (push) Waiting to run
38 lines
1023 B
PHP
38 lines
1023 B
PHP
<?php
|
|
|
|
namespace BookStack\Exports\ZipExportModels;
|
|
|
|
use BookStack\Exports\ZipExportFiles;
|
|
use BookStack\Uploads\Attachment;
|
|
|
|
class ZipExportAttachment implements 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;
|
|
|
|
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));
|
|
}
|
|
}
|