]> BookStack Code Mirror - bookstack/blob - app/Exports/ZipExports/Models/ZipExportAttachment.php
283ffa751c9a152679df1733e0cd75651efb3848
[bookstack] / app / Exports / ZipExports / Models / ZipExportAttachment.php
1 <?php
2
3 namespace BookStack\Exports\ZipExports\Models;
4
5 use BookStack\Exports\ZipExports\ZipExportFiles;
6 use BookStack\Uploads\Attachment;
7
8 class ZipExportAttachment extends 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         $instance->order = $model->order;
22
23         if ($model->external) {
24             $instance->link = $model->path;
25         } else {
26             $instance->file = $files->referenceForAttachment($model);
27         }
28
29         return $instance;
30     }
31
32     public static function fromModelArray(array $attachmentArray, ZipExportFiles $files): array
33     {
34         return array_values(array_map(function (Attachment $attachment) use ($files) {
35             return self::fromModel($attachment, $files);
36         }, $attachmentArray));
37     }
38 }