]> BookStack Code Mirror - bookstack/blob - app/Exports/ZipExportModels/ZipExportAttachment.php
ZIP Export: Started building link/ref handling
[bookstack] / app / Exports / ZipExportModels / ZipExportAttachment.php
1 <?php
2
3 namespace BookStack\Exports\ZipExportModels;
4
5 use BookStack\Exports\ZipExportFiles;
6 use BookStack\Uploads\Attachment;
7
8 class ZipExportAttachment implements ZipExportModel
9 {
10     public ?int $id = null;
11     public string $name;
12     public ?int $order = null;
13     public ?string $link = null;
14     public ?string $file = null;
15
16     public static function fromModel(Attachment $model, ZipExportFiles $files): self
17     {
18         $instance = new self();
19         $instance->id = $model->id;
20         $instance->name = $model->name;
21
22         if ($model->external) {
23             $instance->link = $model->path;
24         } else {
25             $instance->file = $files->referenceForAttachment($model);
26         }
27
28         return $instance;
29     }
30
31     public static function fromModelArray(array $attachmentArray, ZipExportFiles $files): array
32     {
33         return array_values(array_map(function (Attachment $attachment) use ($files) {
34             return self::fromModel($attachment, $files);
35         }, $attachmentArray));
36     }
37 }